• fullscreen
  • Vec2D_1_2.pde
  • // import the necessary toxiclibs libraries
    import toxi.geom.*; 
    import toxi.processing.*;
    
    // declare the vectors we will be using
    ToxiclibsSupport gfx;
    Vec2D m, n, p;
    
    void setup() {
      size(400,400);
      smooth();
      // initialise the ToxiclibsSupport class
      gfx=new ToxiclibsSupport(this);
      // create the three vectors
      m = new Vec2D(50,50); 
      n = new Vec2D(30,30);
      p = new Vec2D(10,10);
      background(0);
      strokeWeight(1);
    }
    
    void draw() {
      // translate so the centre of the screen is the origin
      translate(200,200);
      for(int i=0;i<20;i++){
        // rotate each of the vectors a little, change these
        // to produce a variety of patterns
        m.rotate(0.01);
        n.rotate(0.021);
        p.rotate(0.052);
        // calculate the angle between m and n vectors and
        // use this to set the stroke colour
        float ang = m.angleBetween(n,true);
        stroke(100*ang,255-100*ang,100+50*ang);
        // create a temporary vector for the final position of
        // the dot so we don't change our original vectors
        Vec2D blob = m.add(n);
        blob.addSelf(p);
        // draw a dot at the x,y co-ordinates of the sum of the
        // three vectors
        // we can now do this just by passing the Vec2D object
        // to the point command, easy!
        gfx.point(blob);
      }
    }
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    Justin Pinkney

    Toxiclibs tutorials - Vec2D

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

    Writing some very basic tutorials for the Toxiclibs library.
    Part 1 Vec2D - http://www.cutsquash.com/2011/12/toxiclibs-tutorials-1-vec2d/

    Geo Meadows
    3 Dec 2011
    Thanks for taking the trouble to produce the tutorials, very interesting.
    hey Justin
    cool initiative. are you ok with adding these sketches here:
    http://www.openprocessing.org/classrooms/?classroomID=404 ?
    Justin Pinkney
    4 Dec 2011
    Hey thanks, I will be very happy if these tutorials end up being of any use to anyone else, and I will endeavour to add to the at least semi regularly.
    You need to login/register to comment.