We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Starburst
Page Index Toggle Pages: 1
Starburst (Read 817 times)
Starburst
Feb 21st, 2010, 11:25pm
 
Another visual basic 'sketch' turned to Processing. I'm surprised by how much less code I need to use to do the same things.
Code:

class Particle {
 float x = 0, y = 0, vx = 0, vy = 0;
 int maxDist = 0, lifeSpan = 0, col = 0;
 boolean live = false;

 Particle(float ix, float iy, int id, int ic) {
   x = ix;
   y = iy;
   maxDist = id;
   col = ic;
 }

}


//float HALFPI = PI / 2, SIXTEENTHS = PI / 16, THIRTYSECONDS = PI / 32;
int NUMSHOTS = 1024, maxRange = 0;
float OX = 0, OY = 0;//, GRAV = 4.7, gunangle = 0;
boolean staron = true;




Particle[] spray;


void setup() {
 size(800, 600, P2D);


 maxRange = width * height;

 OX = width / 2;
 OY = height / 2;
 
 spray = new Particle[NUMSHOTS];

 for (int i=0; i<NUMSHOTS; i++) {
   spray[i] = new Particle(OX, OY, 800, color(255));
 }

}

void draw() {

 float tmpang = 0;


 background(0);

 for(int i=0; i<NUMSHOTS; i++) {

   if (!(spray[i].live)) {
     if (staron) {
       tmpang = random(1) * TWO_PI;
       spray[i].vx = random(2) * cos(tmpang);
       spray[i].vy = random(2) * sin(tmpang);

       spray[i].x = OX;
       spray[i].y = OY - 1;
       spray[i].lifeSpan = 0;
       spray[i].col = color((int)random(127) + 128, (int)random(127) + 128, (int)random(127) + 128);
       spray[i].live = true;
     }
     
   } else {
     spray[i].x = spray[i].x + spray[i].vx;
     spray[i].y = spray[i].y + spray[i].vy;

     int offs = (int)(spray[i].y * width + spray[i].x);

     if ((offs >= 0) && (offs < maxRange)) {
       stroke(spray[i].col);
       point(spray[i].x, spray[i].y);
     } else {
       spray[i].live = false;
     }
     
     spray[i].lifeSpan = (int)(abs(spray[i].x - OX) + abs(spray[i].y - OY));

     if (spray[i].lifeSpan > spray[i].maxDist) {
       spray[i].live = false;
     }
     
   }

 }
}


void mousePressed() {
 staron = false;
}

void mouseReleased() {
 staron = true;
}
Re: Starburst
Reply #1 - Feb 22nd, 2010, 1:46am
 
NoahBuddy wrote on Feb 21st, 2010, 11:25pm:
Another visual basic 'sketch' turned to Processing. I'm surprised by how much less code I need to use to do the same things.


I'm having to learn Visual Basic properly for work (rather than just hacking around with it in the occasional Office macro).  I think the V should actually stand for Verbose  Wink
Re: Starburst
Reply #2 - Feb 22nd, 2010, 9:10am
 
Wicked Fast code!

I cam getting 2200FPS! when I use P2D.

Wow! You should post this on www.openrprocessing.org
Page Index Toggle Pages: 1