Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

readme.md

about

Teeny tiny turtle brains.

setup

Fetch latest from GitHub directly:

npm install thewhodidthis/taxi

usage

Initialize with a CanvasRenderingContext2D to then be drawing on. For example,

import createTaxi from '@thewhodidthis/taxi'

const canvas = document.createElement('canvas')
const target = canvas.getContext('2d')

const size = 99
const half = size * 0.5

const jack = createTaxi(target)

// Mix in a couple of helper methods for the sake of it
const jill = Object.assign({
  skin(s) {
    target.strokeStyle = s

    return this
  },
  hint(n) {
    target.lineWidth = n

    return this
  }
}, jack)

// Prepare
jill
  // Pen color
  .skin('red')
  // Move to canvas mid
  .goto(canvas.width * 0.5, canvas.height * 0.5)
  // Pen up
  .pu()
  // Go back a bit
  .bk(half)
  // Turn right
  .rt(90)
  // Go back again
  .bk(half)
  // Pen down
  .pd()

const tick = (n) => {
  if (n === 0) {
    return
  }

  jill.move(size).turn(90)

  tick(n - 1)
}

// Be square
tick(4)

About

Helps with turtle graphics

Resources

License

Packages

No packages published