Welcome!

Javascript rewrite of Andrew Merrill's 2D Python graphics library. ~Just like from Computer Science 1

To make an animation or game, you need to write three functions:

  • A function that initializes a new world

  • A function that updates the world for each frame of the animation

  • A function that draws the world on the screen

import { makeGraphicsWindow, runGraphics, fillCircle } from '@soft-boy/graphics.js'
makeGraphicsWindow(800, 600, document.getElementById('canvas'))

// this function is called once to initialize your new world
function startWorld(world) {
  world.ballX = 50
  world.ballY = 300
}

// this function is called every frame to update your world
function updateWorld(world) {
  world.ballX = world.ballX + 3
}

// this function is called every frame to draw your world
function drawWorld(world) {
  fillCircle(world.ballX, world.ballY, 50, "red")
}

runGraphics(startWorld, updateWorld, drawWorld)

Last updated