Created
June 1, 2012 11:52
-
-
Save Bri-G/2851553 to your computer and use it in GitHub Desktop.
particles
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=3148 | |
-- excellent description given | |
-- Use this function to perform your initial setup | |
function setup() | |
-- initialisations of system and variables used | |
displayMode(FULLSCREEN) | |
points = {x={}, y={}, z={}, vx={}, vy={}, size={}, colr={}} | |
numPoints = 50 | |
bounce = -1 | |
wide = WIDTH | |
height = HEIGHT | |
for i = 1, numPoints do | |
points.x[i] = math.random(wide) | |
points.y[i] = math.random(height) | |
points.vx[i] = math.random(6,10) - 5 | |
points.vy[i] = math.random(6,10) - 5 | |
points.size[i] = math.random(10,30) | |
points.colr[i] = color(math.random(50,255),math.random(50,255), math.random(50,255),255) | |
end | |
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(1) | |
-- Do your drawing here | |
for i = 1,numPoints do | |
pts = points.size[i] | |
fill(points.colr[i]) | |
ellipse(points.x[i], points.y[i], pts, pts) | |
end | |
update() | |
end | |
function update() | |
for i = 1, numPoints do | |
points.x[i] = points.x[i] + points.vx[i] | |
points.y[i] = points.y[i] + points.vy[i] | |
if points.x[i] > wide then | |
points.x[i] = wide | |
points.vx[i] = points.vx[i]*bounce | |
elseif points.x[i] < 0 then | |
points.x[i] = 0 | |
points.vx[i] = points.vx[i]*bounce | |
end | |
if points.y[i] > height then | |
points.y[i] = height | |
points.vy[i] = points.vy[i]*bounce | |
elseif points.y[i] < 0 then | |
points.y[i] = 0 | |
points.vy[i] = points.vy[i]*bounce | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment