|
Author |
Topic: help with spray (Read 1432 times) |
|
Eilsoe
|
help with spray
« on: Mar 9th, 2005, 12:29am » |
|
hey all! I'm fairly new to p5 (startet 2 days ago)... I've been trying to create a spray system using points and arrays, but the points are created in an instant on load through the array... looks kinda weird that a spray system has to initiate properly through several "squirts" is there a way to initiate each particle at run, so it actually starts as a spray? example: www.avalon-rev.dk/p5/spray/
|
« Last Edit: Mar 9th, 2005, 12:40am by Eilsoe » |
|
Kirupaforum moderator...
|
|
|
st33d
|
Re: help with spray
« Reply #1 on: Mar 9th, 2005, 2:24am » |
|
I thought of creating the objects on the fly until the threshold had been reached but since the lastX and lastY seem to initialise to zero all the time I had to move their initialisation to the constructor. But it's a slow increasing spray, hope this was what you meant. Code: int max = 1000; int filler = 1; Dot[] myDot = new Dot[max]; void setup(){ stroke(255); background(0); size(500, 500); framerate(60); noSmooth(); myDot[0] = new Dot(150,250,random(15,20)); myDot[1] = new Dot(150,250,random(15,20)); } void clearscr(){ for(int a=0;a<width;a++){ for(int b=0;b<height;b++){ set(a,b,0); } } } int a=0; void loop(){ clearscr(); if (filler<max-1){ filler++; myDot[filler] = new Dot(150,250,random(15,20)); } for(int a=0;a<filler;a++){ myDot[a].move(); myDot[a].draw(); } } class Dot{ float xpos, ypos, drop, vx; float lastX,lastY;//moved Dot(float xposV, float yposV, float leftV){ xpos = xposV; ypos = yposV; lastX = xpos;//moved lastY = ypos;//moved drop = random(-1,-10); vx = leftV; } void draw(){ line(xpos,ypos, lastX, lastY); lastX = xpos; lastY = ypos; } void move(){ drop += 0.1; ypos += drop; vx *= 0.99; xpos += vx; if(xpos>width){ xpos = width; vx *= 0.1; vx = -vx; drop *= 0.2; } if(ypos>height){ ypos = 250; xpos = 150; lastX = 150; lastY = 250; drop = random(-1,-10); vx = random(15,20); } } } |
|
|
I could murder a pint.
|
|
|
Eilsoe
|
Re: help with spray
« Reply #2 on: Mar 9th, 2005, 12:32pm » |
|
great man, thanks, just what I wanted odd question: you start off by creating 2 instances on setup, why is that? I tried removing one, and it froze during playback... (?)
|
Kirupaforum moderator...
|
|
|
st33d
|
Re: help with spray
« Reply #3 on: Mar 9th, 2005, 12:45pm » |
|
int filler = 0; I should have set filler to start at zero but I just plonked another object making line in there. Sometimes I practically just throw code at the computer and hope it works, or just repaste whole chunks of code when I could be writing a function instead. Sorry about that.
|
I could murder a pint.
|
|
|
Eilsoe
|
Re: help with spray
« Reply #4 on: Mar 9th, 2005, 12:54pm » |
|
oh ok, don't worry about, I have a habit of throwing code at it too optimization comes second, functionality first.
|
Kirupaforum moderator...
|
|
|
|