🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.graphics.algorithms
Article #11

Re: Need help finding graphics-oriented programming projects

#11
From: Mike Brindley
Date: Sat, 25 Nov 1995 19:07
67 lines
3125 bytes
roy@popmail.med.nyu.edu (Roy Smith):
< I'm really struggling to find programming assignments I can give
< which will be useful and interesting to him.

You might try Barnsley's 'Chaos Game'.  It's generally the first thing
I do when starting with a new graphics system.

Here's the description:

1. Open a drawing area on the screen

2. Pick three widely seperated points on the screen (pixel coordinates,
most likely).  It's nice if these points form an equilateral triangle,
but not necessary.  Call these points the 'attractors'.

3. Pick a starting point in the drawing area.  Make this the 'current
point'.

4. Randomly pick one of the three attractors.  

5. Make the new current point the average of the coordinates of the
old current point and the attractor randomly chosen in step 4.

6. Plot the (new) current point to the drawing area.

7. Repeat steps 4-6 for a set number of times (100,000 may be a good
place to start - this number depends on the speed of your computer and
the resolution of the drawing area.


Magically, a figure will appear on the screen.  It is a fractal called the
Sierpenski gasket.  The three attractors form the corners of the base 
triangle.  This figure is the result of taking a triangle, connecting
the midpoints of each side, and removing the triangle in the middle.  
Recursively repeat until you get tired :).  The first stage looks like
this:

           /\
          /__\
         /\  /\
        /  \/  \
        --------

I hope you can get the idea.

A few notes on the procedure.  You will want to pretty much fill the
screen with the triangle, so choose the attractors along the top and
bottom edges.  If the starting point is chosen as one of the attractors,
you get instant convergence; otherwise, you will want to not plot the
first few (say 10) points.  This works well using all integer math in
pixel coordinates.  The randomly choosing 1 of 3 is probably the only
somewhat tricky point - but it will work quit well with just modulo'ing
the integer returned from standard random number routines to base 3.

One nice (minor) modification of this procedure is to change the 
color of the point plotted, using a different color depending on which
attractor was used to make the current point.  Nice bright red, green,
and blue work pretty well.

This basic algorithm is called an 'Iterated Function System' and leads
into Fractals and Fractal Image Compression.  With a teensy bit more
math, you can do other figures.  One very interesting one is a fern
leaf.

-- 
--> Mike Brindley
    brindley@ece.orst.edu
Technical Details
Message-ID: <497ph0$6mp@engr.orst.edu>
Path: arc1-ca.pugleaf.net!hudson.ECE.ORST.EDU!brindley
References: <roy-2211951523470001@mchip8.med.nyu.edu> <hollaschDIJ7CM.HBy@netcom.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!hudson.ECE.ORST.EDU!brindley
From: brindley@hudson.ECE.ORST.EDU (Mike Brindley)
Newsgroups: comp.graphics.algorithms,comp.lang.c,misc.education.science
Subject: Re: Need help finding graphics-oriented programming projects
Date: 25 Nov 1995 19:07:12 GMT
Organization: Electrical and Computer Engineering, Corvallis
Message-ID: <497ph0$6mp@engr.orst.edu>
References: <roy-2211951523470001@mchip8.med.nyu.edu> <hollaschDIJ7CM.HBy@netcom.com>
NNTP-Posting-Host: hudson.ece.orst.edu