Вы находитесь на странице: 1из 4

// This program is used to draw different types of fractals and simulate chaos

import TerminalIO.KeyboardReader; //Imports Keyboard reader to read keyboard inputs


import java.util.Scanner; //Imports Scanner to read multiple number strings
import java.text.DecimalFormat; //Imports decimal formatting tool
import java.util.Arrays;// Allows use of Arrays
import java.lang.Math; //Imports code to use mathematical terms
import TurtleGraphics.*;
import java.awt.*;
import java.util.*;
class fractalTypes{
public void dragon(){
Scanner multi = new Scanner( System.in ); //makes new copy of code
KeyboardReader reader = new KeyboardReader(); //makes new copy of code
DecimalFormat Dec = new DecimalFormat("0.0000"); //makes new copy of code
Timer timer = new Timer();
double length = 1, angle = 90;
int speed = 0;
System.out.println("Please enter the length of the pen between 1 and 10");
length = reader.readDouble();
System.out.println("Would you like to watch the fractal print?");
String watch = reader.readLine();
StandardPen pen = new StandardPen();
pen.setColor(Color.blue);
pen.setWidth(1);
pen.turn(angle);
for(long i = 1; i <= 1000000; i++){
boolean turn = (((i & -i) << 1) & i) != 0;
if(turn == false){
pen.turn(-90);
pen.move(length);

}
if(turn == true){
pen.turn(90);
pen.move(length);
}
if(watch.equals("yes")){
try {
Thread.sleep(6);
}
catch (InterruptedException ie) {
// Handle the exception
}
}
}
}
public void chaos(){
Scanner multi = new Scanner( System.in ); //makes new copy of code
KeyboardReader reader = new KeyboardReader(); //makes new copy of code
DecimalFormat Dec = new DecimalFormat("0.0000"); //makes new copy of code
Timer timer = new Timer();
double length = 10, angle = 90;
int speed = 0;
System.out.println("Please enter initial angle of the pen");
angle = reader.readDouble();
StandardPen pen = new StandardPen();
pen.setColor(Color.red);
pen.setWidth(1);
for(int i = 0; i <= 1000000; i++){
pen.turn(angle);

pen.move(length);
angle = angle + Math.random();
try {
Thread.sleep(6);
}
catch (InterruptedException ie) {
// Handle the exception
}
}
}
public void pattern(){
Scanner multi = new Scanner( System.in ); //makes new copy of code
KeyboardReader reader = new KeyboardReader(); //makes new copy of code
DecimalFormat Dec = new DecimalFormat("0.0000"); //makes new copy of code
Timer timer = new Timer();
double length = 10, angle = 90;
int speed = 0;
System.out.println("Enter the initial angle to start the fractal.");
angle = reader.readDouble();;
StandardPen pen = new StandardPen();
pen.setColor(Color.green);
pen.setWidth(1);
for(int i = 0; i <= 1000000; i++){
pen.turn(angle);
pen.move(length);
angle = angle + i;
try {
Thread.sleep(6);
}
catch (InterruptedException ie) {

// Handle the exception


}
}
}
}
class fractalGenerator {
//pen.setColor(Color.color name) sets color of pen
//pen.setWidth(size) sets width of pen
public static void main(String args[]){
Scanner multi = new Scanner( System.in ); //makes new copy of code
KeyboardReader reader = new KeyboardReader(); //makes new copy of code
DecimalFormat Dec = new DecimalFormat("0.0000"); //makes new copy of code
Timer timer = new Timer();
fractalTypes fractal = new fractalTypes();
String choose;
System.out.println("What type of fractal would you like to make?");
System.out.println("The options are:");
System.out.println("dragon");
System.out.println("chaos");
System.out.println("pattern");
choose = reader.readLine();
if(choose.equals("dragon")) fractal.dragon();
if(choose.equals("chaos")) fractal.chaos();
if(choose.equals("pattern")) fractal.pattern();
}
}

Вам также может понравиться