Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

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 only one new call of procedure line , for example above the sleepMs statement. The line procedure accepts 5 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 can't solve this exercise, take a peek at the solution. You don't have to solve every exercise by yourself. A lot can be learned by simply reading the solution and applying it.

Hint 2

The coordinates of each line endpoint must be the same as coordinates of disc centers. Disc center coordinates are given in the program's source code.

Solution

Insert this statement above the sleepMs statement:

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

Loading...