Using SiMPLE To Create
Your Own Computer Art
(Part 4)


Welcome to Part 4, the final part of our introductory discussion about creating your own computer art.

A Brief Look at "Looping"

Suppose you want the computer to perform a set of instructions over and over for a specified number of times. To do this, you would use something called a "Do-Loop".

A "Do-Loop" has the following general form:

Do index = start To end Step increment

   instruction(s)

Loop

(Notice that the word "Do", the word "To", the word "Step",
and the word "Loop", must all begin with an upper-case letter.)

The structure of a "Do-Loop" can be thought of as a sandwich. The "Do" and the "Loop" statements are the slices of bread, and the instructions between them are the meat of the sandwich. It is these "meat" instructions that will be repeated over and over.

The "index" of the loop is first assigned the value "start". If that value does not exceed the value specified by "end", statement(s) are then executed. "index" is then automatically incremented by "increment". If "index" still does not exceed the value specified by "end", the loop continues.

For example, the following list of instructions tells the computer to draw a row of 10 green circles (each with a radius of 15 pixels), starting at the center of the screen, with the centers of the circles being 40 pixels apart:

Ultra-SiMPLE
row = ypixels()/2
col = xpixels()/2
solid color (10)
Do index = 1 To 10 Step 1
   location = col + 40*index
   solid circle (location, row, 15)
Loop

Go ahead and try it. (You know the routine: Create another "New Text Document", type the listing, drop it on the little icon.)


If the first line of a "Do-Loop" consists of only the word "Do" (without any "index", start", etc. specified), the loop will run forever! So, whenever you decide to use such an "infinite loop", be sure to include a "read quitkey" instuction somewhere in the loop so that the user can terminate it by pressing any key on the keyboard.

For example, try running the following listing (which illustrates how looping can be used to create "dynamic" art):

Ultra-SiMPLE
rows = ypixels()
cols = xpixels()
Do
   x = random (cols)
   y = random (rows)
   z = random (16)
   solid color (z)
   solid circle (x, y, 100)
   delay (10)
   read quitkey
Loop

(The program shown above uses yet another one of SiMPLE's functions ("random") which merely generates a random number between zero and a specified number.)


We have only begun to discuss all the possibilities that looping has to offer. Readers who want more information about looping (and other cool techniques for creating "dynamic" computer art) are encouraged to read the online SiMPLE Tutorial.

Conclusion

This concludes your brief introduction to the world of SiMPLE computer art. You now know how to create simple loops, and how to make your computer draw colored circles anywhere on your screen.

Besides circles, what other shapes are available? Click here to read about some of them.

Don't be afraid to try using different shapes and colors. Go ahead and experiment. See what kind of art you can create! And if you make something really cool, be sure to e-mail the listing to us. We just might add it to The SiMPLE Art Gallery!


Tell Me About SiMPAINT




[ Webmaster | FAQ's | Home Page | Contact Us ]

© Copyright 2007 SiMPLE CodeWorks, Inc. All rights reserved.