Advertisement
Guest User

Circle path

a guest
Sep 16th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. Rotor r;
  2. float timer = 0;
  3. int mode;
  4.  
  5. void setup() {
  6.   size(1000,600);
  7.   smooth();
  8.   noFill();
  9.   frameRate(60);
  10.   background(255);
  11.  
  12.   mode = 1;
  13.   r = new Rotor(random(width/2)+100,random(height/2)+100,random(40,100));
  14. }
  15.  
  16. void draw() {
  17.   noStroke();
  18.   fill( 255,255,255, 10 );
  19.   rect(0,0,width,height);
  20.   noFill();
  21.  
  22.   float t = frameCount / 100.0;
  23.   timer = timer + frameRate/1000;
  24.  
  25.   r.drawRotor(mode);
  26.  
  27.   if(timer > timeLimit()){
  28.     timer = 0;
  29.    
  30.     if(mode != 1){              
  31.       //background(255);
  32.       float newR = random(40,100);
  33.       float newX = r.centerX + cos(r.angle) * (r.radius - newR);
  34.       float newY = r.centerY + sin(r.angle) * (r.radius - newR);      
  35.       r.newPos(newX, newY);
  36.       r.radius = newR;      
  37.     }
  38.     mode *= -1;
  39.   }
  40. }
  41.  
  42. float timeLimit(){
  43.   float timeLimit = random(50);
  44.   return timeLimit;
  45. }
  46.  
  47. class Rotor {
  48.  
  49.   color c;
  50.   int thickness;
  51.   float xPoint;
  52.   float yPoint;
  53.   float radius;
  54.   float angle = 0;
  55.   float centerX;
  56.   float centerY;
  57.  
  58.   Rotor(float cX, float cY, float rad) {
  59.     c = color(0);
  60.     thickness = 1;
  61.     centerX = cX;
  62.     centerY = cY;
  63.     radius = rad;
  64.   }
  65.  
  66.   void newPos(float x, float y){
  67.     centerX = x;
  68.     centerY = y;
  69.   }
  70.  
  71.   void drawRotor(int mode) {
  72.     stroke(c);
  73.     strokeWeight(thickness);
  74.     if(mode == 1){
  75.       angle += frameRate/1000;
  76.     }else{
  77.       radius += 2;
  78.     }
  79.     xPoint = centerX + cos(angle) * radius;
  80.     yPoint = centerY + sin(angle) * radius;
  81.     ellipse(xPoint, yPoint,thickness,thickness);
  82.   }
  83.  
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement