5:47fa6752d882 default tip
Anton Shestakov <av6@dwimlabs.net>, Wed, 16 Mar 2016 10:17:46 +0800
coffee: constructor doesn't have an implicit return

previous change 4:6683c9b69486

sierpinski.coffee

Permissions: -rw-r--r--

Other formats: Feeds:
class L
constructor: (@$el, @width, @height, @order) ->
@init()
init: ->
@pointer = 0
@rule = @a
@rows = []
fillrow = (len) ->
str = []
str.push ' ' for [1..len]
str.join ''
@rows.push fillrow @width for [1..@height]
for [1..@order]
@rule = @rule
.replace /a/g, 'x'
.replace /b/g, 'y'
.replace /x/g, @a
.replace /y/g, @b
return
putc: (x, y, c) ->
replacec = (str, pos, c) ->
str.substr(0, pos) + c + str.substr(pos + c.length)
if 0 <= x < @width and 0 <= y < @height
@rows[y] = replacec @rows[y], x, c
return
line: ->
switch @angle
when 0
@putc @x, @y, '__'
@x += 2
when 60
@putc @x, @y, '/'
@x++
@y--
when 120
@x--
@putc @x, @y, '\\'
@y--
when 180
@x -= 2
@putc @x, @y, '__'
when 240
@x--
@y++
@putc @x, @y, '/'
when 300
@y++
@putc @x, @y, '\\'
@x++
return
step: (visible) ->
if @pointer >= @rule.length
return false
redraw = false
switch @rule[@pointer]
when 'a', 'b'
@line()
redraw = true
when '-'
@angle = (@angle + 60 + 360) % 360
when '+'
@angle = (@angle - 60 + 360) % 360
@pointer++
if visible
if redraw
@draw()
else
@step visible
true
draw: ->
@$el.text @rows.join '\n'
class window.Sierpinski extends L
a: 'b-a-b'
b: 'a+b+a'
angle: 180
init: ->
@x = @width - 2
@y = @height - 2
super
class window.Flowsnake extends L
a: 'a-b--b+a++aa+b-'
b: '+a-bb--b-a++a+b'
angle: 0
init: ->
@x = @width / 2
@y = @height
super