Created
June 1, 2012 11:54
-
-
Save Bri-G/2851560 to your computer and use it in GitHub Desktop.
particles from emitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- A converted javascript (by Keith Peters) adapted for Codea by Bri_G | |
-- ref. http://www.bit-101.com/blog/?p=3150 | |
-- excellent description given | |
-- Use this function to perform your initial setup | |
function setup() | |
-- initialisations of system and variables used | |
displayMode(FULLSCREEN) | |
numPoints = 300 | |
gravity = 0.1 | |
points = {x={}, y={}, vx={}, vy={}, radius={}, length={}, colr={}} | |
wide = WIDTH | |
height = HEIGHT | |
emitterX = wide/2 | |
emitterY = 800 | |
initPoint(#points.x + 1) | |
end | |
-- This function gets called once every frame | |
function draw() | |
-- This sets a dark background color | |
background(0, 0, 0, 255) | |
-- This sets the line thickness | |
strokeWidth() | |
-- Do your drawing here | |
fill(29, 181, 212, 255) | |
len = #points.x | |
for i = 1, len do | |
fill(points.colr[i]) | |
ellipse(points.x[i], points.y[i], points.radius[i], points.radius[i]) | |
end | |
addPoint() | |
update() | |
end | |
function update() | |
len = #points.x | |
for i = 1, len do | |
points.vy[i] = points.vy[i] - gravity | |
points.x[i] = points.x[i] + points.vx[i] | |
points.y[i] = points.y[i] + points.vy[i] | |
if (points.x[i] > wide or points.x[i] < 0 or points.y[i] > height or points.y[i] < 0) then | |
initPoint(i) | |
end | |
end | |
end | |
function addPoint() | |
if #points.x < numPoints then | |
initPoint(#points.x + 1) | |
end | |
end | |
function initPoint(i) | |
points.x[i] = emitterX | |
points.y[i] = emitterY | |
points.vx[i] = math.random(4) - 2 | |
points.vy[i] = math.random(5) - 2 | |
points.radius[i] = math.random(10) + 1 | |
points.colr[i] = color(math.random(50,200),math.random(50,200),math.random(50,200),255) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment