![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
Chaos Game
Can someone help me come up with a different version of the chaos game?
This code works and makes Serpinski's Triangle: [PHP] import java.awt.*; import java.applet.*; import java.awt.event.*; import java.util.Random; public class ChaosGamePrj extends Applet implements ActionListener { //private Button startButton; //private Button pauseButton; //private Button quitButton; private String str = "Welcome to Chaos Game"; private int x1=200; private int y1=50; private int x2=50; private int y2=200; private int x3=350; private int y3=200; private int i=1; private int x=250, y=150; private int maxPts = 100000; private int startX = 250; private int startY = 100; int n; Random gen = new Random(); public void init() { /* startButton = new Button("Start"); add(startButton); pauseButton = new Button("Pause"); add(pauseButton); quitButton = new Button("Quit"); add(quitButton); startButton.addActionListener(this); pauseButton.addActionListener(this); quitButton.addActionListener(this); */ } public void actionPerformed(ActionEvent event) { /* if(event.getSource() == startButton) str = "Start"; if(event.getSource() == pauseButton) str ="Pause"; if(event.getSource() == quitButton) str = "Quit"; //repaint(); */ } public void paint(Graphics g) { g.drawString(str, 10, 20 ); g.setColor(Color.red); g.fillOval(x1,y1,1,1); g.fillOval(x2,y2,1,1); g.fillOval(x3,y3,1,1); while (i<maxPts) { int rand = gen.nextInt(3) + 1; if(rand ==1) { startX = (startX + x1)/2; startY = (startY + y1)/2; g.fillOval(startX,startY,1,1); } if(rand ==2) { startX = (startX + x2)/2; startY = (startY + y2)/2; g.fillOval(startX,startY,1,1); } if(rand == 3) { startX = (startX + x3)/2; startY = (startY + y3)/2; g.fillOval(startX,startY,1,1); } i++; } } } [/PHP] This code does not work... I am trying to make a "Square Gasket" Could someone please help me out? [PHP] import java.awt.*; import java.applet.*; import java.awt.event.*; import java.util.Random; public class ChaosSquare extends Applet implements ActionListener { //private Button startButton; //private Button pauseButton; //private Button quitButton; private String str = "Welcome to Chaos Game"; private int x1=50; private int y1=50; private int x2=50; private int y2=350; private int x3=350; private int y3=350; private int x4=350; private int y4=50; private int i=1; private int x=250, y=150; private int maxPts = 10000000; private int startX = 200; private int startY = 200; private int X1 = 50; private int Y1 = 200; private int X2 = 200; private int Y2 = 50; private int X3 = 350; private int Y3 = 200; private int X4 = 200; private int Y4 = 50; int n; Random gen = new Random(); public void init() { /* startButton = new Button("Start"); add(startButton); pauseButton = new Button("Pause"); add(pauseButton); quitButton = new Button("Quit"); add(quitButton); startButton.addActionListener(this); pauseButton.addActionListener(this); quitButton.addActionListener(this); */ } public void actionPerformed(ActionEvent event) { /* if(event.getSource() == startButton) str = "Start"; if(event.getSource() == pauseButton) str ="Pause"; if(event.getSource() == quitButton) str = "Quit"; //repaint(); */ } public void paint(Graphics g) { g.drawString(str, 10, 20 ); g.setColor(Color.red); g.fillOval(x1,y1,1,1); g.fillOval(x2,y2,1,1); g.fillOval(x3,y3,1,1); g.fillOval(x4,y4,1,1); while (i<maxPts) { int rand = gen.nextInt(4) + 1; if(rand ==1) { x1 = (x1 + X1)/2; y1 = (y1 + Y1)/2; g.fillOval(x1,y1,1,1); } if(rand ==2) { x2 = (x2 + X2)/2; y2 = (y2 + Y2)/2; g.fillOval(x2,y2,1,1); } if(rand == 3) { x3 = (x3 + X3)/2; y3 = (y3 + Y3)/2; g.fillOval(x3,y3,1,1); } if(rand==4) { x4 = (x4 + X4)/2; y4 = (y4 + Y4)/2; g.fillOval(x4,y4,1,1); } i++; } } } [/PHP]
__________________
|
|
|
|
|
#2 |
|
Expert Programmer
|
Does anyone know how to help me with this?
__________________
|
|
|
|
|
#3 |
|
Expert Programmer
|
Does anyone have any clue on how to help me or what is wrong?
__________________
|
|
|
|
|
#4 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 641
Rep Power: 4
![]() |
Well, what are you trying to do?
I don't know what the chaos game is. I don't know why the code above does not compile, or work. Is there an area that does not work? Do you have any error messages? You have to provide more information in order to aid those who could possibly aid you.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
#5 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
You may want to look into arrays for some of those instance variables. Cleaner code and much fewer lines. And names that differ only by case generally aren't a great idea. Especially when you make a typo.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
#6 |
|
Expert Programmer
|
__________________
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Throwing up code and saying, "This doesn't work. Help." is a sucky approach. It would require people to intuit your purposes and your design, THEN go through the code in great detail, or even compile and debug it. It's much better to explain what the code is supposed to do, how it is failing to do that, what errors your compiler/linker issue to you, where in the code they are occurring, minor shit like that.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
#8 |
|
Newbie
Join Date: Feb 2006
Location: Ohio
Posts: 22
Rep Power: 0
![]() |
Dawei, you must have no life.
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 218
Rep Power: 4
![]() |
Quagmire, give it a rest, we all know you don't get on with DaWei, but posting comments like your own is just going to start another flame war and ruin the originals posters post.
|
|
|
|
|
#10 | |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
Quote:
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|