Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

Simple Graphics [11/15]

In this example, a for loop is used to draw a bunch of lines that form a triangle.

A strange pattern should be slightly visible, mostly near the bottom of the triangle. This pattern is called moire (moo-ah-rei).
[Run the program]

Try changing the step of the for loop (the number 9) to see how it affects the moire pattern. For example, you can try out values 3, 4, 6, and 12.

The linep procedure has the form:
linep( [pointA], [pointB] )

Exercises:

The disc procedure has the form:
disc(x, y, radius, color)

1. Draw an orange disc of radius 20 at the bottom tip of the triangle.

Solution

    disc(450, 650, 20, /orange);

2. Change the step of the loop to 30.

3. Draw a red disc of radius 15 at the tip of every line.

Hint: inside the body of the for loop, insert only one new statemet, above the sleepMs statement. The coordinates of disc centers are (i, 100).

Solution

    disc(i, 100, 15, /red);

Loading...