Chaos Fractal Toolkit

No preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 4.1pre1 • Viewed 498 times • Downloaded 48 times • Run 1 time
Download the 'Chaos Fractal Toolkit' modelDownload this modelEmbed this model

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


VERSION

$Id: Chaos Fractal Toolkit.nlogo 39714 2008-05-01 18:14:18Z tisue $

WHAT IS IT?

This section could give a general understanding of what the model is trying to show or explain.

HOW IT WORKS

This section could explain what rules the agents use to create the overall behavior of the model.

HOW TO USE IT

This section could explain how to use the model, including a description of each of the items in the interface tab.

THINGS TO NOTICE

This section could give some ideas of things for the user to notice while running the model.

THINGS TO TRY

This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.

EXTENDING THE MODEL

This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.

NETLOGO FEATURES

This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.

RELATED MODELS

This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.

CREDITS AND REFERENCES

This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed [ squares square ]
breed [ outlines outline ]
breed [ points point ]

squares-own [ my-size half-size my-rotation-angle reflection-matrix rotation-matrix scale-matrix xadjustment yadjustment ]

globals [ function-list ]

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
  ]
  create-points 100 [ setxy 0 0 set size .010001 ]
end 

to iterate-sierpinski
  let random-function random 3
  if( random-function = 0 ) [
    setxy ( .5 * xcor ) + ( 1 / 2 )
          ( .5 * ycor ) + ( 0 )
  ]
  if( random-function = 1 ) [
    setxy ( .5 * xcor ) + ( 0 )
          ( .5 * ycor ) + ( 0 )
  ]
  if( random-function = 2 ) [
    setxy ( .5 * xcor ) + ( 1 / 4 )
          ( .5 * ycor ) + ( sqrt(3) / 4 )
  ]
end 

to iterate-quint
  let random-function random 5
  if( random-function = 0 ) [
    setxy ( ( 1 / 3 ) * xcor ) + ( 0 )
          ( ( 1 / 3 ) * ycor ) + ( 0 )
  ]
  if( random-function = 1 ) [
    setxy ( ( 1 / 3 ) * xcor ) + ( 2 / 3 )
          ( ( 1 / 3 ) * ycor ) + ( 0 )
  ]
  if( random-function = 2 ) [
    setxy ( ( 1 / 3 ) * xcor ) + ( 1 / 3 )
          ( ( 1 / 3 ) * ycor ) + ( 1 / 3 )
  ]
  if( random-function = 3 ) [
    setxy ( ( 1 / 3 ) * xcor ) + ( 0 )
          ( ( 1 / 3 ) * ycor ) + ( 2 / 3 )
  ]
  if( random-function = 4 ) [
    setxy ( ( 1 / 3 ) * xcor ) + ( 2 / 3 )
          ( ( 1 / 3 ) * ycor ) + ( 2 / 3 )
  ]
end 

to iterate-leaves
  let random-function random 7
  if( random-function = 0 ) [
    setxy ( ( 1 / 3 ) * x ) + ( 2 / 3 )
          ( ( 1 / 3 ) * ycor ) + ( 0 )
  ]
  if( random-function > 0 and random-function < 3 ) [
    ;setxy ( ( sqrt(2) / 2 ) * ( sqrt(2) / 3 ) * xcor - ( sqrt(2) / 2 ) * ( sqrt(2) / 3 ) * ycor ) + ( 1 / 3 )
    ;      ( ( sqrt(2) / 2 ) * ( sqrt(2) / 3 ) * xcor + ( sqrt(2) / 2 ) * ( sqrt(2) / 3 ) * ycor ) + ( 0 )
    setxy ( ( 2 / 6 ) * xcor - ( 2 / 6 ) * ycor + ( 1 / 3 ) )
          ( ( 2 / 6 ) * xcor + ( 2 / 6 ) * ycor + 0 )
  ]
  if( random-function > 2 and random-function < 7 ) [
    setxy ( ( 2 / 3 ) * xcor ) + ( 1 / 3 )
          ( ( 2 / 3 ) * ycor ) + ( 1 / 3 )
  ]
end 

to iterate-problem-a
  let random-function random 11
  if( random-function >= 0 and random-function < 4 ) [ ;; lower left box
    setxy ( ( 1 / 2 ) * xcor ) + ( 0 )
          ( ( 1 / 2 ) * ycor ) + ( 0 )
  ]
  if( random-function >= 4 and random-function < 8 ) [ ;; upper right rotated box
    setxy ( - ( 1 / 2 ) * ycor ) + ( 1 )
          ( ( 1 / 2 ) * xcor ) + ( 1 / 2 )
  ]
  if( random-function = 8 ) [
    setxy ( ( 1 / 4 ) * xcor ) + ( 1 / 2 )
          ( ( 1 / 4 ) * ycor ) + ( 0 )
  ]
  if( random-function = 9 ) [
    setxy ( ( 1 / 4 ) * xcor ) + ( 3 / 4 )
          ( ( 1 / 4 ) * ycor ) + ( 0 )
  ]
  if( random-function = 10 ) [
    setxy ( - ( 1 / 4 ) * ycor ) + ( 1 )
          ( ( 1 / 4 ) * xcor ) + ( 1 / 4 )
  ]
end 

to iterate-problem-b
  let random-function random 3
  if( random-function = 0 ) [ ;; large box
    setxy ( - ( 1 / 2 ) * ycor ) + ( 1 / 2 )
          ( ( 1 / 2 ) * xcor ) + ( 1 / 2 )
  ]
  if( random-function = 1 ) [
    setxy ( ( 1 / 2 ) * xcor ) + ( 0 )
          ( ( 1 / 2 ) * ycor ) + ( 0 )
  ]
  if( random-function = 2 ) [
    setxy ( ( 1 / 2 ) * xcor ) + ( 1 / 2 )
          ( ( 1 / 2 ) * ycor ) + ( 0 )
  ]
end 

to-report x
  report xcor
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 white ]
      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 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 )
  ;; moves from original square position
  set xcor xcor + item 4 right-function
  set ycor ycor + item 5 right-function
;  set xcor ( item 1 right-function * xcor ) + ( item 2 right-function * ycor ) + ( item 5 right-function )
;  set ycor ( item 3 right-function * xcor ) + ( item 4 right-function * ycor ) + ( item 6 right-function )
end 

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 

to rotate-point [ my-rotation-matrix ]
  set xcor ( item 0 my-rotation-matrix * xcor ) + ( item 1 my-rotation-matrix * ycor ) + item 4 my-rotation-matrix
  set ycor ( item 2 my-rotation-matrix * xcor ) + ( item 3 my-rotation-matrix * ycor ) + item 5 my-rotation-matrix
end 

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 

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 [
    ;; scale, then reflect, then correct
;    let entry-a ( item 0 scale-matrix * item 0 reflection-matrix ) + ( item 2 scale-matrix * item 1 reflection-matrix )
;    let entry-b ( item 1 scale-matrix * item 0 reflection-matrix ) + ( item 3 scale-matrix * item 1 reflection-matrix )
;    let entry-c ( item 0 scale-matrix * item 2 reflection-matrix ) + ( item 2 scale-matrix * item 3 reflection-matrix )
;    let entry-d ( item 1 scale-matrix * item 2 reflection-matrix ) + ( item 3 scale-matrix * item 3 reflection-matrix )
    ;;set half-size my-size / 2
    ;; list elements: probability determined by ratio of area,
    ;;                rotation matrix a b c d
    ;;                x ( my xcor - half my size )
    ;;                y ( my ycor - half my size )
    set iterated-function-list lput ( list ( prob-counter ) reflection-matrix rotation-matrix 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 

There are 9 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 14 years ago Chaos Fractal Toolkit Download this version
Uri Wilensky over 14 years ago random stuff for testing Download this version
Uri Wilensky over 14 years ago random stuff for testing Download this version
Uri Wilensky over 14 years ago random stuff for testing Download this version
Uri Wilensky over 14 years ago random stuff for testing Download this version
Uri Wilensky over 14 years ago random stuff for testing Download this version
Uri Wilensky over 14 years ago random stuff for testing Download this version
Uri Wilensky over 14 years ago random stuff for testing Download this version
Uri Wilensky over 14 years ago random stuff for testing Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.