2012. 05. 16.
Me, melting.
p5 = processing img = null dirts = [] coarse = 16 started = false class Dirt constructor: (img, x, y, nx) -> idx = y * img.width + x @x = x + (p5.width - img.width) / 2 + random(coarse) @y = y + random(coarse) + coarse @c = img.pixels.getPixel(idx) @a = 255 @n = random(1000.0) @w = random(coarse * 0.5, coarse * 1.5) @wd = random(0.9, 0.997) @ay = 0.04 * (0.6 - abs(img.width / 2 - x) / parseFloat(img.width)) + 0.03 * noise(nx, @x * 0.02) + 0.00005 * (255 - brightness(@c)) @vy = 0 @ad = 0.95 + 0.05 * pow(@darkness() / 255.0, 2) draw: -> @vy += @ay @px = @x @py = @y @x += max(0.1, @vy) * (noise(@n, p5.frameCount * 0.1) - 0.5) @y += @vy @a *= @ad @w *= @wd strokeWeight @w stroke @c, @a line @px, @py, @x, @y alive: -> @y < p5.height and @a > 5 and @wd > 0.05 darkness: -> 255 - brightness(@c) preload = images: ["/images/glasses.jpg"] setup = -> size $(window).width(), $(window).height() frameRate 20 strokeWeight coarse noFill() img = loadImage('/images/glasses.jpg') mousePressed = -> if img.pixels.getLength() > 1 started = true background 255 dirts = [] nx = random(100.0) for y in [0...img.height] by coarse for x in [0...img.width] by coarse dirts.push new Dirt(img, x, y, nx) dirts = _(dirts).sortBy (u) -> [u.darkness] image(img, (p5.width - img.width) / 2, coarse) draw = -> if dirts.length == 0 and !started mousePressed() dirts = for d in dirts when d.alive() d.draw(); d