Created
March 15, 2022 17:12
-
-
Save claytical/1f9fcf573a8e76e87de87fce38e42649 to your computer and use it in GitHub Desktop.
Processing, Line Drawing Program, Loop with Mapped Values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//draw a contiuous line | |
void setup() { | |
size(500, 500); | |
background(0, 0, 0); | |
} | |
void draw() { | |
println("Mouse X: " + mouseX + " Mouse Y: " + mouseY); | |
} | |
void mouseDragged() { | |
//check if the previous mouse x position was on the screen of the x axis | |
if (pmouseX > 0 && pmouseX < width) { | |
//check if the previous mouse y position was on the screen of the y axis | |
if (pmouseY > 0 && pmouseY < height) { | |
lineDraw(5); | |
} | |
} | |
} | |
void lineDraw(int numberOfLines) { | |
for (int i = 0; i < numberOfLines; i++) { | |
float scaledColorValue = map(i, 0, numberOfLines, 0, 255); | |
stroke(scaledColorValue); | |
line(pmouseX + (i * 5), pmouseY+ (i * 5), mouseX+ (i * 5), mouseY+ (i * 5)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment