/* 081212 Christmas code by MIska Knapek - miska@knapek.org thanks to the Processing team! - check which buttons to press at the bottom of the code over by the mousePressed() function. */ import processing.opengl.*; float half_arrow_length = 80; float arrow_stroke_weight = 7; int transparency_level = 128; color[] arrow_colours = { color(255, 0, 0, transparency_level), color(0, 255, 0, transparency_level), color( 0,0,255, transparency_level) }; float x_offset = 400; float y_offset = 200; int num_of_columns = 15; int num_of_rows = 17; float column_x_spacing = 25; float row_y_spacing = 25; int curr_angle_index_vs_lookuptable_length = 0; int curr_angle_incr = 20; // use the following if we're using the mouse to control the speed int max_curr_angle_incr = 80; // for faster cos/sin values int num_of_lookuptable_positions = 100000; float[] cos_lookup_table = new float[ num_of_lookuptable_positions ]; float[] sin_lookup_table = new float[ num_of_lookuptable_positions ]; void setup(){ size( 1280, 768, OPENGL); frameRate(25); smooth(); gen_cos_n_sin_lookup_tables(); println(" cos_lookup_table "+cos_lookup_table[99998]); } void draw(){ // set the speed according to the mouse X int curr_angle_incr = int((mouseX/float(width))*max_curr_angle_incr) + 10; // prepare background( 255 ); noFill(); strokeWeight( arrow_stroke_weight ); //stroke( 128, 0, 0 ); //println(" working on angle "+curr_angle_index_vs_lookuptable_length ); //// draw // find the vectors to the end of the line float half_length_vector_x = cos_lookup_table[curr_angle_index_vs_lookuptable_length] * half_arrow_length; float half_length_vector_y = sin_lookup_table[curr_angle_index_vs_lookuptable_length] * half_arrow_length; for( int curr_row_num = 0; curr_row_num < num_of_rows; curr_row_num++ ){ float curr_y = y_offset + ( curr_row_num*row_y_spacing ); for( int curr_col_num = 0; curr_col_num < num_of_columns; curr_col_num++){ float curr_x = x_offset + ( curr_col_num*column_x_spacing ); int curr_stroke_colour_index = ((curr_row_num*num_of_columns)+curr_col_num) % arrow_colours.length; stroke( arrow_colours[ curr_stroke_colour_index ] ); strokeWeight( arrow_stroke_weight ); line( curr_x+half_length_vector_x, curr_y+half_length_vector_y, curr_x-half_length_vector_x, curr_y-half_length_vector_y ); } } // fetch the correct index for the current angle curr_angle_index_vs_lookuptable_length = (curr_angle_index_vs_lookuptable_length+curr_angle_incr )%num_of_lookuptable_positions; } // - - - - - - - - void gen_cos_n_sin_lookup_tables(){ // how big each step has to be to step through pi in the given number of steps to fill our cos/sin lookup tables float step_length = TWO_PI / float( num_of_lookuptable_positions ); for( int curr_step = 0; curr_step < num_of_lookuptable_positions; curr_step++ ){ cos_lookup_table[ curr_step ] = cos( curr_step*step_length); sin_lookup_table[ curr_step ] = sin( curr_step*step_length); } } // - - - - - - - - // here's where we can change things // ... such as the col/row count and spacing... the arrow length / width... rotation speed... void keyPressed(){ //// changing column count? q/w if( key == 'q'){ num_of_columns -= 1; // subtract columns if( num_of_columns == 0 ){ // stop it from getting a zero value num_of_columns = 1; } } if( key == 'w'){ num_of_columns += 1; // add columns } //// changing row count? a/s if( key == 'a'){ num_of_rows -= 1; if( num_of_rows == 0 ){ // stop it from getting a zero value num_of_rows = 1; } } // add if( key == 's'){ num_of_rows += 1; } //// changing column spacing? r/t if( key == 'r'){ column_x_spacing -= 0.25; } // add if( key == 't'){ column_x_spacing += 0.24; } //// changing row spacing? f/g if( key == 'f'){ row_y_spacing -= 0.25; } // add if( key == 'g'){ row_y_spacing += 0.25; } //// changing arrow length? u/i if( key == 'u'){ half_arrow_length -= 0.5; } // shorten if( key == 'i'){ half_arrow_length += 0.5; } //// changing arrow width? j/k if( key == 'j'){ arrow_stroke_weight -= 0.25; if( arrow_stroke_weight < 0.25 ){ arrow_stroke_weight = 0.25; } } // make more narrow if( key == 'k'){ arrow_stroke_weight += 0.25; if( arrow_stroke_weight > 10.0 ){ arrow_stroke_weight = 10; } } //// move the offset position // left/right if( keyCode == LEFT){ x_offset -= 1; if( x_offset < 0 ){ x_offset = 0; } } if( keyCode == RIGHT){ x_offset += 1; if( x_offset > width-10 ){ x_offset = width-10; } } // up/down if( keyCode == UP){ y_offset -= 1; if( y_offset < 0 ){ y_offset = 0; } } if( keyCode == DOWN){ y_offset += 1; if( y_offset > height-20 ){ y_offset = height-20; } } // change transparency? 4/5 ///// reset values? if( key == 'x'){ half_arrow_length = 80; arrow_stroke_weight = 10; x_offset = 400; y_offset = 200; num_of_columns = 15; num_of_rows = 17; column_x_spacing = 25; row_y_spacing = 25; } ///// a setting I like... if( key == 'z'){ half_arrow_length = 80; arrow_stroke_weight = 2; x_offset = 400; y_offset = 200; num_of_columns = 25; num_of_rows = 25; column_x_spacing = 20; row_y_spacing = 20; } } // - - - - - - - - // - - - - - - - -