We are about to switch to a new forum software. Until then we have removed the registration on this forum.
The program must draw the color in the corner, erase and have the ability to change hue, saturation and brightness at this point that is what I am having trouble with. Could someone walk me through and help me figure out what I did wrong?
Code:
color CurrentColor;
int strokeW;
int flag=0;
int hue=0;
int sat=0;
int bright=0;
int alpha=0;
void setup()
{
size(640, 480);
colorMode(HSB);
background(255);
stroke(hue, sat, bright, alpha);
CurrentColor = color(0, 0, 0, 0);
}
void draw()
{
noStroke();
fill(CurrentColor);
rect(0, 0, 30, 30);
stroke(CurrentColor);
strokeWeight(strokeW);
if(flag==1) line(mouseX, mouseY, pmouseX, pmouseY);
if (keyPressed){
if (key == 's') sat = sat-1;
if (key == 'S') sat = sat+1;
if (key == 'b') bright = bright-1;
if (key == 'B') bright = bright+1;
if (key == 'h') hue = hue-1;
if (key == 'H') hue = hue+1;
}
}
void mouseDragged() {
flag=1;
}
void mouseReleased(){
flag=0;
}
void keyPressed() {
if (key == 'c')
background(255);
if (key == 'p') background(CurrentColor);
if (key == '1') strokeW = 1;
if (key == '2') strokeW = 2;
if (key == '3') strokeW = 3;
if (key == '4') strokeW = 4;
if (key == '5') strokeW = 5;
if (key == '6') strokeW = 6;
if (key == '7') strokeW = 7;
if (key == '8') strokeW = 8;
if (key == '9') strokeW = 9;
if (key == '0') strokeW = 0;
if (key == 'w') saveFrame("save-######.png");
}
Answers
My experiments w/ your code. See if it's close to whatcha want:
do you know why it wasn't working? It looks like you aren't setting the stroke size at first, you should at least give it a default value. You also had keychecking in two locations when it should be in the keypressed event. you don't need to set so many things every time draw is called your settings should be set before draw at least for this program. GotoLoop's code above is pretty nice and concise. here's something i put together http://studio.sketchpad.cc/sp/pad/view/hNPFWzhGal/rev.823 that is similar. good luck.
thanks everyone for the help, that helped me edit my own to allow hsb editable, my next dilemma is making an eraser that goes to the previous hsb after its been used. How can i do this?
This is a copy and pasted program from above with red (3), blue (5), green (4), gray(6), white (1), and black (2) color selections and made tab the random color changer.
void setup() { size(1900, 1000); background(c2); }
int x,y,xp,yp; int strokeW=1,flag=0;
color c = color(255); color c2 = color(0);
void draw() {
fill(c); noStroke(); rect(0, 0, 50, 50); stroke(c); strokeWeight(strokeW); if(flag==1) line(mouseX, mouseY, pmouseX, pmouseY); } void mouseDragged(){ flag=1; } void mouseReleased(){ flag=0; }
void keyPressed() { if (key == CODED) { if (keyCode == UP) strokeW++; if (keyCode == DOWN) strokeW--; } if (strokeW<0)strokeW=1; if(key == TAB) c = color(random(0,255),random(0,255),random(0,255)); if(key == '1') c = color(255); else if(key == '2') c = color(0); else if(key == '3') c = color(100,0,0); else if(key == '4') c = color(0,100,0); else if(key == '5') c = color(0,0,100); else if(key == '6') c = color(100,100,100); if (keyCode == BACKSPACE) { background(c2); } }
@Green_Titan This is an old post.
Please edit your post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code.
Kf