🎨
graphics.js
  • Welcome!
  • Quick Start
  • How to Specify Colors
  • API Reference
    • Fundamental
    • Drawing
    • Image
    • Sound
    • Mouse
    • Keyboard
    • Time
    • Math
    • Miscellaneous
Powered by GitBook
On this page

Welcome!

NextQuick Start

Last updated 2 years ago

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

Try it on

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)
library
CodePen