back To Home
Fiit's law simulator
Author :
Sesha Sai Srivatsav
Fall 2017
Simulator
Sketch
Create a canvas
that is 640x480
When the user
clicks their mouse
for the first time, start the simulation.
Record the current time using the
millis
function.
Draw a square at a
random
position.
The random x-coordinate will be between 0-600.
The random y-coordinate will be between 0-400.
The square size will be 40x40.
Record the
mouseX
and
mouseY
position at this time.
Everytime the user presses their mouse, increment a counter.
If the user clicks in the box, then record how long it took.
Add this to an array data structure to store these times.
You add elements to arrays by '
pushing
them'
Calculate the
distance
from the previously recorded
mouseX
and
mouseY
variables. Push these values in a separate array.
If the user misses the square, tally that as an error.
For display you may find useful:
text
Consult the
Reference
for more commands and add at least one new element our
library
beyond what I have done.