Simple drawing with processing, a few questions.
in
Programming Questions
•
2 years ago
Hello,
I'm a Processing beginner.
I'd like to explore drawing with a mouse with Processing, a seemingly simple issue, but I fail.
the most basic code is the one following (not including the setup() method):
- void draw() {
- if (mousePressed) {
- line(mouseX, mouseY, pmouseX, pmouseY);
- }
- }
It has a drawback: curves are rendered by approximations (several straight lines) when moving the mouse fast,
as you can see here:
if a line is drawn fast, the differerence between mouse and pmouse is big, and connected by straight lines, which is obvious on this image...
I am trying to get rid of this behaviour, and I'm searching for a way to draw each pixel the mouse has gone over.
I have tried to replace the line function, by a curve function (and an array of four mouse positions: mouse, pmouse, and the previous pmouse, and the previous previous pmouse). It works somehow (no more nasty straight lines), but this solution has another drawback for the project I have:
I cannot control each pixel color, but only color of an entire curve. I'd like, for instance have darker pixels when the mouse is moved slowly (abs(mouse-pmouse) is small).
So how could I track the position of the mouse for everypixel it crosses, or at least at a higher rate than framerate?
I've tried to do a loop inside draw() to draw several time a line inside each frame:
- void draw() {
- for (int i = 0; i < 10; i++) {
- if (mousePressed) {
- line(mouseX, mouseY, pmouseX, pmouseY);
- }
- }
- }
but it doesn't work, which is easy to check by adding to the loop
- println("loop: " + i +" mouseX: " + mouseX);
while i cycle from 0 to 9, mouseX doesn't change...
Do you have any hint?
thanks a lot.
1