• fullscreen
  • bouncingballA25Sept08.pde
  • thing_class.pde
  • import noc.*;
    
    boolean showVectors = true;
    boolean check = false;
    
    Thing T;
    
    void setup()
    {
      size(640,480);
      T = new Thing(new Vector3D(1,1),new Vector3D(0,0),new Vector3D(420,100));
      translate(320,0);
      smooth();
      ellipseMode(CENTER);
      noStroke();
      fill(200);
    }
    
    void draw()
    {
      background(0);
      T.go();  
    }
    
    void drawVector(Vector3D v, Vector3D l, float scayl)
    {
      pushMatrix();
      translate(l.x,l.y);
      popMatrix();
    }
    
    void mousePressed()
    {
      T = new Thing(new Vector3D(1,1),new Vector3D(0,0),new Vector3D(mouseX,mouseY));
    }
    
    
    
    // Simple Vector3D
    // Daniel Shiffman <http://www.shiffman.net>
    // The Nature of Code, Spring 2006
    
    // Demonstrates simple motion with a Thing class
    
    // Created 2 May 2005
    
    // A class to describe a thing in our world
    // Has variables for location, velocity, and acceleration
    
    class Thing {
      Vector3D loc;
      Vector3D vel;
      Vector3D acc;
    
      int change = 1;
      //The Constructor (called when the object is first created)
      Thing(Vector3D a, Vector3D v, Vector3D l) {
        acc = a.copy();
        vel = v.copy();
        loc = l.copy();
      }
    
      //main function to operate object)
      void go() {
        update();
        borders();
        render();
      }
    
      //function to update location
      void update() {
        vel.add(acc);
        loc.add(vel);
      }
    
      void borders() {
        if (loc.y >= height-8) 
        {      
          vel.y*=-1;
          loc.y = height-8;
        }
        if (loc.x >= width-8) 
        {       
          change=-1;
        }
        if (loc.x <= 0) 
        {      
          change=1;
        }
         acc.x-=0.02; 
         if(acc.x<=0) acc.x=0;     
         vel.x = abs(vel.x)-0.007;
         if(abs(vel.x)<=0) vel.x = 0;
         vel.x*=change;     
    
      }
    
      //function to display
      void render() {    
        ellipse(loc.x,loc.y,16,16);
        //drawVector(vel,loc,10);
      }
    
    }
    
    
    
    
    
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    rajan

    vector ball bounce

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

    You need to login/register to comment.