polygon-0
2012. 05. 13.

A variation of circles-1. The idea behind this was simple, let's draw polygons instead of circles. After several iterations of modifications to the drawing style, I ended up with this version, which looks nothing like what I'd imagined.

Click on the screen and see how it goes.

```r      = random
traces = []
count  = 50

class Trace
constructor: (c) ->
@x      = width() / 2
@y      = height() / 2
@length = r 50, height() * 0.4
@turns  = parseInt(r 3, 36)
@srad   = c * TWO_PI / parseFloat(count)

@bend = PI - PI * (@turns - 2) / parseFloat(@turns)
@t    = 0
@diff = 1

@r = r 255
@g = r 0, @r
@b = r 0, @g
@w = r 10, 30

alive: -> @turns > 0

live: ->
@x += @diff * cos(@rad)
@y += @diff * sin(@rad)

pushMatrix()
translate @x, @y
rotate    @srad + TWO_PI * @t / @length
stroke    @r, @g, @b
rect      0, 0, @w, @w
popMatrix()

@t += @diff

if @t >= @length
@t      = 0
@turns -= 1

mousePressed = ->
traces = []
for i in [0...count]
traces.push new Trace(i)

setup = ->
size         \$(window).width(), \$(window).height()
frameRate    90
background   255
fill         255, 30
strokeWeight 1
mousePressed()

draw = ->
traces =
for t in traces when t.alive()
t.live(); t```

## initial sketch

» launch polygon-0-pre

```p5     = processing
r      = random
traces = []

class Trace
constructor: (@x, @y) ->
@length   = r 10, height() * 0.5
@turns    = parseInt(r 3, 8)
@rad      = r p5.TWO_PI

@bend     = p5.PI - p5.PI * (@turns - 2) / parseFloat(@turns)
@progress = 0
@diff     = r 2, 5

@b        = r 150
@g        = r @b, 255
@r        = r @g, 255

alive: -> @turns > 0

live: ->
@x += @diff * cos(@rad)
@y += @diff * sin(@rad)
stroke @r, @g, @b
line   @px || @x, @py || @y, @x, @y
@px = @x
@py = @y

@progress += @diff

if @progress >= @length
@progress = 0
@turns    -= 1

setup = ->
size         \$(window).width(), \$(window).height()
frameRate    30
background   255
fill         255
strokeWeight 1

draw = ->
if __mousePressed() and traces.length < 20
traces.push new Trace(p5.mouseX, p5.mouseY)
traces = for t in traces when t.alive()
t.live(); t```
» capture | close