This site requires JavaScript, please enable it in your browser!
Greenfoot back
mrbones
mrbones wrote ...

2013/8/24

Chaos Game Technique

mrbones mrbones

2013/8/24

#
Hello all, I am just starting out in programming, and I am trying to make a Sierpinksi gasket - a fractal. I was told to use the chaos game technique, but I am very confused by all of this. Can anybody help me out? Please keep in mind, I am VERY new to programming so I need a simple description. Better yet, even the code itself. Thanks everybody. Gasket
danpost danpost

2013/8/24

#
You were told to use the chaos game technique. Is this a requirement? Is this a school project? If you are so new to programming, then why are you trying to tackle this problem? You should be working on basic stuff; not on something that requires some knowledge of java and programming.
mrbones mrbones

2013/8/24

#
It is not a school assignment in specific terms, it is more of just something that I want to try to incorporate into my games for my school assignment. I am fully aware that it is complicated, but I want to take on the challenge, after all that's how we learn. My teacher has mentioned the chaos game technique and fractals, but I'm still confused. I have tried researching it, but what I have found is either not detailed enough, or too complicated. I have been programming for a bit now, but not enough to understand this concept. If you could help that we would be fantastic!!!!!1
danpost danpost

2013/8/24

#
I created an Actor subclass called 'Node' whose image is a point and whose instances hold the location of the node within the triangle. The location values are passed to each node through constructor call parameters where the constructor saves the values in instance fields (I made them 'public' for easy access; but you may make them 'private' and create 'get' methods for accessing). In the world constructor, I created the initial Node object with (0, 0) location values (although the actual location of the object was (300, 44) in my 600x600 world). The world act method created two new Node objects for each Node object already in the world each cycle, provided that the location values for the new nodes were within the main triangle region. Each node was placed at (300+node.x, 44+node.y in my world). I added an instance int field in the world class to track the distance the new nodes needed to be from the current ones. I started its value at 512, and each cycle would divide it by 2. When its value reached one, I stopped creating new nodes. I also added a timer to add a delay between each cycle to create the animation of the gasket being built. I uploaded my Sierpinski Triangle scenario with source for you to look at.
mrbones mrbones

2013/8/24

#
First off I'm pretty impressed that you could just drum up the code like that. So thanks for that. I now understand that you take the node, add the distance, and divide it by two and that's how you add the point. I also get the idea of having the timer, but I'm confused on three things. First off the entire idea of a node, is it just a point? or a distance? also where do you define it? The next part that I'm confused about is the timer. this is my first exposure to timers so what is the code saying? what does this mean "timer = (timer+1)%50; if (timer != 0) return; " finally what the heck does "Greenfoot.setWorld(new Triangle());" that part of the code do? is it just adding a triangle. Sorry for all of the questions, I'm trying to learn how the code works, not just copy it for part of a project.
danpost danpost

2013/8/24

#
Yes, a node is a point; but it is actually more than that. It is also a vertex for possible future points. The Node class defines the point (or node). It creates actors whose image is a point and holds its location with respect to the initial Node object created in the world constructor. The first line in the timer code you are confused about increments the timer field and returns the remainder after dividing by 50. The value of the timer will increase to 49, then start back at zero and count up to 49 again and again. The second line performs an exit (return) out of the method (without executing any further code) if the timer is not at zero. The two lines together, adds a delay between the adding of new nodes at a shorter distance. Finally, 'Greenfoot.setWorld(new Triangle());' does not add a triangle, per se. It basically resets the scenario (it is like you clicking on both the 'Reset' and 'Run' buttons). It works like that in this case since you only have one world class and no static fields. If you do not understand that, do not fret; just think of it this way: when you load a scenario, a new world object is created and set as the current world whose code is to be executed when started; by setting a new 'Triangle' world, you are doing the same thing -- creating and setting a new 'Triangle' world object as current and its code is then executed.
mrbones mrbones

2013/8/24

#
So I now understand the concept of a timer, but the nodes are still tripping me up. Is there a way to make this program without nodes? Perhaps a solution more on my level of programming?
danpost danpost

2013/8/24

#
If you mean without Node actor objects, yes. However, you would then need to save the list of points already set (which is what is returned with 'getObjects(Node.class)') and you would also need to draw the point onto the screen (without Actor objects, you would need to draw the points onto the background of the world; I displayed them by adding the Node objects into the world, which each have the image of a point). I will attempt to create another world class to work it without the Node objects and upload it again.
mrbones mrbones

2013/8/24

#
That would be fantastic if you could. I am really trying to learn here, not just ind the right answer
mrbones mrbones

2013/8/25

#
Thanks for all of the help danpost, I now understand it.
You need to login to post a reply.