We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey,
I am creating a paint program and am in need of some help with the buttons. I have a rectangular button drawn with;
boolean redbuttonpressed ;
int TypeIsRect ;
Void setup() {
size (400,400);
background (255) ;
fill (255,0,0) ;
rect (379, 10, 20, 20) ;
}
void draw() {
if (mousePressed){
stroke(0) ;
line(mouseX,mouseY,pmouseX,pmouseY);
}
redbuttonpressed = false ;
}
if(mousePressed){
if(redbuttonpressed){
stroke(255,0,0);
line(mouseX,mouseY,pmouseX,pmouseY);
}
}
but when I click on the rectangle the line remains black, why is that and how can I fix it? I tried commenting out the
stroke(0);
but that does not work, either.
Answers
I took out the
and the
codes. That does not work either.
the principle is the same as in our other program
use the function mousePressed() and not the var mousePressed
check with if(mouseX > etc.
if the mouse was pressed in your rect
when it was so, store the color in a var to use later with the line
;-)
do you mean like this
I have this code (with syntax error);
This is my new code (still with a syntax error...how do I get rid of this syntax error?)
right before
void mousePressed() {
a
}
is missingwhy does the line keep following the mouse and not stop once the mouse is released?
almost there
again use only one line in draw
stroke must be before line to take effect
;-)
again use only one line in draw
stroke must be before line to take effect
the line in draw() must be conditioned
with mousePressed
Error: expected: ";"
you must have the lines inside the function draw()
what's your first language?
line 17 is necessary
delete
//
hereHint
now you have multiple buttons
in function
mousePressed()
you need to checkwhich one has been checked
so these lines for every button:
but each time for the coordinates / position of the rects / buttons (like in draw())
almost there!!!!
;-)
it's a shame you can't use ctrl-t because it would help you spot the errors
read your own code carefully
you are not closing your { with a } after line 19
hint
this not in mousePressed
a part in draw()
a part in draw() must look like this
it's not complete
set stroke() before using line()
use line only when mousePressed (this is the var mousePressed)
the function (not the var) mousePressed() is used only for the buttons.
you are doing great !
;-)
It still gives me a syntax error, though:
what happened to my rectangles?
there is one }
it is now in 41
but must be in 58
read careful your own code
ok, I am off. Sorry.
you need to implement my changes.
See above.
See you tomorrow.
;-)
See you tomorrow! :)
no no.................
no stroke or line in the function mousePressed() !!!!
like in the other sketch in the function mousePressed() we just store data we don't draw - see above
one block must be closed with }
one block looks like this
at the moment all } are at the end - they must be each be after its own block of code
how to improve this, I told you...
see above
error; expect; ";"
You need to keep track of your blocks. In the PDE a little blue rect shows you where the block, in which the carat is, closes. Use it. :)
delete line 16 and 37 and it should work.
EDIT: And add a
}
at line 54Also you might consider start using arrays and/or classes. It will make things much easier. For instance, what happens if you press green? It is selected, but then you can't select another color... That's because green is the last color in your
mousePressed()
function, so if it is true, than it's green forever. To avoid that you need to set allcolorButtonPressed
booleans tofalse
at the begging ofmousePressed()
. If you had an array of booleans, that would be easier to do...check out this two cool articles:
http://forum.processing.org/two/discussion/8082/from-several-variables-to-arrays
http://forum.processing.org/two/discussion/8081/from-several-arrays-to-classes
This is it:
but the program is still not done...
How would I change the brush size with the mouse wheel?
I have this code for the rainbow color;
but it does not give me a rainbow color
read in the reference
mouseWheel and strokeWeight()
what do you want to happen there?
It looks like you get one random color (well, one color from the colors of the rainbow)
hint
you could say in
draw()
;-)
I will check the reference and get back to you on that. I want it to give me random colors at the same time; like it may give me a random color (let's say blue) then I can draw a line with the color blue but it remains blue. I do not want the color to remain blue, I want it to change color for every small line drawn. Thank you.
is this homework?
yea
but I don't have a teacher to help me, which is why I a using this forum
am
the button for rainbow must be implemented like every other button. Check it with mouse and so on.
hint
you could say in
draw()
that will give you a new random color every time
you could even let the rainbowbutton change its color all the time
Ok, now I want the mouseEvent for the size and I need to know how to use a star instead of a line
I found this in void mousePressed() but I don't understand it:
what values does e have?
what do you mean?
the place where I found it is;
the full code is:
well, I can't do the work for you.
So did you test it this in your sketch:
It shows something in the black/white window.
What does it say there?
These are the values of e....
;-)
I know.... I told you where to find it.....
I used it in my code:
but it neither does anything nor does it read anything on the screen.
you can't have 2 draw()
did you notice you have the button rects outline color change
when you change your pen color?
Therefore say before drawing the button rects
like this? (this is the code you send me but with the stroke(0);)