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.
IndexProgramming Questions & HelpPrograms › spinner/follower source code
Page Index Toggle Pages: 1
spinner/follower source code (Read 532 times)
spinner/follower source code
Mar 14th, 2008, 7:54am
 
hey guys. this is my first sorce code goes here. In this, i was create a funky particles where thats particles controlling theta and radius by mouse position, click for generate it. i hope you copy/paste this code here

//-start here

shaker[] sr;
int nmb=500;

void setup(){
 size(500,500);
 background(0);
 
 sr=new shaker[nmb];
 
 for(int a=0;a<nmb;a++){
   sr[a]=new shaker(250,250,random(-PI,PI),183,211,232,a);
 }
}

void draw(){
 fill(0,10);
 rect(0,0,width,height);
 
 for(int a=0;a<nmb;a++){
   sr[a].trail();
 }
}

void mousePressed(){
 for(int a=0;a<nmb;a++){
   sr[a]=new shaker(250,250,random(PI),183,211,232,a);
 }
}

class shaker{
 int id; //index
 float x,y; //position
 float tdir; //theta direction
 int rd,gr,bl; //colors
 
 float themo; //controlled by mouse position
 float spd,spd2; //speed and delay
 
 shaker(float x0,float y0,float tdir0,int rd0,int gr0,int bl0,int id0){
   //construct this
   x=x0;
   y=y0;
   tdir=tdir0;
   rd=rd0;
   gr=gr0;
   bl=bl0;
   id=id0;
   
   //speed init
   spd=random(0.5,2.5);
   spd2=random(0.995,1.005);
 }
 
 void trail(){
   //control theta by mouse position
   themo=atan2(250-mouseX,250-mouseY);
   
   //circular moves
   x+=cos(themo+tdir)*spd+(id%3);
   y+=sin(themo+tdir)*spd+(id%3);
   
   //make it wrap around
   while(x<0){
     x+=width;
   }
   while(x>=width){
     x-=width;
   }
   while(y<0){
     y+=height;
   }
   while(y>=height){
     y-=height;
   }
   
   //trail it
   stroke(rd,gr,bl,32);
   point(x,y);
   
   spd*=spd2;
 }
}

//-end

happy coding and tell me if you works thats code Smiley
Page Index Toggle Pages: 1