Learn to Program with ZedLX

Free Online Programming Course for Beginners

Simple Graphics [12/15]

This program draws a red disc and a row of yellow discs.
[Run the program]

Exercise:

Exercise Coord 9-1 output image

Draw orange lines connecting the center of the red disc with each of the yellow discs.

Hint: Inside the body of the for loop, insert a new call of procedure line above the sleepMs call. The line procedure accepts five arguments. The first two arguments are coordinates of one line endpoint. The next two arguments are coordinates of the other line endpoint. The final, fifth argument is the line color.

If you get stuck, you can take a look at the solution. You don't need to solve every exercise on your own, and you can learn a lot by reading and understanding the solution.

Hint 2

Use the disc center coordinates from the program's source code as the line endpoints.

Solution

Insert this statement above the call to sleepMs:

    line(300, 100, i, 500, /orange);

Loading...