Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This example introduces a couple of new things starting on line 13:

float radius = dist(mouseX,mouseY,width/2,height/2);

Here the distance from the mouse pointer to the window center centre is determined (see Pythagoras).


radius = map(radius,0,width,1,4);

The original range is from 0 to the width of the window. The target range is from 1-4. Now radius is transformed from original range to the target range.


-atan2(mouseX - (width / 2),mouseY - (height / 2)); 

The atan2 function returns the angle in radians at a given coordinate from the 0 point. In this example we shift the 0 point to the centre of the screen by subtracting width/2 from X and height/2 from Y.

Image Added

Image Credit: wikipedia

Exercise 8

Create a new program where a simple car follows the mouse on the screen. The car should be drawn from the side, and include wheels that rotate. You may use the example code to get started.

...