Join for FREE | Take the Tour Lost Password?
Shop deviantART for the
holidays and save BIG!
Click here! :holly:
[x]

deviantART

 
About Me Member Mad Scientist WelcomeToTheDeepEndUnited States Recent Activity Deviant for 1 Year
Needs Premium Membership
Statistics 31 Deviations
29 Comments
261 Pageviews

Code for star fractal

Wed Dec 17, 2008, 6:26 PM
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.Color;
import java.io.*;
import javax.imageio.*;
import [link].Point2D.Float;
import java.util.ArrayList;

public class Main{
public static final int height=1000;
public static final double Hyp=height/Math.sin(Math.toRadians(72));
public static final double SHRINK=Math.sin(Math.toRadians(38));
public static void main(String[] args){
ArrayList<Float> list=new ArrayList(12000);
double rev=1;
double size=1;
double x=300;
double y=height;
list.add(new Float((float)x,(float)y));

for(int i=0;i<3000;i++)
{
x+=Hyp*Math.cos(Math.toRadians(72))*size;
y-=Hyp*Math.sin(Math.toRadians(72))*size*rev;
list.add(new Float((float)x,(float)y));

x+=Hyp*Math.cos(Math.toRadians(72))*size;
y+=Hyp*Math.sin(Math.toRadians(72))*size*rev;
list.add(new Float((float)x,(float)y));

x-=Hyp*Math.cos(Math.toRadians(36))*size;
y-=Hyp*Math.sin(Math.toRadians(36))*size*rev;
list.add(new Float((float)x,(float)y));

x+=Hyp*size;
y=y+0;
list.add(new Float((float)x,(float)y));

size*=SHRINK;
rev*=-1;
}

//this creates a picture, makes the background white, and generates a graphics item
BufferedImage pic=new BufferedImage(4000,height,BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g=(Graphics2D)pic.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0,0,4000,height);
g.setColor(Color.black);

//this draws the lines
for(int i=1;i<list.size();i++)
g.drawLine((int)list.get(i-1).getX(), (int)list.get(i-1).getY(), (int)list.get(i).getX(), (int)list.get(i).getY());

//this saves the newly created picture
File file=new File("output.jpg");
try{
ImageIO.write(pic,"jpg",file);
}catch(Exception e){}
}
}

deviantID

Devious Info

  • Current Residence: Houston
  • MP3 player of choice: iPod, I know that it is buggy, but hey, it shows videos
  • Favourite gaming platform: PC for Political Corectness
  • Tools of the Trade: A camera and Paint.NET

deviantART Community Board

[x]

Comments


:iconexit20one:
I'm with kamietsukazehin, I didn't know you had this sort of thing. Unlike myself, you should be taking more pictures. This looks great!
:iconkamietsukazehin:
ok, so i've known you for about... 15 years. and i had no idea you could do this.

--
"Anybody have a life?.....That I can borrow?"

Forgive and Forget.....But keep a list of names
:icontoolshed333:
thanks for the fav

--
toolshed333

[link]
:iconsweetlike-honey:
thnx for the fav:D

--
Me & U only...just Me & U.... :blackrose:
:iconkeremizmir:
Thanks for the fav

--
Kerem Bektas ™
:iconrgc3:
Glad you think so. Heh.

Site Map