/************************************* * Author: Jonathan Seguin * Last Modified: March 3rd 2010 * Problem Set: 2 * Question: 2 **************************************/ //This program uses a function to create a brush. //The brush is dynamic and can be changed by specifying //different parameters. Animation is achieved by //constantly updating arguments via mouseDragged() //or draw(); //I apologize for making you mark this. void setup () { size (720,480); background (0); smooth(); cursor(CROSS); } //Variables int rot = 0; // brush rotation rate int rad = 0; // brush radius int[] min_max_RGB = { 100,255,0,0,150,255}; //color preset: min red, max red, min green, max green, min blue, max blue boolean alt = false; // used to alternate between expansion/contraction //Functions //========== // brush() creates a brush with 6 lines or dots radiating outwards // from a central point distanced from that point by a radius. // parameters x,y = position // rad = radius; // stickLength = set to 1 for dots, increase for lines // thickness = thickness of lines or dots // rotations = current rotation state // colorRanges = array of min and max red, blue, green values to give // the brush a two-tone colour void brush (int x, int y, int rad, int stickLength, int thickness, int rotations, int[] colorRanges) { pushMatrix(); translate (x, y); rotate(radians(rotations)); for (int a = 0; a < 6; a++) { for (int b = 0; b < stickLength; b++) { pushMatrix(); translate(0, 0); rotate(map(a, 0, 6, 0, TWO_PI)); strokeWeight(thickness); stroke (map(b,0,stickLength,colorRanges[0],colorRanges[1]), map(b,0,stickLength,colorRanges[2],colorRanges[3]), map(b,0,stickLength,colorRanges[4],colorRanges[5]),150); line (0, 0+b+rad, 0, 0+b+rad); popMatrix(); } } popMatrix(); } // Use keys 1-4 to switch between different // presets. Click+dragging mouse will draw with // brush. Press any other key other than // 1,2,3,4,c to reset to default brush. void mouseDragged () { if (key =='1') { regular(); } else if (key=='2') { tornado(60); } else if (key=='3') { expand_contract(50); } else if (key=='4') { //eraser fill(0); noStroke(); ellipse(mouseX, mouseY, 100,100); } else { brush (mouseX, mouseY,0,30,1,rot,min_max_RGB); } } //Time Modifier Presets //========================= //Default Animated Spin void regular () { int[] min_max_RGB = { 220,255,100,200,0,0 }; // set colour brush (mouseX, mouseY,10,20,1,rot, min_max_RGB); // call brush rot+=4; // rotation rate } // Expand, Reset to Small, Repeat void tornado (int x) { //modify arugments rad++; // increase radius if (rad > x) { // reset radius rad = 0; } int[] min_max_RGB = { 0,0,150,200,100,255 }; // set colour brush (mouseX, mouseY,rad,10,5,rot,min_max_RGB); // call brush rot+=12; // rotation rate } // Expand, Contract, Repeat void expand_contract (int x) { //modify arugments if (rad <= 0) { //conditional to alternate operations alt = false; } else if (rad >= x) { alt = true; } if (alt == true) { rad-=1; //shrink radius } else { rad+=1; //expand radius } int[] min_max_RGB = { 0,0,150,255,0,0 }; // set colour brush (mouseX, mouseY,rad,10,2,rot,min_max_RGB); // call brush rot+=8; // rotation rate } void draw () { //press 'c' or 'C' to clear screen if (keyPressed==true) { if (key == 'c' || key == 'C'){ background(0); } } //limit rotation rate modifiers if (rot >= 360) { rot = 0; } }