I made a pretty cool procedural drawing tool of sorts, based on flowfields (which I've been playing with the last couple of days). Unfortunatly I can't attach pictures from the ipad (figures, Apple only works inside of it's own little universe), but because the code is pretty short I can share that (thanks for the blessing Hotshot, would be cool to have a sort of DBF Codea code repository).
Here's the code.
-- flowfield
function setup()
backingMode(RETAINED) -- retain screen pixels
background(0, 0, 0, 255) -- draw black background
col = color(math.random(255), math.random(255), math.random(255)) -- set random color
parameter("swirls", 1/2000, 1/50, 1/100) -- declare interactive swirlyness parameter
parameter("fade", 0, 1, 0) -- declare interactive screen fade parameter
parameter("transparency", 1, 10, 2.5) -- declare interactive line alpha parameter
watch("particles") -- watch particle count
touches = {} -- make container to track screen touches
parts = {} -- make container for particles
end
function touched(touch) -- track all screen touches
if touch.state == ENDED then
touches[touch.id] = nil
col = color(math.random(255), math.random(255), math.random(255), transparency*12.5)
else touches[touch.id] = touch
end
end
function draw()
fill(0, 0, 0, fade*100) -- set fill alpha acording to fade parameter
rect(0,0, WIDTH, HEIGHT) -- draw transparent rectangle to slowly fade screen
particles = #parts -- track nr of particles
col.alpha = transparency*12.5 -- set line alpha to transparancy parameter
fill(col)
for i, p in pairs(parts) do -- loop through particles
pixel = noise(p.x*swirls, p.y*swirls) -- define location of noisemap pixel
brightness = (pixel+1) / 2 * p.mult -- define brightness between 0-1
speed = brightness * p.mult -- get particle speed value
size = 2 + speed/2 * p.mult -- get particle size value
angle = brightness * 360 * math.pi / 180 -- get angle based on pixel brightness
p.x = p.x + math.cos(angle) * speed -- move particle over X
p.y = p.y + math.sin(angle) * speed -- move particle over Y
ellipse(p.x, p.y, size) -- draw particle
if p.x < 0 or p.x > WIDTH or p.y < 0 or p.y > HEIGHT then
table.remove(parts, i) -- remove particle if outside of screen
end
end
for i, t in pairs(touches) do -- add particles at touch position
if t.state == MOVING or t.state == BEGAN then
table.insert( parts, {x=t.x, y=t.y, mult=(1.5 + math.random() * 1.5)} )
end
end
end Would love to hear what you think about it, you can create a bunch of really interesting effects by adjusting the sliders.
