/* * ARTS 102 - Aesthetics of the Algorithmic Image * Johannes Goerz (johannes.goerz@gmail.com) * 2005-12-04 */ class Vector { float angle,x,y,l; Vector() { } void init(float _x, float _y) { this.x = _x; this.y = _y; this.l = sqrt( sq(_x) + sq(_y) ); this.angle = atan2( _y, _x); } void reset() { this.init( 0, 0); } float distance( Vector v ) { return sqrt( sq(this.x - v.x) + sq(this.y - v.y) ); } void add( Vector v ) { this.init( this.x + v.x, this.y + v.y ); } void sub( Vector v ) { this.init( this.x - v.x, this.y - v.y ); } void setAngle( float _a ) { this.angle = _a; this.x = cos( _a ) * this.l; this.y = sin( _a ) * this.l; } void setLength( float _l) { this.l = _l; this.x = cos( this.angle ) * _l; this.y = sin( this.angle ) * _l; } void draw( int x, int y ) { stroke(255,0,0); line(x,y,x+this.x,y+this.y); noStroke(); } }