We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there,
I'm really new to processing and honestly not very good at coding but am trying to learn. I'm trying to make a simple paint type of thing and keep getting an error because my stroke weight is going below zero. My question would be how to stop that from happening.
float px;
float py;
float strokeW = 1;
//draws once
void setup() {
size(400, 400);
background(255);
}
//draws everyframe
void draw() {
px = pmouseX;
py = pmouseY;
//draws my line(paint brush)
if (mousePressed) {
stroke(10);
fill(0);
line(mouseX, mouseY, px, py);
}
//this increases the size of line
if (keyPressed) {
if (key == ']' || key == '}') {
//created a variable for strokeWeight and added
//strokeWeight = itself plus 1 for increaseing the size
strokeW++;
}
//this decreases the size of my line
if (keyPressed) {
if (key == '[' || key == '{') {
//opposite process for decrease
//but i do have a problem because i can decrease the size
//of the line until it is gone and the program freezes
strokeW--;
}
}
}
}
and i tried adding this to stop it but no luck yet
if (strokeW < 1) {
strokeWeight(1);
}
???
Thanks
Answers
https://Processing.org/reference/keyPressed_.html
https://Processing.org/reference/max_.html
I made a few changes to your sketch, the most important one is checking that strokeW is greater than 1.0 before you make it smaller:
I think that the rate of growing / shrinking is very fast. Your strokeW is a float, you could make it grow / shrink at a rate slower than 1.0 if you wanted to. For example, add / subtract 0.25 instead of doing strokeW++ and strokeW--
thanks GoToLoop and asimes for your help!!!!! really appreciate it!!
Some online examples too: :bz
http://studio.ProcessingTogether.com/sp/pad/export/ro.9ldYvJUyiXGzi
http://studio.ProcessingTogether.com/sp/pad/export/ro.9c9DCUznTwot6
Thank you so much!