Programming

The art of Code

< Universe2D Our Solar System Solar System Generator Interactive Mandelbrot Fractal Interactive Julia Sets Vogel Disk Sample Generator Gaussian Kernel Calculator <

Why I code

Coding for fun

I think programming is a lot of fun, although it can sometimes drive you crazy.
The thing I think is fascinating about computers, is that a computer does what you say him to do, not what you want him to do. In the real world this difference isn't very present. When you work with code, you realize how inacurate your expressing things, and how much rethinking has to be done. That's a big difference between humans and computers: we do not need exact descriptions to know what to do.
I also really enjoy creating new things, even if their use is debatable. Programming allows you to be creative without any boundries, like drawing. You can create your own world with your own rules.

My Projects

Fractals

If you spend some time on YouTube and are interested in Math like me, you might have come across some of these Mandelbrot zoom videos. If not, well it doesn't really matter. I find them very beautiful, and since their formulas are extremely simple, I decided to give it go.

For both the Mandelbrot and Julia Sets the formula to compute these Factals is z = z² + c. Pretty simple, right?
You basically run this function over and over again, and if it reaches infinity (or in code, some arbitrary high value) you conclude that it does not belong to the fractal. If it does not go to infinity, and stays in a "orbit", then it belongs to the fractal (usually colored black).

I made a simple JavaScript implementation of it, but since you have to rerun this formula hundreds of times per pixel, it was very slow. That is because normal JavaScript (and most programming languages) utilize the CPU. And the CPU is really slow when it comes to calculations, that can be done in parallel. So, in order to get this to work in frames per second, not seconds per frame I had to turn to OpenGL, or the browser version WebGL. WebGL is a bit complicated and very annoying to work with, but it's farely simple code, so it worked out.

Even though the Mandelbrot Set and the Julia Sets use the same formula, the values entered are a bit different.
For the Mandelbrot Set, z is initially set to 0 + 0i, while c is a value on the complex plane, usually the pixel coordinate. When you open the page, you will be able to zoom and navigate the mandelbrot set as you'd expect.

For the Julia Sets, z is initially set to the pixel coordinate while c is an arbitrary complex number.
If you were wondering, that is why I'm speaking of the Julia Sets in plural, since there are infinitely many of them.
This is the reason the navigation is different. If you click on a point on the screen, you will see the corresponding Julia Set for that point. c will be set to that value. You are still able to zoom in and out, but as of now panning is not possible.

Congrats if you actually read this all, but now you are definitely ready to try it out. Below are links to the Mandelbrot and Julia Sets. For the Julia Sets I included some POI's that I found while developing it. In a Chromium-based browser, you should be able to right click => download the image, in case you want to save it.

Universe2D
A 2D Space Physics Simulation in your Browser

This is the most difficult project I've ever done.

I first started with programming gravity and collisions separately, to combine them at the end. After that I made the spawning system. The first big problem came with friction, if planets are inside each other. Currently I am using the Formula for air friction with obviously different values as for air. I know it isn't really perfect, but it worked the best out of different formulas I tried.

It was almost finished for over a month, and the big problem I had was the conservation of momentum. Sounds easy, but its not easy to get working when mass is transfered between objects. After having no idea how to get it working I did an complete recode of the physics engine, which indeed fixed some bugs. Sadly not all, and the conservation of momentum was still often violated.

After abandoning the project for almost a month I tried again and recoded the way mass transfer worked. I still ran into issues, but it fixed a few things. I restructured a few functions and changed a some other things on the way, until I finally got it working.

As always some things aren't exactly accurate, but at least the fundamental laws of physics are followed. Therefore, you can now try it here on my Website.

Solar System Generation

I first got the idea from a Coding Challenge from The Coding Train and decided to work on it. I used his code as a starting point and continued from there. After I had finished the generator, I recreated our Solar system in the same fashion. However, this took way longer than expected, since copying hundreds of values one by one from Wikipedia isn't too fast. Anyways, if you want to see it in action, here it is.

Lossy Text Compression

That was my first idea when started learning Python. I knew it was actually useless since text is very small on its own and there are much better lossless algorithms, but programming is fun and I wanted to learn Python. I took me really long to get it working and to make it actually compress. My first idea didn't work out so I came up with a completely different approach. So I wanted to log the change in characters, instead of the characters directly. Then I save the change to a binary file with a limited bitrate to reduce size. And by the way, its not good.

An Example:

Original: (1,25kb)

From Wikipedia: Baobab Tree

Baobabs reach heights of 5 to 30 meters and have trunk diameters of 7 to 11 meters. The Glencoe baobab, a specimen of A. digitata in Limpopo Province, South Africa, was considered to be the largest living individual, with a maximum circumference of 47m and a diameter of about 15.9 meters. The tree has since split into two parts, so the widest individual trunk may now be that of the Sunland baobab, or Platland tree, also in South Africa. The diameter of this tree at ground level is 9.3 meters and its circumference at breast height is 34 meters. [...]

Compressed: (0,96kb, 24% compression)

From wikipedia: Baobab tree

Baobabs reach heights of 5 to 30 meters and have trunk diameters of 7 to 11 meters. The glencoe baobab, a specimen of a. Digitata in limpopo province, south africa, was considered to be the largest living individual, with a maximum circumference of 47m and a diameter of about 15.9 Meters. The tree has since split into two parts, so the widest individual trunk may now be that of the sunland baobab, or platland tree, also in south africa. The diameter of this tree at ground level is 9.3 Meters and its circumference at breast height is 34 meters. [...]

Compressed: (0,8kb, 36% compression)

From pikipediag baobab tree

Baobabs reach heights of f to f0 meters and have trunk diameters of f to f1 metersvwthe glencoe baobab, a specimen of a. Digitata in limpopo province, south africa, fas considered to be the largest living individualo fith a maximum circumference of f7 and a diameter of about f5.9 Meters f the tree has since split into two parts, so the fidest individual trunk may now be that of the sunland baobab, or platland tree, also in south africa. The diameter of this tree at ground level is f.3 Meters and its circumference at breast height is f4 metersvr [...]