|
Author |
Topic: Colorcheck (Read 562 times) |
|
Wim_Van_der_Vurst
|
Colorcheck
« on: Oct 28th, 2002, 10:47am » |
|
/* * Colorcheck * by Wim Van der Vurst * Based on Typewriter by Martin Gomez * * Colorcheck produces a pattern of random colours * With the mouse it is possible to select one of the rectangles * All rectangles with other color are "deleted" * Spacebar makes pattern move * enter-key generates new pattern * */ // Global variables int width = 400; int height = 200; int i = 0; int var = 50; // Variation of selected color int x = 0; // X position of the rectangle int y = 0; // Y position of the rectangle int rect_height = 10; // Height of the rectangle int rect_width = 5; // Width of the rectangle int num = (width/rect_width)*(height/rect_height); //Number of array objects REct[] rc = new REct[num]; //Create empty array of rectangle objects int [] rect_color_r = new int [num]; //Create empty array of red values int [] rect_color_b = new int [num]; //Create empty array of blue values int [] rect_color_g = new int [num]; //Create empty array of green values int [] rect_x = new int [num]; //Create empty array of x values int [] rect_y = new int [num]; //Create empty array of y values // Initalization - run once void setup() { size(width+1, height+1); noBackground(); stroke(255); // sets a white border for(int i=0; i<num; i++) { //Fill array of rectangles with zero values rc[i] = new REct(0,0,0,0,0); } for(int i=0; i<num; i++) { //Fill array of colors with random values rect_color_r [i] = int(random(0, 255)); rect_color_g [i] = int(random(0, 255)); rect_color_b [i] = int(random(0, 255)); } } void loop() { //Draw rectangles for(i; i<num; i++) { rc[i].draw(); } if (keyPressed) { //If enter key is pressed, generate new pattern if(key == 10) { for(int i=0; i<num; i++) { rect_color_r [i] = int(random(0, 255)); rect_color_g [i] = int(random(0, 255)); rect_color_b [i] = int(random(0, 255)); } i=0; x=0; y=0; stroke(255); } //If spacebar is pressed, move pattern if(key == 32) { i=0; for(int k = 0; k<num; k++) { rc[i].draw(); i++; } } } } //object rectangle class REct { int rc_x, rc_y, rc_r, rc_g, rc_b; REct (int irc_x, int irc_y, int irc_r, int irc_g, int irc_b) { irc_x = rc_x; irc_y = rc_y; irc_r = rc_r; irc_g = rc_g; irc_b = rc_b; } // Draw the rectangle void draw() { // Set color fill( rect_color_r [i],rect_color_g [i],rect_color_b [i]); // Draw rectangle rect( x, y, rect_width, rect_height ); rect_x [i] = x; rect_y [i] = y; // Update the rectangle position y = ( y + rect_height ); // set x to ( x + 5 ) if (x > width - rect_width) { x = 0; y+= rect_height; } // Wrap vertically if( y > height - rect_height) { y = 0; // reset y to 0 x = x + rect_width; } } } //If mouse is pressed check which rectangles have same color as current rectangle //if not change color rectangle to color current rectangle void mousePressed () { int j = (mouseY/rect_height)+((mouseX/rect_width)*20); noStroke(); for(int i=0; i<num; i++) { if (!((rect_color_r [j] - var) < rect_color_r [i] && rect_color_r [i] < (rect_color_r [j] + var) && (rect_color_g [j] - var) < rect_color_g [i] && rect_color_g [i] < (rect_color_g [j] + var) && (rect_color_b [j] - var) < rect_color_b [i] && rect_color_b [i] < (rect_color_b [j] + var)) ) { rect_color_r [i]=rect_color_r [j]; rect_color_g [i]=rect_color_g [j]; rect_color_b [i]=rect_color_b [j]; } } } void mouseReleased () { i=0; x=0; y=0; }
|
|
|
|
REAS
|
Re: Colorcheck
« Reply #1 on: Oct 28th, 2002, 8:38pm » |
|
I find the most interesting parts of the software to be hidden. I like what I can do with the space bar and enter key and would love to be able to find these functions with the mouse. Why rely on random values for selecting colors? It would be interesting to develop a series of data structures for organizing the color into significant patterns rather than random ones.
|
|
|
|
Wim_Van_der_Vurst
|
Re: Colorcheck
« Reply #2 on: Oct 29th, 2002, 12:26pm » |
|
i don't know if i understand it correctly but the problem with the mouse is that the mousepressed function only has one button (maybe mac related) so i had to use other keys to (or maybe mouse move can be a solution...). the use of random colors is a flaw, i know but i finding a relevant color generation rule seems difficult... any suggestions?
|
|
|
|
fry
|
Re: Colorcheck
« Reply #3 on: Oct 29th, 2002, 6:05pm » |
|
if you want more control out of mousePressed, use the full java version instead of mousePressed() with no arguments: public void mousePressed(MouseEvent event) { // make sure mouseX/mouseY get set by p5 super.mousePressed(event); // insert code here to do fancier things // with the 'event' object } by using the event object, you can find out whether the second button is used, or if alt/ctrl/shift is down. and regarding color.. working with a reasonable algorithmic color generator is a topic for a graduate degree, and even then it's questionable whether it's useful. color is a very subjective experience and the choices are something best left to people rather than algorithms. in general, it can be useful to pick a set of colors beforehand (i.e. in photoshop using its color picker), and stuff those in an array. for instance: static color list[] = { #cc00ff, #ff00ee, #eeaadd }; at the beginning of your program. (hmm, i hope that code works if not in the current release, something similar should.. hopefully the idea is clear) a few well-chosen colors your piece get out of that rainbow-colored randomness that's all too prevalent in computational design works. have fun..
|
|
|
|
|