Raining demo in canvas with XST LIB.


winScreen(640, 480, 0);
setFps(30);
var particles = [], maxParticles=1000;
var w = getScreenWidth(), h = getScreenHeight();

for(var x = 0; x < maxParticles; x++) {
particles.push({
x: rnd(w),
y: rnd(h),
l: rnd(1),
vx: -4 + rnd(4) + 2,
vy: rnd(10) + 10
});
}

function draw() {
clear();
for(var i = 0; i < particles.length; i++) {
var p = particles[i];
line(p.x, p.y, p.x+p.l*p.vx, p.y+p.l*p.vy, 1, rgba(174,194,224,0.5));
}
}

function move() {
for(var c = 0; c < particles.length; c++) {
var p = particles[c];
p.x += p.vx;
p.y += p.vy;
if(p.x > w || p.y > h) {
p.x = rnd(w);
p.y = -20;
}
}
}

function main() {
draw();
move();
}

 

you can see it here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s