# IFS Fractal Toolkit

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

### VERSION

$Id: IFS Fractal Toolkit.nlogo 43156 2009-03-05 16:58:08Z tisue $

### WHAT IS IT?

An Iterated Function System is a collection of functions that are applied to a set of points repeatedly. The functions move that set of points to smaller and smaller regions, so that the resulting image includes patterns repeated within themselves. This model enables users to create their own fractal images by manipulating squares to define Iterated Function Systems.

### HOW IT WORKS

The user first defines an Iterated Function System by scaling, placing, rotating, and reflecting squares inside of the unit square. When they are satisfied with their design, they can press the DRAW MY FRACTAL! button to see the resulting figure. This figure is created by first generating 100 points randomly distributed within the unit square. Then at each tick, each point follows the following rules:

1) Assign an existing mapping function. The mapping function that the point is assigned to at each tick is random, but proportional to the size of each function, so that larger squares (that is, functions that map to larger regions) are more likely to be chosen than smaller squares.

2) Apply that function to the point. For example, if the point is in the lower left corner of the unit square, applying a given function will move that point to the lower left of that function's respective square.

3) Stamp, so that the point's location is recorded visually.

For more information on Iterated Function Systems, see http://en.wikipedia.org/wiki/Iterated_function_systems.

### HOW TO USE IT

To create a fractal, first press SETUP.

Then, select the size of the square you would like to add with the SQUARE-SIZE slider and press CREATE SQUARE. This square, and the ways you manipulate it, represent one mapping function in your Iterated Function System. It defines the translation, scaling, rotation and reflection that a point will undergo under that mapping function:

MOVE SQUARE lets you move the square to your desired location by dragging it with your mouse in the view.

DELETE SQUARE lets you click on a square in the view to remove it.

Change the ROTATION-ANGLE to define the number of degrees you would like to rotate a square, and then select ROTATE SQUARE to choose the square you would like to rotate in the view.

Choose a REFLECTION-AXIS and press REFLECT SQUARE to choose the square you would like to reflect in the view.

When you have included all of the squares that you want, press DRAW MY FRACTAL! to see the results.

After the fractal is drawn, you can see where you placed your squares by pressing SHOW/HIDE SQUARES.

### THINGS TO NOTICE

During the first few ticks of the model, some points stamp in a place that other points do not end up. Why does this happen?

What happens if you only put one square (and thus only one function) in the system? Does that make sense? Why or why not?

### THINGS TO TRY

When you find an arrangement of squares that creates a fractal you like, try exploring what will happen if you only change one square a little bit, by reflecting or rotating it. Is it what you would expect?

Try finding a gallery of IFS fractals online, like the one here: http://library.thinkquest.org/26242/full/gallery/ifs.html. Can you come up with a strategy for recreating them? Can you create any fractal using IFS?

### EXTENDING THE MODEL

Try to see more of the systematic patterns in fractals by using transparency or color as a "heat map" to show where points are most likely to land after the system has run for a while. Are these locations different from what you expected? Why or why not?

Can you think of other ways that you can transform or manipulate points that would lead to interesting fractals? How would you build them into the toolkit? Try it!

### NETLOGO FEATURES

### RELATED MODELS

See Chaos Fractal Toolkit with Circularization for an extension of this model. Chaos Game produces fractals using a different way to express IFS. For other methods for producing fractals, check out the Fractals folder in the Mathematics section of the Models Library.

### CREDITS AND REFERENCES

## Comments and Questions

breed [ squares square ] breed [ outlines outline ] breed [ points point ] squares-own [ my-size half-size my-rotation-angle reflection-matrix scale-matrix xadjustment yadjustment ] globals [ function-list ] ;;;;;;;;;;;;;;;;;;;;;;; ;;; Setup Functions ;;; ;;;;;;;;;;;;;;;;;;;;;;; to setup ca set-default-shape squares "square 4" set-default-shape outlines "square 3" set function-list [] create-outlines 1 [ setxy .5 .5 set size 1.44 set heading 0 set color black ] create-points 100 [ setxy 0 0 set size .010001 ] ask patches [ set pcolor white ] end ;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Building Functions ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;; to create-square create-squares 1 [ set size ( square-size * 1.44 ) set heading 0 set my-size square-size set half-size ( my-size / 2 ) set scale-matrix ( list my-size 0 0 my-size ) set reflection-matrix ( list 1 0 0 1 0 0 ) ;; no reflection yet setxy .5 .5 ] end to move-squares if mouse-down? [ let candidate min-one-of squares [distancexy mouse-xcor mouse-ycor] if [distancexy mouse-xcor mouse-ycor] of candidate < 1 [ ask candidate [ set color red ] while [mouse-down?] [ ;; If we don't force the display to update, the user won't ;; be able to see the turtle moving around. display ;; The SUBJECT primitive reports the turtle being watched. ask candidate [ setxy mouse-xcor mouse-ycor ] ] ;ask candidate [ set color black ] ask candidate [ check-bounds ] stop ] ] end to check-bounds ;; square procedure if( ( xcor - half-size ) < 0 ) [ set xcor half-size ] if( ( xcor + half-size ) > 1 ) [ set xcor 1 - half-size ] if( ( ycor - half-size ) < 0 ) [ set ycor half-size ] if( ( ycor + half-size ) > 1 ) [ set ycor 1 - half-size ] end to delete-squares if( mouse-down? and any?( squares ) ) [ let candidate min-one-of squares [distancexy mouse-xcor mouse-ycor] if [distancexy mouse-xcor mouse-ycor] of candidate < 1 [ ask candidate [ die ] stop ] ] end to reflect-square ;; (x, y) = (-x, -y), axis \\ if( mouse-down? and reflection-axis = "\\\\" ) [ let candidate min-one-of squares [distancexy mouse-xcor mouse-ycor] if [distancexy mouse-xcor mouse-ycor] of candidate < 1 [ ask candidate [ set reflection-matrix (list -1 0 0 -1 1 1 ) set shape "reflected\\\\" ] ] stop ] ;; (x, y) = (-x, y), axis | if( mouse-down? and reflection-axis = "|" ) [ let candidate min-one-of squares [distancexy mouse-xcor mouse-ycor] if [distancexy mouse-xcor mouse-ycor] of candidate < 1 [ ask candidate [ set reflection-matrix (list -1 0 0 1 1 0 ) set shape "reflected|" ] ] stop ] ;; (x, y) = (x, -y), axis - if( mouse-down? and reflection-axis = "-" ) [ let candidate min-one-of squares [distancexy mouse-xcor mouse-ycor] if [distancexy mouse-xcor mouse-ycor] of candidate < 1 [ ask candidate [ set reflection-matrix ( list 1 0 0 -1 0 1 ) set shape "reflected-" ] ] stop ] ;; (x, y) = (y,x) if( mouse-down? and reflection-axis = "/" ) [ let candidate min-one-of squares [distancexy mouse-xcor mouse-ycor] if [distancexy mouse-xcor mouse-ycor] of candidate < 1 [ ask candidate [ set reflection-matrix (list 0 1 1 0 0 0 ) set shape "reflected/" ] ] stop ] end to rotate-square if mouse-down? [ let candidate min-one-of squares [distancexy mouse-xcor mouse-ycor] if [distancexy mouse-xcor mouse-ycor] of candidate < 1 [ ask candidate [ rt rotation-angle ] ] stop ] end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Fractal Drawing Functions ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to create-fractal ;; point procedure if( function-list = [] ) [ set function-list ifs-list ] let random-function random-float 1 let counter 0 let right-function [] while [ counter < length function-list ] [ if( random-function < item 0 ( item counter function-list ) ) [ set right-function item counter function-list ] set counter counter + 1 ] reflect-point ( item 1 right-function ) rotate-point ( item 2 right-function ) scale-point ( item 3 right-function ) set xcor xcor + item 4 right-function set ycor ycor + item 5 right-function end ;; generates the list of functions from the squares ;; manipulated by the user to-report ifs-list let iterated-function-list [] ;; list of lists let total-area-of-squares ( sum [ my-size ] of squares ) let prob-counter 1 ask squares [ set iterated-function-list lput ( list ( prob-counter ) reflection-matrix heading scale-matrix ( xcor - half-size ) ( ycor - half-size ) ) iterated-function-list ;;item 0 : prob counter ;;item 1 : reflection matrix ;;item 2 : rotation matrix ;;item 3 : scale matrix ;;item 4 : xcor of bottom left corner ;;item 5 : ycor of bottom left corner set prob-counter ( prob-counter - ( my-size / total-area-of-squares ) ) ] report iterated-function-list end to draw ifelse( any? squares ) [ ask squares [ ht ] ask points [ create-fractal stamp ] ] [ stop ] end ;;;;;;;;;;;;;;;;;;;;;;; ;;; Point Functions ;;; ;;;;;;;;;;;;;;;;;;;;;;; to reflect-point [ my-reflection-matrix ] ;; this reflects and resets inside original square set xcor ( item 0 my-reflection-matrix * xcor ) + ( item 1 my-reflection-matrix * ycor ) + item 4 my-reflection-matrix set ycor ( item 2 my-reflection-matrix * xcor ) + ( item 3 my-reflection-matrix * ycor ) + item 5 my-reflection-matrix end ;; rotate the point to rotate-point [ angle ] facexy .5 .5 ;; face the center let dist distancexy .5 .5 ;; store how far I am fd dist rt angle + 180 fd dist end ;; scale the point to scale-point [ my-scale-matrix ] ;; scales down original square area set xcor ( item 0 my-scale-matrix * xcor ) + ( item 1 my-scale-matrix * ycor ) set ycor ( item 2 my-scale-matrix * xcor ) + ( item 3 my-scale-matrix * ycor ) end

There is only one version of this model, created about 11 years ago by Michelle Wilkerson-Jerde.

## Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.