How do I make a line sensitive to mouse speed?

I have to write a program that draws a line from the previous to the current position of the mouse. Then I need to change the previous program using the abs() and strokeWeight functions to draw a line sensitive to mouse speed. I also have to use mouseX and mouseY as variables to make the line colourful and (|mouseX-mouseY|) for the third colour.

I have the first step done so far and my code is below:

void setup() { size(500,500); background(0); }

void draw() { strokeWeight(5); stroke(255); line(pmouseX,pmouseY,mouseX,mouseY); }

void mousePressed() { background(0); }

Thanks for any help! I really appreciate your time to answer my questions!

Answers

  • shouldn't draw() start with background?

    for homework 2: the speed is abs mousex-pmousex

  • If I put the background in draw() then it just makes a dot, but I need an actual line. For the second part, I'm not really sure where and how to put that in my code.

  • I am fairly new to processing, so I'm not quite familiar with how to use it yet, so can someone post the new correct code please?

  • Answer ✓

    for homework 2: the speed is abs mousex-pmousex

    use this value with strokeWeight before you draw the line

  • Thanks that solved the problem but how would I change the colours depending on the speed of the cursor?

  • for homework 2: the speed is abs mousex-pmousex

    use this value with the command map()

    Then use the result with

    stroke(value,0,0); before you draw the line

Sign In or Register to comment.