• fullscreen
  • ball_and_spiral_motion.pde
  • /* espiral en movimiento, con retroceso
    */
    
    ball bola;
    
    void setup() {
      
      size(500, 500);
      
      bola = new ball();
      
    }
    
    void draw() {
      rectMode(CENTER);
      fill(0,10);
      noStroke();
      rect(width/2,height/2,width,height);
    bola.move();
    bola.display();
     //ball settings
    }
     class ball{
       
      color a;
      
     // a polar coordinate
    float r; // radius value
    float theta;
    float speed;
    float x1;
    float y1;
    float xp; 
    float yp; 
    
    ball() {
      
      a= color (0,0,250);
      r = 50; // radius value
      theta = 1;
      speed = 2;
      x1 = 100;
      y1 = 100;
      xp = r*cos(theta); //add random values to jitter
      yp = r* sin (theta);
      
    }
    
    void display(){
     strokeWeight(20);
    stroke(250,0,20,40);
    noFill ();
    ellipse(width/2 +xp,height/2 + yp, 50+r, 50+r);
    
    stroke(a,60);
    ellipse(width/2 +xp*-1,height/2 + yp*-1, 50+r, 50+r);
    
    }
    
    void move(){
    theta=theta+.1;
    r= r+2;
      xp = r*cos(theta);
      yp= r* sin (theta);
    if (xp > 400 ) {
    xp = 0;
    yp=0;
    
    
    
    }
    
    while (r == 400) {
    theta =theta *-.1;
    r = r*-1;
    
    }
    }
     }
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Efrain Garcia A

    motion balls OOP

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    motion balls OOP

    You need to login/register to comment.