Cartesian Mouse


In this project, you are going to graphically show your mouse position on the Cartesian plane, and then calculate the angle to the mouse position.

Here is what the finished project looks like: here


Directions
  1. If you are coding outside of WoofJS.com (like in Sublime), insert the Woof_JS source tag into the <head>section of your project page:

    <script src="https://rawgit.com/stevekrouse/WoofJS/master/dist/woof.js"></script>

    Your code now speaks Woof!

  2. Setup your background to be an all-black, or another dark color.

  3. Declare the two cartesian grid lines using the new Line({}) call. In the example they are red and green, but use any colors you like.

  4. Create a text label on the upper left of the screen using the new Text({}) call.

  5. Setup a forever function.

    forever( function() {
        YOUR CODE GOES HERE
    });


    This will take care of showing your mouse position in real time.

  6. In the forever function, update the mousePosition text label to show the X and Y coordinates of the mouse.

  7. In the top of the program, before the forever function, declare the 3 lines that will connect with the position of your mouse: xLine (red), yLine (green), rLine (blue). You'll then modify them inside the forever function.

  8. Start with the xLine. Back in the forever function, update the endpoints for the xLine to start on the Y axis and end on the mouse position.

  9. Once you get it working, you may want to group the 4 endpoint variables into one expression as follows:

    [x,y,x1,y1] = [a,b,c,d]

    This will help make your program readable and easier to understand.

  10. Repeat for the other two lines. Does everythig look good so far?

  11. Declare a 2nd textLabel to show angleDegrees.

  12. Calculate degrees for the mouse X and Y position using a Math.atan2 trig function. The degrees should be a number between 0 and 360. Show the degrees in the angleDegrees label.
  13. Calculate radians (between 0 and 2PI) and show that as well.

  14. Add a descriptive label on the upper left of the canvas with the name of this project, and any other info you want to show the user.

  15. Keep working on the project and customizing until you are satisfied. Ask your teacher/CIT to upload it to your public folder.



(c) 2017 by Code Craft Academy