Results of a Bored Java Student

A Graphing Calculator

    I didn't realize that if you know C++, you can learn Java in a few days. It didn't take long until I was curious about the things I could make in the limited development environment supplied by my high school.

    During class, we had these short programs that would teach the student a basic concept in Java. It took me about a minute to complete each coding activity, so I often found myself staring at my Google Classroom assignments, pretending that I was doing something productive.

    After a little while, we finally got to learning how to call functions in Java. The demo we were given in class to practice was a simulation of a turtle that you could move around with function calls like forward() and turnRight(). This finally gave me an idea of something I could make in my free time.

    Around the same time, we were doing a lot of graphing in my Calculus class, so I thought it would be funny to make a graphing calculator using the turtle. While everyone was making the turtle draw squares, I had the turtle graphing y = cos(1/x), and x = sin(y). Yes, this thing can graph relations, not just functions.

y = cos(1/x)

A graph of y = cos(1/x)

A relation I cannot remember

A graph of something I don't remember

    I wish I could say this was cool. Of course the code behind it is pretty cool, but the demonstration of mathematics here is lacking. If I can graph real numbers, I better be able to graph imaginary numbers too. Yes, I'm talking about making a mandelbrot set with the turtles.

    I first wanted to make the fractal viewer in just ASCII art, but I ended up getting an image that didn't look like a mandelbrot.

The FailFractal

A Failfractal

    Turns out, This isn't a fluke, because I did a render using the turtles for color, and it also looks strange.

The Colored FailFractal

A Colored Failfractal

    The bug isn't actually in the math, it's just because I forgot how to use temporary variables.

Improper Imaginary Arithmetic

    public void Square()
        aReal = ( aReal * aReal ) - ( aImag * aImag );
        aImag = 2 * ( aReal * aImag );  // You can tell something's wrong here...

Proper Implementation

    public void Square()
        double real = ( aReal * aReal ) - ( aImag * aImag );
        aImag       = 2 * ( aReal * aImag );
        aReal       = real;

    You gotta love how experienced programmers create the simplest bugs that cause the most frustration. This almost feels embarrassing. Sure enough, after that fix, I had a working mandelbrot. I actually ported my fractal viewer to C before fixing this bug but I'll expand on that in a later post. I have no idea if I'm the first to discover the weird fractal I made with that small bug, but if I am, I would like it to be known as the FailFractal, discovered by me.

The Final Results