Login Register






L-Systems : Dragon Curve Fractal [Modified] filter_list
Author
Message
L-Systems : Dragon Curve Fractal [Modified] #1
I made this Dragon Fractal in Java. Its a bit modified. Next time I will make a better one with animation Biggrin

Code:
package dragon; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import javax.imageio.ImageIO; public final class DragonCurve { private BufferedImage img = null; private int IMG_WIDTH; private int IMG_HEIGHT; private GraphicsEnvironment ge = null; private GraphicsDevice gd = null; private GraphicsConfiguration gc = null; public DragonCurve() { IMG_WIDTH = 1400; IMG_HEIGHT = 1400; ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); gd = ge.getDefaultScreenDevice(); gc = gd.getDefaultConfiguration(); } private void createDragonFractal() { Graphics g = null; Graphics2D g2d = (Graphics2D) g; img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_RGB); img = gc.createCompatibleImage(IMG_WIDTH, IMG_HEIGHT); g2d = img.createGraphics(); g2d.setColor(Color.black); g2d.fillRect(0, 0, IMG_WIDTH, IMG_HEIGHT); g2d.setColor(Color.red); dragonRecur(300, 500, 1000, 1100, 20, g2d); g2d.drawImage(img, 0, 0, null); g2d.dispose(); writeImage(); } private void writeImage() { File file = new File("pic.png"); try { file.createNewFile(); OutputStream out = new FileOutputStream(file); ImageIO.write(img, "png", out); out.close(); } catch (IOException e) { e.printStackTrace(); } } private void dragonRecur(int x1, int y1, int x2, int y2, int k, Graphics2D g2d) { if (k > 0) { int xn = (x1 + x2) / 2 + (y2 - y1) / 2; int yn = (y1 + y2) / 2 - (x2 - x1) / 2; dragonRecur(x2, y2, xn, yn, k - 1, g2d); dragonRecur(x1, y1, xn, yn, k - 1, g2d); } else { g2d.drawLine(x1, y1, x2, y2); } } public static void main(String... strings) { new DragonCurve().createDragonFractal(); } }


Sample Output

[Image: vpmPoOv.png]

Source
[Image: OilyCostlyEwe.gif]

Reply

L-Systems : Dragon Curve Fractal [Modified] #2
I made this Dragon Fractal in Java. Its a bit modified. Next time I will make a better one with animation Biggrin

Code:
package dragon; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import javax.imageio.ImageIO; public final class DragonCurve { private BufferedImage img = null; private int IMG_WIDTH; private int IMG_HEIGHT; private GraphicsEnvironment ge = null; private GraphicsDevice gd = null; private GraphicsConfiguration gc = null; public DragonCurve() { IMG_WIDTH = 1400; IMG_HEIGHT = 1400; ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); gd = ge.getDefaultScreenDevice(); gc = gd.getDefaultConfiguration(); } private void createDragonFractal() { Graphics g = null; Graphics2D g2d = (Graphics2D) g; img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_RGB); img = gc.createCompatibleImage(IMG_WIDTH, IMG_HEIGHT); g2d = img.createGraphics(); g2d.setColor(Color.black); g2d.fillRect(0, 0, IMG_WIDTH, IMG_HEIGHT); g2d.setColor(Color.red); dragonRecur(300, 500, 1000, 1100, 20, g2d); g2d.drawImage(img, 0, 0, null); g2d.dispose(); writeImage(); } private void writeImage() { File file = new File("pic.png"); try { file.createNewFile(); OutputStream out = new FileOutputStream(file); ImageIO.write(img, "png", out); out.close(); } catch (IOException e) { e.printStackTrace(); } } private void dragonRecur(int x1, int y1, int x2, int y2, int k, Graphics2D g2d) { if (k > 0) { int xn = (x1 + x2) / 2 + (y2 - y1) / 2; int yn = (y1 + y2) / 2 - (x2 - x1) / 2; dragonRecur(x2, y2, xn, yn, k - 1, g2d); dragonRecur(x1, y1, xn, yn, k - 1, g2d); } else { g2d.drawLine(x1, y1, x2, y2); } } public static void main(String... strings) { new DragonCurve().createDragonFractal(); } }


Sample Output

[Image: vpmPoOv.png]

Source
[Image: OilyCostlyEwe.gif]

Reply

L-Systems : Dragon Curve Fractal [Modified] #3
I made this Dragon Fractal in Java. Its a bit modified. Next time I will make a better one with animation Biggrin

Code:
package dragon; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import javax.imageio.ImageIO; public final class DragonCurve { private BufferedImage img = null; private int IMG_WIDTH; private int IMG_HEIGHT; private GraphicsEnvironment ge = null; private GraphicsDevice gd = null; private GraphicsConfiguration gc = null; public DragonCurve() { IMG_WIDTH = 1400; IMG_HEIGHT = 1400; ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); gd = ge.getDefaultScreenDevice(); gc = gd.getDefaultConfiguration(); } private void createDragonFractal() { Graphics g = null; Graphics2D g2d = (Graphics2D) g; img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_RGB); img = gc.createCompatibleImage(IMG_WIDTH, IMG_HEIGHT); g2d = img.createGraphics(); g2d.setColor(Color.black); g2d.fillRect(0, 0, IMG_WIDTH, IMG_HEIGHT); g2d.setColor(Color.red); dragonRecur(300, 500, 1000, 1100, 20, g2d); g2d.drawImage(img, 0, 0, null); g2d.dispose(); writeImage(); } private void writeImage() { File file = new File("pic.png"); try { file.createNewFile(); OutputStream out = new FileOutputStream(file); ImageIO.write(img, "png", out); out.close(); } catch (IOException e) { e.printStackTrace(); } } private void dragonRecur(int x1, int y1, int x2, int y2, int k, Graphics2D g2d) { if (k > 0) { int xn = (x1 + x2) / 2 + (y2 - y1) / 2; int yn = (y1 + y2) / 2 - (x2 - x1) / 2; dragonRecur(x2, y2, xn, yn, k - 1, g2d); dragonRecur(x1, y1, xn, yn, k - 1, g2d); } else { g2d.drawLine(x1, y1, x2, y2); } } public static void main(String... strings) { new DragonCurve().createDragonFractal(); } }


Sample Output

[Image: vpmPoOv.png]

Source
[Image: OilyCostlyEwe.gif]

Reply

RE: L-Systems : Dragon Curve Fractal [Modified] #4
Thats pretty sweet man

Reply

RE: L-Systems : Dragon Curve Fractal [Modified] #5
Thats pretty sweet man

Reply

RE: L-Systems : Dragon Curve Fractal [Modified] #6
You should check out electric sheep. Their website is down so here is the wikipedia page. http://en.wikipedia.org/wiki/Electric_Sheep
http://electricsheep.org/
[Image: iQ3pcQu.png]
BTC Address: 1DCKgDaWcmc9dxBkhe9qrTQtrQpoFUzXdn

Reply

RE: L-Systems : Dragon Curve Fractal [Modified] #7
You should check out electric sheep. Their website is down so here is the wikipedia page. http://en.wikipedia.org/wiki/Electric_Sheep
http://electricsheep.org/
[Image: iQ3pcQu.png]
BTC Address: 1DCKgDaWcmc9dxBkhe9qrTQtrQpoFUzXdn

Reply

RE: L-Systems : Dragon Curve Fractal [Modified] #8
(09-16-2014, 07:55 PM)h3r0 Wrote: You should check out electric sheep. Their website is down so here is the wikipedia page. http://en.wikipedia.org/wiki/Electric_Sheep
http://electricsheep.org/

Ah I didn't knew about that one. I need the math functions else I won't be able to make it. Well I will Google Biggrin
[Image: OilyCostlyEwe.gif]

Reply

RE: L-Systems : Dragon Curve Fractal [Modified] #9
(09-16-2014, 07:55 PM)h3r0 Wrote: You should check out electric sheep. Their website is down so here is the wikipedia page. http://en.wikipedia.org/wiki/Electric_Sheep
http://electricsheep.org/

Ah I didn't knew about that one. I need the math functions else I won't be able to make it. Well I will Google Biggrin
[Image: OilyCostlyEwe.gif]

Reply

RE: L-Systems : Dragon Curve Fractal [Modified] #10
(09-17-2014, 02:44 AM)Psycho_Coder Wrote:
(09-16-2014, 07:55 PM)h3r0 Wrote: You should check out electric sheep. Their website is down so here is the wikipedia page. http://en.wikipedia.org/wiki/Electric_Sheep
http://electricsheep.org/

Ah I didn't knew about that one. I need the math functions else I won't be able to make it. Well I will Google Biggrin

My favorite thing about electric sheep though is that many computers are creating these fractal frames evolving the animation.
[Image: iQ3pcQu.png]
BTC Address: 1DCKgDaWcmc9dxBkhe9qrTQtrQpoFUzXdn

Reply