In this exercise, you will draw small circles in the canvas, one per frame, and label them with the (x,y) coordinate of
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
In this exercise, you will draw small circles in the canvas, one per frame, and label them with the (x,y) coordinate of
In this exercise, you will draw small circles in the canvas, one per frame, and label them with the (x,y) coordinate of their centres, as shown on the right. The draw() function should generate a random (x,y) coordinate, and draw a small white circle, with a diameter of 5 pixels, with its centre at that location. Use int values, not float values, for x and y (otherwise the coordinates will not look very good when you draw them), and make sure that the x coordinate is at least 80 pixels from the right edge, and the y coordinate is at least 25 pixels from the top edge, to make sure there is room to draw the coordinates. Use a 500x500 canvas, as usual. Remember that random(a, b) can be used to get a random float value r where a<r<b. Use appropriate named constants to control all of these things as usual. Make sure this part of the program is working properly before continuing. SampleSolutionLab05Bronze (51,206) (91,357) (87,495) 0 (184,38) (336,104) (202,146) (315,142) (260,279) (234,292) (373,251) Then draw the (x,y) coordinates using Strings as shown in the image. You should use black text, 16 pixels in size. Draw the text starting 5 pixels above and to the right of the centres of the circles. Use more appropriate named constants, of course. If you draw 60 small circles per second, it will not work very well. Add the new command frameRate (1); to your setup() function. This will cause draw() to be run 1 time per second, not 60 times per second, which will work a lot better for this program. X