Jump to Content

RSS Feeds:

Posts | Comments

http://ivanwlam.com/experiments/programming

Leave a Reply


Example

Click inside each applet to create new dot objects.
  • mousePos - Movement based on time and mouse, tracked, radius determined by enumeration of dots, color based on time. If you leave your mouse in one position, the dots will only move in a straight line.
  • moveDraw - Movement based on time, tracked, radius based on enumeration of dots, color based on time.
  • moveOnly - Movement based on time, not tracked, radius determined by enumeration of dots plus 20, color based on time.

Processing Code in Example

 //mousePos    Dot[] dots=new Dot[0];    void setup(){   size(345,345);   for(int i=0;i<dots.length;i++){   dots[i]=new Dot(i);   }   frameRate(30);  }    void draw(){   //background(200);   for(int i=0;i<dots.length;i++){   dots[i].move();   dots[i].display();   }  }    class Dot{   float radius;   float x;   float y;   float speed;   color c;     Dot(float dotNumber_){   radius=(dotNumber_);   while(radius%11==0 || radius%13==0){   radius=radius+radius;   }   x=mouseX;   y=mouseY;   c=color(millis()%255,second()*4,minute()*4);   }     void move(){   x=x+((mouseX*radius)%11)-5; // using the mouse position makes the dots move straight when you stop the mouse, but random when you move the mouse   y=y+((mouseY*radius)%13)-6;    // x=x+((millis()*radius)%11)-5; // try dividing the milliseconds and changing the frameRate to multiply to 1000  // y=y+((millis()*radius)%13)-6;     if(x>width-radius){   x=width-radius;   } else if(x<radius){   x=radius;   }     if(y>height-radius){   y=height-radius;   } else if (y<radius){   y=radius;   }   }     void display(){   c=color(((millis()+(1000*second()))/200)%255);   fill(c);   ellipse(x,y,radius,radius);   }  }    void mouseClicked(){   dots=(Dot[]) expand(dots, dots.length+1);   dots[dots.length-1]=new Dot(dots.length);  }

Processing Code in Example

 //moveDraw    Dot[] dots=new Dot[0];    void setup(){   size(345,345);   for(int i=0;i<dots.length;i++){   dots[i]=new Dot(i);   }   frameRate(30);  }    void draw(){   //background(200);   for(int i=0;i<dots.length;i++){   dots[i].move();   dots[i].display();   }  }    class Dot{   float radius;   float x;   float y;   float speed;   color c;     Dot(float dotNumber_){   radius=(dotNumber_);   while(radius%11==0 || radius%13==0){   radius=radius+radius;   }   x=mouseX;   y=mouseY;   c=color(millis()%255,second()*4,minute()*4);   }     void move(){  // x=x+((mouseX*radius)%11)-5; // using the mouse position makes the dots move straight when you stop the mouse, but random when you move the mouse  // y=y+((mouseY*radius)%13)-6;     x=x+((millis()*radius)%11)-5; // try dividing the milliseconds and changing the frameRate to multiply to 1000   y=y+((millis()*radius)%13)-6;     if(x>width-radius){   x=width-radius;   } else if(x<radius){   x=radius;   }     if(y>height-radius){   y=height-radius;   } else if (y<radius){   y=radius;   }   }     void display(){   c=color(((millis()+(1000*second()))/200)%255);   fill(c);   ellipse(x,y,radius,radius);   }  }    void mouseClicked(){   dots=(Dot[]) expand(dots, dots.length+1);   dots[dots.length-1]=new Dot(dots.length);  }

Processing Code in Example

 //moveOnly    Dot[] dots=new Dot[0];    void setup(){   size(345,345);   for(int i=0;i<dots.length;i++){   dots[i]=new Dot(i);   }   frameRate(30);  }    void draw(){   background(200);   for(int i=0;i<dots.length;i++){   dots[i].move();   dots[i].display();   }  }    class Dot{   float radius;   float x;   float y;   float speed;   color c;     Dot(float dotNumber_){   radius=(dotNumber_+20);   while(radius%11==0 || radius%13==0){   radius=radius+radius;   }   x=mouseX;   y=mouseY;   c=color(millis()%255,second()*4,minute()*4);   }     void move(){  // x=x+((mouseX*radius)%11)-5; // using the mouse position makes the dots move straight when you stop the mouse, but random when you move the mouse  // y=y+((mouseY*radius)%13)-6;     x=x+((millis()/500*radius)%11)-5; // try dividing the milliseconds and changing the frameRate to multiply to 1000   y=y+((millis()/500*radius)%13)-6;     if(x>width-radius){   x=width-radius;   } else if(x<radius){   x=radius;   }     if(y>height-radius){   y=height-radius;   } else if (y<radius){   y=radius;   }   }     void display(){   c=color(((millis()+(1000*second()))/200)%255);   fill(c);   ellipse(x,y,radius,radius);   }  }    void mouseClicked(){   dots=(Dot[]) expand(dots, dots.length+1);   dots[dots.length-1]=new Dot(dots.length);  }