We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So, in an attempt to get better at using processing and programming, i decided to make a program as similar to ms paint as possible. So, what i did was i made the layout, three rectangles, one for the menu (color, stroke, and what not), the light blue background color, and the white pad where the drawing is actually made. Anyways, now that i have these three rectangles, how do i make it so when i draw the line (line(mouseX, mouseY, pmouseX, pmouseY) stays inside my white rectangle? I tried some lengthy if statement, but that failed miserably. if (mouse coordinates are outside the white box size/ coordinates) { stroke(0); //0 means no line right? or whatever the code is, my line stops drawing, or the mouseDragged is overridden in thinking that the mouse is not pressed or something) } else { stroke(10); }
I tried a boolean, where if it was outside, allowDraw would be false, and if it's false, then i can't draw, but again, it still draws the line outside of the "boundaries"
Sorry, again, i am a new programmer, and i can't figure out a way to create this boundary. I'll include the code so you can see what the layout looks like (the if statement and boolean are both deleted since it did not work, or maybe i just messed up) PS: i tried using the draw function, and well, even though the border code sort of works, it's just not as smooth and it's very detached vs the draw line code, and the circles that it places can overlap into the background, vs being cutoff by the "border."
Thanks for your help and tips.
void setup() {
//setting the layout
size(1440, 760);
background(192, 203, 234);
//draw pad noStroke(); fill(255); rect(10, 125, 1000, 500);
//menu box fill(232, 238, 255); rect(0, 20, 1440, 100); }
void draw() { }
void mouseDragged() { stroke(random(255), random(255), random(255)); strokeWeight(20); line(mouseX, mouseY, pmouseX, pmouseY); }
Yeah, there's a trippy rainbow code, i couldn't figure out how to make the borders so i made the rainbow code instead. haha Thanks guys.
Answers
-1 Format code posted in forum please.
-2 Use variables instead of hard numbers for menu and canvas positioning.
-3 Usually it's not a good idea to draw inside events callbacks. It's fine so far though...
-4 I think a PGraphics as a canvas would be a better idea.
Anyway, to your question:
Thanks for the tips. sorry, i tried the "code" button, but nothing happened, it still posted as normal text vs your code. I probably messed it up though. thanks again.
There is a link in my previous post to the page explaining how to format the code. Perhaps you missed skipping a line before and after the code block...
:)