/** * Node.pde * * Oscillating lines, vibrating shape, scrawl... * What else? * * A node is defined by a series of Bezier's curves. Each curves are drawing * from two static endpoints and one choosed randomly in the Node area. All * bends can be controlled, and define with the numbers of lines the Node shape. */ class Node { static final int CENTER_POINT = 0; // the node center point index value static final int RANDOM_POINT = 0; // the randomized point index value (must be used for modify this point's category) static final int FIRST_ENDPOINT = 1; // the first endpoint index value (must be used for modify this point specifically) static final int SECOND_ENDPOINT = 2; // the second endpoint index value (must be used for modify this point specifically) // for curves float complexity = 1; // the number of curves Range amplitude = new Range(0,1); // the node form amplitude Range[] bends = { // bends in order : the randomized point, the first endpoint, the last endpoint new Range(0,0), new Range(0,0), new Range(0,0) }; Range angle = new Range(0,360); // the used angle to determine the randomized point around the shape's center // fir static elements Point[] points = new Point[3]; // in order: the shape center, the first endpoint, the second endpoint float radius = 0; // the radius between the center and one endpoint float axis = 0; // the angle used to define the endpoints axis /** * Creates a new Node at the specified position, with a given opening * space between endpints. * * @param x the x coordinate of the center point * @param y the y coordinate of the center point * @param gap the interval value between the endpoints */ Node( float x, float y, float gap ) { this.radius = gap/2; points[0] = new Point( int(x), int(y) ); points[1] = new Point( int(x-radius), int(y) ); points[2] = new Point( int(x+radius), int(y) ); } /** * Modifies the Node amplitude in a radius contained between 0 and the passed value. * * @param value the maximum radius value */ void amplitude( float value ) { amplitude(0,value); } /** * Modifies the Node amplitude in a radius contained between value1 and value2. * * @param value1 the minimum radius value * @param value2 the maximum radius value */ void amplitude( float value1, float value2 ) { amplitude.set(value1,value2); } /** * Changes the shape's complexity. Increase or decrease the number of * drawing curves. * * @param val the number of curves */ void complexity( float val ) { complexity = val; } /** * Changes the Bezier curve's control value on a specified point. * Use this method to define a control value for this (kind of) * point as a randomized number between -value and value. * * @param value int or float * @param which specify which point used */ void bend( float value, int which ) { bend( -value, value, which ); } /** * Changes the Bezier curve's control values on a specified point. * Use this method to define a control value for this (kind of) * point as a randomized number between value1 and value2. * * @param value1 the first value for curve's control range * @param value2 the second value for curve's control range * @param which specify which point used */ void bend( float value1, float value2, int which ) { bends[which].set(value1, value2); } /** * Defines an angle between 0 and the passed value, used to determine * randomly a point around the node's center. * * @param value float: an angle in radian */ void angle( float value ) { angle(0,value); } /** * Defines an angle between value1 and value2, used to determine * randomly a point around the node's center. The angle * * @param value1 float: an angle in radian * @param value2 float: an angle in radian */ void angle( float value1, float value2 ) { angle.set(value1,value2); } /** * Moves the entire node's structure to the specified location. * * @param x the x coordinate of the new location * @param y the y coordinate of the new location */ void move( float x, float y ) { move(x,y,false); } /** * Moves the node's structure to a specified location. If * 'fixed' is set to true, only the center point is moved. * * @param x the x coordinate of the new location * @param y the y coordinate of the new location * @param fixed set both endpoints to their location or not */ void move( float x, float y, boolean fixed ) { if ( !fixed ) { for(int i=1; i<3; i++) points[i].move( int(x+(points[i].x-points[0].x)),int(y+(points[i].y-points[0].y)) ); } points[0].move( int(x), int(y) ); } /** * Rotates the node's structure to a specified axis. * * @param angle the axis angle in radian */ void rotate( float angle ) { update(angle,radius); } /** * Increase or decrease the opening space between the two endpoints. * * @param value the distance between the two points */ void gap( float value ) { update(axis,value/2); } /** * Updates endpoints's location. Endpoints are defined from the node's * center with the passed radius and the given angle for axis. * radius*2 equals the node's opening space. * * @param angle the axis angle in radian * @param radius the distance between node's center and boundaries */ void update( float angle, float radius ) { this.axis = angle; this.radius = radius; points[FIRST_ENDPOINT].move( points[0].x-int(cos(axis)*radius),points[0].y-int(sin(axis)*radius) ); points[SECOND_ENDPOINT].move( points[0].x+int(cos(axis)*radius),points[0].y+int(sin(axis)*radius) ); } /** * Returns the requested endpoint's parameters in an array containing * in order: the x axis coordinate, the y axis coordinate and the bend * value. * * @param which from which point * @return float[] */ float[] get( int which ) { return new float[]{ float(points[which].x), float(points[which].y), bends[which].current() }; } /** * Draw curve(s) */ void draw() { for( int i=0; i