• fullscreen
  • Pendulum.pde
  • pendulums.pde
  • class Pendulum{
    
      float theta_0;
      float theta;
      PVector leng = new PVector(0,0);
      float g = 9.8;
      int conv = 4000000; //conversion factor from physics units to pixels
      
      Pendulum(float length_, float theta_0_){
        theta_0 = theta_0_;
        leng.y = length_;
      }
      
      void update(float time){
        theta = theta_0*cos(sqrt(g/leng.mag())*time);
      }
      
      void render(){
        pushMatrix();
        translate(width/2,0);
        rotate(theta);
        line(0,0,conv*leng.x,conv*leng.y);
        ellipse(conv*leng.x,conv*leng.y,10,10);
        popMatrix();
      }
    }
    
    Pendulum p;
    float t = 0.0;
    ArrayList pends;
    float[] lengths = new float[30];
    float g = 9.8;
    
    void setup(){
      size(400,400);
      lengths[0] = 0.00009;
      for(int i=1;i<30;i++){
        //arrange lengths so frequency difference between pendulums is constant
        lengths[i] = g*lengths[i-1]/( g + 4*PI*PI*lengths[i-1] + 4*PI*sqrt(g*lengths[i-1]) );
      }
      
      
      pends = new ArrayList();
      for(int i=0; i<30; i++){
        p = new Pendulum(lengths[i],0.2);
        pends.add(p);
      }
      smooth();
    }
    
    void draw() {
      background(255);
      //update current time
      t+=0.0002;
      for(int i = 0;i<pends.size();i++){
        p = (Pendulum) pends.get(i);
        // fetch position of current pendulum at time t
        p.update(t);
        // draw pendulum
        p.render();
      }
    }
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Justin Pinkney

    Pendulum Waves

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

    A quick and rough recreation of the Pendulum Waves demonstration made popular lately the Havard lecture demonstration video:
    http://bit.ly/mScLo8

    Shows lots of nice beat patterns coming and going and also at time reminiscent of the 'Spinning Dancer' illusion.

    Blog post: http://www.cutsquash.com/blog/?p=62

    It would be great to build that as a cool clock!
    You need to login/register to comment.