// ========================================================================= // Markus Lerner // http://www.markuslerner.com // 2003-10-28 // // Behavior: Mechanical vs. Organic // ========================================================================= BImage bgImage; int num = 25; int hSpacing = 20; float friction = 0.8f; boolean gLock; boolean tFixed; SpringPoint p[]; // button vars int buttonNum, state; Button[] buttons; BFont univers; // setup =================================================================== void setup() { size(600, 300); background(0,0,0); // smooth(); framerate(60); ellipseMode(CENTER_DIAMETER); bgImage = loadImage("bg_be.jpg"); image(bgImage, 0, 0); p = new SpringPoint[num]; for(int i=0; i= buttonNum) { state = 0; } } } // mouse methods =========================================================== void mousePressed() { for(int i=0; i0; i--) past[i].set(past[i-1]); past[0].set(pos.x, pos.y); waitCount = 0; } if(state == 1) { drawPast(); } draw(); } void drawPast() { noStroke(); for(int i=0; i=x && mx<=x+w && my>=y && my<=my+h) state = id; } } // General vector class for 2D vectors ===================================== class Vec2D { float x,y; // Constructor with no parameters Vec2D() { x=0; y=0; } Vec2D(float _x,float _y) { x=_x; y=_y; } Vec2D(Vec2D v) { x=v.x; y=v.y; } void set(float _x,float _y) { x=_x; y=_y; } void set(Vec2D v) { x=v.x; y=v.y; } void add(float _x,float _y) { x+=_x; y+=_y; } void add(Vec2D v) { x+=v.x; y+=v.y; } void sub(float _x,float _y) { x-=_x; y-=_y; } void sub(Vec2D v) { x-=v.x; y-=v.y; } void mult(float m) { x*=m; y*=m; } void div(float m) { x/=m; y/=m; } float length() { return sqrt(x*x+y*y); } float angle() { return atan2(y,x); } void normalise() { float l=length(); if(l!=0) { x/=l; y/=l; } } Vec2D tangent() { return new Vec2D(-y,x); } void rotate(float val) { // Due to float not being precise enough, double is used for the calculations double cosval=Math.cos(val); double sinval=Math.sin(val); double tmpx=x*cosval - y*sinval; double tmpy=x*sinval + y*cosval; x=(float)tmpx; y=(float)tmpy; } }