Learn to Program with ZedLX

Free Online Programming Course for Beginners

Simple Graphics [11/15]

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

An unusual pattern should be slightly visible, especially near the bottom of the triangle. This pattern is called moiré (mwoa-RAY).
[Run the program]

Experiment with different step values (the number 9) in the for loop to see how they affect the moire pattern. Try values like 3, 4, 6, or 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 point of the triangle.

Solution

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

2. Change the step of the loop to 30.

3. Inside the body of the for loop, add a red disc of radius 15 at the top end of each line.

Solution

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

Loading...