Code Snippet - Mouse Trail
in
Share your Work
•
3 years ago
Seeing how reas thinks the exhibition section is a good place to post and discuss code snippets, i'll just go ahead and post this. But first i just want to clarify why i am posting this. So i created this mouse trail/Paint effect some days ago and i think it looks really cool but i really have no use for it. So i am posting it here because someone else might be able to use it for something or get some new ideas from it. I am also hoping that someone would be able to improve on it a post the results here and by doing that maybe creating what could be an interesting discussion on mouse trail effects. :)
Here's some images just to show how it looks and what you can do with it:
And here's the code:
Here's some images just to show how it looks and what you can do with it:
And here's the code:
- float widthOfTheStorke;
void setup(){
size(screenWidth,screenHeight,P2D);
background(255);
smooth();
stroke(255,10);
strokeWeight(4);
widthOfTheStorke = 100;
}
void draw(){
if(mousePressed){
line(pmouseX,pmouseY,mouseX,mouseY);
PVector current = new PVector(pmouseX,pmouseY);
PVector destination = new PVector(mouseX,mouseY);
while(current.dist(destination) >0.5){
stroke(current.x*255/width,current.y*255/height,noise(current.x/100,current.y/100)*255,20);
float angle = atan2(destination.y-current.y,destination.x-current.x);
float rad = noise(current.x/100,current.y/100)*widthOfTheStorke;
line(current.x,current.y,current.x+cos(angle-PI/2)*rad,current.y+sin(angle-PI/2)*rad);
current.x += cos(angle);
current.y += sin(angle);
}
}
if(keyPressed){
if (key == ' ') {
//space clears the screen
background(255);
}
}
}