Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Closed Thread
 
Thread Tools Display Modes
Old Mar 4th, 2006, 9:32 PM   #1
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 579
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
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]
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline  
Old Mar 6th, 2006, 6:23 AM   #2
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 579
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Does anyone know how to help me with this?
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline  
Old Mar 7th, 2006, 9:41 PM   #3
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 579
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
Does anyone have any clue on how to help me or what is wrong?
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline  
Old Mar 7th, 2006, 9:51 PM   #4
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 641
Rep Power: 4 Jessehk is on a distinguished road
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!
Jessehk is offline  
Old Mar 7th, 2006, 10:20 PM   #5
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
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
Dameon is offline  
Old Mar 8th, 2006, 6:55 AM   #6
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 579
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
This is the chaos game

Chaos Game
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline  
Old Mar 8th, 2006, 7:02 AM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline  
Old Mar 8th, 2006, 9:42 AM   #8
Quagmire
Newbie
 
Quagmire's Avatar
 
Join Date: Feb 2006
Location: Ohio
Posts: 22
Rep Power: 0 Quagmire is an unknown quantity at this point
Dawei, you must have no life.
Quagmire is offline  
Old Mar 8th, 2006, 11:22 AM   #9
zorin
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 218
Rep Power: 4 zorin is on a distinguished road
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.
zorin is offline  
Old Mar 8th, 2006, 11:32 AM   #10
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Quote:
Originally Posted by Quagmire
Dawei, you must have no life.
You must have no brains.
Polyphemus_ is offline  
Closed Thread

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:23 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC