Animated Chaos Game in GHPython

Hi Guys,

Inspired by ‘The Coding Train’ I’ve made a simple chaos game using GHPython, but wanted to try animating it with grasshopper using a timer. I keep getting the Runtime error: Object reference not set to an instance of an object.

Everything I’ve tried doesn’t work and I can’t quite figure out what I’m missing, I think its where I’m outputting my lists to my custom geo component?

chaos game_02.gh (20.2 KB)

Add this line:
bild

// Rolf

The solution to your problem was already provided by @RIL. Out of pure curiosity, I also downloaded script and after fixing the missing object reference, I also needed to change all the 2d points to 3d points, for it to work. I just added a 0 as z-coordinate for each point tuple. Somewhere in your script, a 3d point is needed! :wink:

Unfortunately, that doesn’t work. You need to create the class object, then switch the toggle to update. Otherwise, the script just recreates the class object over and over.

Hi guys, I managed to find a solution to have it update live in grasshopper… was a matter of switch from RhinoScriptSyntax to Rhino.Geometry for the points. Now the game draws in real time with a timer.

Thanks for the assistance.

Sounds nice, @Karls. Could you elaborate on how you accomplished this please!

Hi pirateboy - sorry, not typing that one out!

Check out the script here. set the top Bool to false. enable the timer. and switch the top bool to true to see the script run.

chaos game_animating.gh (10.8 KB)

1 Like

Uh nice! Thanks for sharing. Have you ported other scripts from Coding Train to GHPython or is this your first one?

This is my first time, but I think I might start doing more for my YouTube channel

I’d like to check your channel out, if you please! What’s it called? Can you supply a link?

Always happy to share my channel!

1 Like

Thanks, you have some great content on your channel.

I’ve also managed to write Shiffman’s chaos game in GHPython. It’s of course inspired by your version.
What’s different in mine, is that there is no external counter, but a built-in one (thanks to @AndersDeleuran).
Furthermore, the class is saved in a sticky dictionary and then reloaded and updated, when the component refreshes. I also just output the initial start points, as well as a tree of new points in three branches. Each branch represents the points belonging to one of three start points. Colours are managed on the grasshopper canvas.

So far, I’ve run it up to 15 000 points with no issues or crashes. It just takes a little time. :sweat_smile:

You and everybody else, who’s interested, is welcome to check it out below.
(I’ll probably update it in the coming days with a few other features and re-share it. No promises, though.)

chaos_game_v1.0.gh (14.0 KB)

1 Like

Hello @Karls, @RIL and everybody else, :wave:

I’ve update my chaos game GHPython script, to make it correspond to Shiffman’s 2nd version!

Check it out, if you’re interested:
chaos_game_v2.0.gh (13.1 KB)

It’s now able to produce fractals, beyond the Sierpinski triangles.

Here are some changes:

  • the number of initial points can be changed (previously limited to 3)
  • the positions of the initial points can be random (previous version) or organised in a circular manner
  • the “algorithm” can be run with practically no rule, except the basic one (new point = old Point + temp point) * percentage), or with more rules. This can be achieved by writing a new class that inherits the basic chaos game, but overwrites its previous update() function (examples in the script).
  • the percentage can now also be changed (should be between 0.0 and 1.0, default 0.5 for a mid point)
  • a Speed input was introduced which speeds up the point generation (be carful here!)
  • presets are now available as input, and produce preset patterns (call functions that inherit the basic chaos game)

The pattern usually emerges around 10 000 to 15 000 points (also depending on the preview point size).

For now, I won’t develop the script any further. I’m satisfied with what it can do. :yum:

Great work!

1 Like