Making really big pictures

Hello, I have written a program that saves the Dragon Fractal to a file. The fractal is iteration based but I can only go up to the 26th iteration before I run out of heap space when I try to create the BufferedImage. How can I either use another image object or better manage my memory? I have extended my default heap space to 6 gigs when I run it from the terminal. My specs for my PC are: i7 920 @2.66*4, 6 Gb DDR3 2000, 1TB 7200 RPM HDD, Asus P6T Deluxe V2 Mobo, and a GTX 275. Here is my code, all in one class:
package fractal;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import javax.imageio.ImageIO;
@author Chris Philip
*public class DragonFractal {*
*private static boolean[] iteration;*
*private static int lineLength, xMin, xMax, yMin, yMax, width, height;*
*public static void main(String args[]) {*
*int iterations=Integer.parseInt(args[0]);*
*calcTurns(iterations);*
*calcSize(iterations);*
*draw(iterations);*
*private static void calcTurns(int iterations) {*
*boolean old[];*
*iteration = new boolean[] {true};*
*for(int i=2;i<=iterations;i++) {*
*old=iteration;*
*iteration=new boolean[old.length*2+1];*
*iteration[old.length]=true;*
*System.arraycopy(old, 0, iteration, 0, old.length);*
*System.arraycopy(old, 0, iteration, old.length+1, old.length/2);*
*iteration[old.length*3/2+1]=false;*
*System.arraycopy(old,old.length/2+1,iteration,(iteration.length-3)*3/4+3,old.length/2);*
*private static void calcSize(int iterations) {*
*double angle=Math.PI/4*iterations;*
*lineLength=2+(iterations%2);*
*int xStart=0,*
*xEnd=xStart+(int)(lineLength*Math.cos(angle)),*
*yStart=0,*
*yEnd=yStart+(int)(lineLength*Math.sin(angle));*
*xMin=xStart>xEnd?xEnd:xStart;*
*xMax=xStart>xEnd?xStart:xEnd;*
*yMin=yStart>yEnd?yEnd:yStart;*
*yMax=yStart>yEnd?yStart:yEnd;*
*for(int i=0; i<iteration.length; i++) {*
*angle+=Math.PI/2*(iteration?-1:1);
xStart=xEnd;
yStart=yEnd;
xEnd=xStart+(int)(lineLength*Math.cos(angle));
yEnd=yStart+(int)(lineLength*Math.sin(angle));
xMin=xMin>xEnd?xEnd:xMin;
xMax=xMax<xEnd?xEnd:xMax;
yMin=yMin>yEnd?yEnd:yMin;
yMax=yMax<yEnd?yEnd:yMax;
width=xMax-xMin+1;
height=yMax-yMin+1;
+}+
+private static void draw(int iterations) {+
BufferedImage image=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g=image.getGraphics();
BigDecimal counter=new BigDecimal("1"),
max=(new BigDecimal("2")).pow(iterations);
double angle=Math.PI/4*iterations;
int xStart=-xMin,
xEnd=xStart(int)(lineLength*Math.cos(angle)),
yStart=-yMin+1,
yEnd=yStart+(int)(lineLength*Math.sin(angle));
for(boolean turn:iteration) {
g.setColor(new Color(Color.HSBtoRGB((counter.divide(max, 3, RoundingMode.UP)).floatValue(), 1, 1)));
counter = counter.add(BigDecimal.ONE);
g.drawLine(xStart,height-yStart,xEnd,height-yEnd);
angle+=Math.PI/2*(turn?-1:1);
xStart=xEnd;
yStart=yEnd;
xEnd=xStart+(int)(lineLength*Math.cos(angle));
yEnd=yStart+(int)(lineLength*Math.sin(angle));
g.setColor(new Color(Color.HSBtoRGB((counter.divide(max, RoundingMode.UP)).floatValue(), 1, 1)));
g.drawLine(xStart,height-yStart,xEnd,height-yEnd);
try {
BufferedImage bi = image;
File outputfile = new File("C:\\Users\\Chris\\Desktop\\NewDragonCurve-"+iterations+".png");
ImageIO.write(bi, "png", outputfile);
} catch (IOException e) {
System.out.println("YOU FAIL");

Sorry about that, but you really don't have to read the code. Still here is another try:
package fractal;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import javax.imageio.ImageIO;
* @author Chris Philip
public class DragonFractal {
    private static boolean[] iteration;
    private static int lineLength, xMin, xMax, yMin, yMax, width, height;
    public static void main(String args[]) {
        int iterations=Integer.parseInt(args[0]);
        calcTurns(iterations);
        calcSize(iterations);
        draw(iterations);
    private static void calcTurns(int iterations) {
        boolean old[];
        iteration = new boolean[] {true};
        for(int i=2;i<=iterations;i++) {
            old=iteration;
            iteration=new boolean[old.length*2+1];
            iteration[old.length]=true;
            System.arraycopy(old, 0, iteration, 0, old.length);
            System.arraycopy(old, 0, iteration, old.length+1, old.length/2);
            iteration[old.length*3/2+1]=false;
            System.arraycopy(old,old.length/2+1,iteration,(iteration.length-3)*3/4+3,old.length/2);
    private static void calcSize(int iterations) {
        double angle=Math.PI/4*iterations;
        lineLength=2+(iterations%2);
        int xStart=0,
            xEnd=xStart+(int)(lineLength*Math.cos(angle)),
            yStart=0,
            yEnd=yStart+(int)(lineLength*Math.sin(angle));
        xMin=xStart>xEnd?xEnd:xStart;
        xMax=xStart>xEnd?xStart:xEnd;
        yMin=yStart>yEnd?yEnd:yStart;
        yMax=yStart>yEnd?yStart:yEnd;
        for(int i=0; i<iteration.length; i++) {
            angle+=Math.PI/2*(iteration?-1:1);
xStart=xEnd;
yStart=yEnd;
xEnd=xStart+(int)(lineLength*Math.cos(angle));
yEnd=yStart+(int)(lineLength*Math.sin(angle));
xMin=xMin>xEnd?xEnd:xMin;
xMax=xMax<xEnd?xEnd:xMax;
yMin=yMin>yEnd?yEnd:yMin;
yMax=yMax<yEnd?yEnd:yMax;
width=xMax-xMin+1;
height=yMax-yMin+1;
// System.out.println("Iteration "+iterations+
// ":\tWidth: "+(xMax-xMin+1)+
// "\tHeight: "+(yMax-yMin+1)+
// "\tXMax: "+xMax+
// "\tMMin: "+xMin+
// "\tYMax: "+yMax+
// "\tYMin: "+yMin);
private static void draw(int iterations) {
BufferedImage image=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g=image.getGraphics();
BigDecimal counter=new BigDecimal("1"),
max=(new BigDecimal("2")).pow(iterations);
double angle=Math.PI/4*iterations;
int xStart=-xMin,
xEnd=xStart+(int)(lineLength*Math.cos(angle)),
yStart=-yMin+1,
yEnd=yStart+(int)(lineLength*Math.sin(angle));
for(boolean turn:iteration) {
g.setColor(new Color(Color.HSBtoRGB((counter.divide(max, 3, RoundingMode.UP)).floatValue(), 1, 1)));
counter = counter.add(BigDecimal.ONE);
g.drawLine(xStart,height-yStart,xEnd,height-yEnd);
angle+=Math.PI/2*(turn?-1:1);
xStart=xEnd;
yStart=yEnd;
xEnd=xStart+(int)(lineLength*Math.cos(angle));
yEnd=yStart+(int)(lineLength*Math.sin(angle));
g.setColor(new Color(Color.HSBtoRGB((counter.divide(max, RoundingMode.UP)).floatValue(), 1, 1)));
g.drawLine(xStart,height-yStart,xEnd,height-yEnd);
try {
BufferedImage bi = image;
File outputfile = new File("C:\\Users\\Chris\\Desktop\\NewDragonCurve-"+iterations+".png");
ImageIO.write(bi, "png", outputfile);
} catch (IOException e) {
System.out.println("YOU FAIL");

Similar Messages

  • Windows PC User Making The Big Switch To Mac OS X & MacBook 2.0GHz

    I'm from the Philippines. I've been a Windows PC user for around 10 years. I figured it's time to replace my old Pentium III 500MHz/Win98SE with a newer system to keep up with highter system requirements set forth by newer applications.
    The features I looked for include portability, performance, connectivity (built-in WiFi & Bluetooth) and value (not too expensive). I'm initially leaning towards getting another Windows XP-based platform because Windows-based apps are readily available here and getting tech support for the Mac would be a little prob. Also, I just can't afford to leave behind some applications that are somehoew inexistent in the Mac world, but the mere thought that the PC world would soon be shifting to Vista kinda turned me off. Nobody wants to buy a new notebook that would suddenly become obsolete in just a few months or so.
    However, everything changed when online research led me to Apple's homepage (www.apple.com), where I discovered Mac's latest wonder: the Macbook. I heared about the Mac OS X's reputation for stability and performance. They say Macs are less prone to worms & viruses too since most of these things were designed specificically to infect Windows-based platforms. Looks like this is it for me. I'll be getting a MacBook 2.0GHz soon.
    I must admit that what primarily attracted me to the Intel-powered Macbook is the fact that it could now run two operating systems thru "Boot Camp" or Parallels For Mac. Two applications that would give me the capability to run Mac OS X and Windows XP on a single platform. It's like having the best of both worlds.
    For me, this is really great news but I still have questions though. The Macbook is a new release, so I'm still iffy about purchasing it as new technology is notorious for having many annoying quirks and kinks that need to be smoothed out.
    My question is... What are the PROS and CONS of using BootCamp and Parallels respectively? Is Parallels better than the other? Which one would you recommend? Should I decide to install both, will there be any hitches?
    I won't be upgrading for the next 5 years or so. The notebook will likely see some heavy use for Medical Transcription work and maybe occasional gaming (mostly flight sims). This would be my first Mac purchase so I better do it right the first time. So if you have any comments, feedbacks, suggestions... kindly post it here.
    I'll be making the big switch soon.
    Rich

    I'm running Parallels on an iMac 2.0 GHz, and I absolutely love it! I expected all sorts of glitches and found virtually none. The only drawback I know if is that it treats your USB 2.0 ports like USB 1.1. Otherwise, my Windows XP virtual machine inside of Parallels doesn't seem to know it's not on a PC; it runs smoothly and much faster than on my previous 1.5GHz PC with 1.0 GB RAM. I've loaded Quicken for Windows, MS Office, Norton Anti-Virus, Adobe Acrobat, and several other Windows Apps with no troubles at all. I'm telling you, this software (Parallels) is amazing. I feel like I literally have two computers now.
    I would recommend that you have 2.0 GB of RAM, because while you're running Parallels, you have 2 OS's operating at the same time. But the ability to switch back and forth between the two OS's, share files, cut and paste - well, it's simply awesome, and well worth any extra cost.

  • Big picture - conceptual guidance

    As a newbie buying CS5 Web Premium I started using Flash Catalyst first. I initially found Catalyst was more useful to me as I am more interested in Flash use for web design. I tried out all the main features and loved it. However, there are some things that FC just will not do and so I need to develop my knowledge of Flash Pro.
    Here's the thing I need guidance on. I find the Page/States so easy to grasp. They are excellent for tranistions and make designing web pages/sites so much easier, that concept is simple and fluid to me. What I fail to grasp is how one would operate in Flash Pro - in a similar way. I apreciate the Timeline use in Flash Pro for animation but Animation is not my thing. I will make more use of the 'website interaction' stuff that Flash is capable of.
    So I guess the 'big picture' question is this - How does one use Flash Pro in a kind of Page/States way ?
    Does one use grouped layers instead of page/states - or - does one use key frames instead of Page/States ?
    Before I start designing, I really want to grasp the concept of operating in Flash Pro to produce websites so I have the foundation set in my mind.
    I hope I got the issue across - I fear I have not communicated this very well but hopefully, someone out there will understand.
    regards

    There are a number of different ways to approach a web site design in Flash, and all kinds of variations among them and in combining them since each can serve a useful purpose.  You can use the timeline to isolate separate sections, or you can use movieclips to contain them and manage their visibility, or you can have your sections as separate swf files (or library content) that get loaded dynamically, or you can have content that is created entirely dynamically using internal/external data resources.
    I'd say rather than picking one to follow, learn them all since they all offer certain features that prove useful under varying circumstances.

  • Home screen really big,can only see the center, cant move it or shrink it

    iphone 4 been working just fine, went to turn it on today , pushed the button, turned on screen and the picture was blown up really big. could only see the center, could not slide or shrink so cant answer my phone or access the home page. Tried restarting with the power button, and tried resetting by holding down both buttons for 10 seconds....still the same.Any ideas?

    to make shure this does not happen again go to settings, general, accessibility, and under zoom just turn that off

  • I updated my iphone to ios 7.1.1 and after that my contact photo when i call or call others to me is a small cycle of that picture i choose ... How can i make a big picture when i call my contant and when others call me ?

    I updated my iphone to ios 7.1.1 and after that my contact photo when i call or call others to me is a small cycle of that picture i choose ... How can i make a big picture when i call my contant and when others call me ?

    It's not clear why Apple made this change; speculation (which is not really allowed in these forums) is that it was done to protect the privacy of the caller.

  • HT4995 My location is sometimes wrong it says I'm in the middle of the ocean 80 miles away. This even happens when I'm connected to my wifi. This has become a really big pain in the ***.

    My location is sometimes wrong it says I'm in the middle of the ocean 80 miles away. This even happens when I'm connected to my wifi. This has become a really big pain in the ***. I've tried resetting and all that jazz but still I can't find a solution.

    If your country's iTunes Store allows you to redownload purchased tracks, I'd delete your current copies of the dodgy tracks and try redownloading fresh copies. For instructions, see the following document:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    Otherwise, I'd report the problem to the iTunes Store.
    Log in to the Store. Click on "Account" in your Quick Links. When you're in your Account information screen, go down to Purchase History and click "See all".
    Find the items that are not playing properly. If you can't see "Report a Problem" next to the items, click the "Report a problem" button. Now click the "Report a Problem" links next to the items.

  • Small picture inset in the big picture

    Why would the printer print a picture that has part of the picture set in the big picture?  On the page preview it doesn't show up but.  It has happened when printing a PDF and also when printing a bmp. file.  Any ideas?
    Thanks.
    Bert

    What printer model?  What program are you printing from?  
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

  • In mail drag and drop to desktop does not work with big pictures in 10.9

    My drag and drop function in apple mail program does not working anymore after upgrade to macos 10.9
    Big picture in my mail does not want to drag to the desktop anymore!
    Imac 2.93 Ghz core i7

    Hello,
    Please give your SPS (Java) and Patch level of BIBASES & BIWEBAPP.
    Regards, Karol
    SAP NetWeaver BI, Development

  • My screen has gone haywire - the screen content has gone REALLY BIG, how do I get it back to normal?

    I have a problem with my Iphone 6.  The screen content has resized itself to be really big and it will not go back to normal even though I have rebooted it.  Anyone know what has gone wrong and how to fix it?

        Let's take a closer look into this! Is larger text on? Settings > General > Accessibility > Larger Text
    YosefT_VZW
    Follow us on Twitter @VZWSupport

  • Calculating hash values for really big files

    I am using the following code to calculate the hash values of files
    public static String hash(File f, String algorithm)
                throws IOException, NoSuchAlgorithmException {
            if (!f.isFile()) {
                throw new IOException("Not a file");
            RandomAccessFile raf = new RandomAccessFile(f, "r");
            byte b[] = new byte[(int) raf.length()];
            raf.readFully(b);
            raf.close();
            MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
            messageDigest.update(b);
            return toHexString(messageDigest.digest());
        }Now the problem is, for really big files, 100 MB or over, I get an OutOfMemoryError.
    I have used the -Xms and -Xms options to increase the JVM heap size, and untimately made it to work. However, I think this is lame and there is also a limit to the -Xmx option.
    Is there any other way I can calculate the hash values of these really big files?
    Thanks a lot in advance.

    why do u open the file the way u do ?
    why to u upload ALL the file AT ONCE into the memory ?
    i would do it like this:
    FileInputStream fis = new FileInputStream (f);
    int fileSize = f.available();
    byte buffer[] = new byte[1000];
    MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
    for(int read = 0;read < fileSize;read +=1000;)
    if(fis.available() > 1000)
    fis.read(buffer, read, 1000);
    else if(fis.available() > 0)
    fis.read(buffer, read, fis.available());
    else
    break;
    messageDigest.update(b);
    fis.close();
    return toHexString(messageDigest.digest());

  • Displaying a Big Picture on Flash CS4

    Hello folks..........
    It is possible to create a flash picture that the user
    can drag around ?
    In another words, this will be a big picture
    on a small area or screen and the person with
    scrollbars or mouse can drag / pan the picture.
    Thanks
    Gesy

    Yes, if you place the image inside a movieclip you can use actionscript to control the x and y properties of the movieclip (to move it around with scrollers) and to have it draggable.  You can also add a mask over it to define the area of it that will be viewed.

  • How to separate 2 divisions via authorization; Big Picture needed

    Hi,
    we are going to use our CRM System for a second Division and we are planning to do this with the SAP Authorization Concept. (Main Issue: Div 2 is not allowed to see the BPs of Div 1)
    I found some relevant SAP Notes for this; for example Note 545334(Separate the BP Transaction Results of the F4 Search) But I`m still missing the BIG Picture.
    Does anybody have some hints for me how to get the big Picture?
    Thanks in advance
    Best regards
    EVA

    Dagfinn,
    You probably need to send email to Amit Levavi. Technically with my infrastructure/landscape project experiences, I would agree with Alternative 4. If SSL and Security is not an issue, and you have the same audience (external/intranet, etc.), then it would be my approach as well. Even with a Big Portal, with J2EE WAS 6.40, you can always add servers.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/25cab009-0801-0010-1380-edaa1d5e7f85

  • KCLP - can someone give me the big picture?

    In a project I have to review I stumbled into some log files displayed with Tx KCLP. It's some "external data transfer" logs.
    Unfortunately I miss the big picture and I did not find much on KCLP. Can someone give me a hint what's the big picture, e.g. what kind of applications use the KCLP logs.
    Thanks Frank

    I know KCLP is used by CO-PA to import external data via KEFC.
    THe bigger picture is
    - provide an import structure
    - define some transfer rules
    - post the data
    Christian

  • The April 22 Earth Day in 2000 combined the big-picture feis

    The April 22 Earth Day in 2000 combined the big-picture feistiness of the first Earth Day with the international grassroots activism of Earth Day 1990.....
    [url=http://cyberload.net/mc/index.php?topic=140263.0]Watch Captain America 2 Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140276.0]Watch Captain America The Winter Soldier Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140283.0]Watch Noah Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140299.0]Watch Rio 2 Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140314.0]Watch Divergent Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140323.0]Watch Oculus Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140331.0]Watch 300 Rise of An Empire Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140334.0]Watch Need for Speed Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140343.0]Watch God's Not Dead Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140348.0]Watch The Raid 2 Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140369.0]Watch The Grand Budapest Hotel Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140378.0]Watch Frozen Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140406.0]Watch That Awkward Moment Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140423.0]Watch The Lego Movie Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140440.0]Watch Draft Day Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140454.0]Watch Vampire Academy Online[/url]
    [url=http://cyberload.net/mc/index.php?topic=140467.0]Watch Non Stop Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47065.0]Watch Captain America 2 Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47115.0]Watch Captain America The Winter Soldier Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47147.0]Watch Noah Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47175.0]Watch Rio 2 Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47198.0]Watch Divergent Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47232.0]Watch Oculus Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47272.0]Watch 300 Rise of An Empire Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47306.0]Watch Need for Speed Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47346.0]Watch God's Not Dead Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47367.0]Watch The Raid 2 Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47397.0]Watch The Grand Budapest Hotel Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47422.0]Watch Frozen Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47467.0]Watch That Awkward Moment Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47536.0]Watch The Lego Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47585.0]Watch Draft Day Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47618.0]Watch Vampire Academy Movie Online[/url]
    [url=http://thesewingsourceinc.com/forum/index.php?topic=47652.0]Watch Non Stop Movie Online[/url]
    Earth Day is an annual event, celebrated on April 22, on which events are held worldwide to demonstrate support for environmental protection.

    What Intel video card do you have? The only Intel HD graphics cards officially supported by Photoshop CC are:
    Intel HD Graphics P3000
    Intel HD Graphics P4000
    Intel(R) HD Graphics P4600/P4700
    Intel HD Graphics 5000
    Go here to read more about the requirements: Photoshop CC and CC 2014 GPU FAQ

  • Cisco network management software's/application's in a big picture

    Hi,
    I am looking for a document or slide which can help me understand the various Cisco network management software umbrella.
    I mean there are so many Cisco network management software, one big picture of all the application will help me understand.
    Thanks
    Mudassir

    Hi,
    I am looking for a document or slide which can help me understand the various Cisco network management software umbrella.
    I mean there are so many Cisco network management software, one big picture of all the application will help me understand.
    Thanks
    Mudassir

Maybe you are looking for