Street Drawer

mrdoob's "Map Generator" (http://jsdo.it/mrdoob/xI3u) ported to coffeescript

HTML

<canvas id='world'></canvas>

CSS

body {
    margin: 0;
    overflow: hidden;
}

CoffeeScript

# forked from mrdoob's "Map Generator" http://jsdo.it/mrdoob/xI3u
# Based on Jared Tarbell's Substrate algorithm concept.
# http://www.complexification.net/gallery/machines/substrate/index.php


# tau is a whole turn, whereas pi is unusefully half a turn
# http://jsfiddle.net/1j01/HvHdZ/
tau = #C/r    #%##%#|#%##%#
          #%###     |     #%###
       #%#          |          #%#
     #%#            |            #%#
   #%#              |              #%#
  ##                |                ##
 ##                 |                 ##
 #                  |                  #
##                  |                  ##
#                   |                   #
- - - - - - Math.PI + Math.PI - - - - - 0
#                   |                   #
##                  |                  ##
 #                  |                  #
 ##                 |                 ##
  ##                |                ##
   #%#              |              #%#
     #%#            |            #%#
       #%#          |          #%#
         #%##%#     |     #%###
              #%##%#|#%##%#

{cos, sin, pow, random: rand} = Math

class Boid
    constructor: ({@x, @y, angle})->
    
        @angle = pow(rand(), 20) + angle
        @dx = cos @angle
        @dy = sin @angle
    
        @life = rand() * 100 + 100

    update: ->

	    ctx.strokeStyle = '#000000'
	    ctx.beginPath()
	    ctx.moveTo(@x, @y)

	    @x += @dx * 2
	    @y += @dy * 2
	    @life -= 2

	    ctx.lineTo(@x, @y)
	    ctx.stroke()

	    index = (~~@x + width * ~~@y) * 4

	    (@life <= 0 or
        @x < 0 or @x > width or
        @y < 0 or @y > height or
        image.data[index + 3] > 0)


width = window.innerWidth
height = window.innerHeight

canvas = document.getElementById 'world'
canvas.width = width
canvas.height = height

ctx = canvas.getContext '2d'
image = null

boids = [
    new Boid 
        x: width / 2
        y: height / 2
        angle: rand() * 360 * Math.PI / 180
]

step = ->
    image =...