Visions of Chaos is now compatible with High DPI displays

High DPI

Mobile phones and tablets have had nice high DPI displays for a long time now. PC screens have started to catch up and 4K monitors are starting to come down in price and will become the standard in the future.

The good thing about higher DPI screens is that there are many more pixels on the same sized screen so text and images are shown much more clearly.

The bad thing is most applications (especially older programs) are not aware of High DPI scaling settings. If an application does not support scaling Windows just “zooms” the application window to a larger size. This leads to blurry text that most people complain about. So you either set the scaling factor to 100% which leads to tiny text or you live with blurry text.

Over the past few weeks I have been working on making Visions of Chaos high DPI aware. The end result is that it will now run happily on all scale settings and higher 4K monitors without the text being too tiny to read or blown up and blurry. The menus and all text within Visions of Chaos will scale according to your Windows settings and remain smooth and crisp to read.

High DPI in Visions of Chaos

Prior to Visions of Chaos being DPI aware Windows would just scale the output window like in a photo editor app. The following shows how the Visions of Chaos window looks at 150% scaling under Windows 10 on a 4K display.

Non DPI aware Visions of Chaos image

This leads to the blurred text and the generated image (set to 480×360 pixels in size) is shown onscreen also stretched and blurred to 725 pixels wide.

Here is the same window using the latest version of Visions of Chaos that is DPI aware. The text fonts are scaled to a larger size so they remain crisp and smooth. The fractal image that has been set to 480×360 pixels is exactly 480×360 monitor pixels.

DPI aware Visions of Chaos image

Windows is still playing catch up with higher resolution DPI support, but it will hopefully get better as 4K monitors become the standard. At least you can be confident that Visions of Chaos will continue to be usable and readable at high DPI settings.

Now I can get back to adding new features to Visions of Chaos.

Jason.

ADDLED

ADDLED logo

ADDLED is a new and unique puzzle game for Android devices that I have been working on for the past few months. After much testing and preparation I am finally ready to release it to the public.

ADDLED game grid

The aim is to find a set of numbers that add up to a total value. Initially the levels are simple with just sums using positive numbers, but later levels give larger grid sizes and negatives, multiplication and division.

As the difficulty increases there are more strategies to implement to get through levels.

The levels are quick enough to fill in a few minutes when you have some spare time.

If you think this is your sort of puzzle game, download ADDLED through the Google Play Store.

Jason.

3D Gravity using OpenCL

NOTE: This post is currently WRONG. I am not correctly comparing every particle to every other particle in the gravity calculations. So, consider the listed results and speeds as incorrect. I will update this post once I get a correct working model going.

OpenCL allows you to write programs that run on your video card processor chip (GPU). GPUs can have many hundreds of cores so can process many more things simultaneously than a CPU can. A good candidate for parallel processing is a gravity simulation.

Previous Results

Since I originally posted the following 3D gravity movies to YouTube…

…there were questions and some skepticism in the comments so hopefully this blog post helps clarify things.

Coding Information

It has been a while since I was working with the gravity code, but this should be enough info for those interested.

This is the OpenCL kernel code that does the calculation for every object each frame. I had to screen capture it as WordPress kept deleting lines no matter what tags I used.

OpenCL Gravity Kernel

The kernel uses the standard Newtonian gravitation formulas. No other fancy calculations are included. So no energy conservation, no collision detection, no objects clustering into planets, no dark matter, no dissipation, no energy conservation, no overall angular momentum constraint, no speed-of-light limit on propagation of gravity taken into account and no inertia of mass. Basically it is the simplest possible formulas that give gravity like results.

The pos, vel, acc and mass are float arrays that hold the position, velocity, acceleration and mass for all the objects. Every frame those arrays are filled and passed to OpenCL using clCreateBuffer and clSetKernelArg. Once the above kernel code processes the objects the values are read back from the GPU using clEnqueueReadBuffer and then OpenGL (GL not CL) is used to display the objects to the screen using transparent billboard quads. Display is currently done in software OpenGL which is why the OpenGL display time is slower than the OpenCL calculations time.

The mingravdist check makes the calculations ignore objects that are too close together. If you allow objects very close together to interact they end up flinging objects out of the simulation space at a very high speed. For a world size of 300 units I use a mingravdist of 1.

Latest Results

Here is a new movie I just rendered with 3,000,000 particles. The frames took 4,700 ms to render on a GeForce GTX 570. Out of that time 844 ms was the OpenCL calculations. The rest of the time was rendering and passing the data back and forth to and from the GPU.

Unfortunately YouTube’s compression ruined the movie quality a bit. Mostly due to the noisy/static like nature of the millions of particles. Not enough I frames and too many P frames. Here are a series of screenshots showing what the frames looked like before the compression.

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

To push it further, here is a rotating disk of 5,000,000 objects. This one took 6,950 ms per frame with 1,420 ms for OpenCL calculations.

Again, here are some uncompressed screenshots.

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

3D Gravity Simulation

The GTX 570 is on the lower end of the GeForce cards these days so the simulation speeds should be faster on the newer cards.

GTX 570

10,000,000 objects was also possible, but until I work out better ways of display it is not worth posting as most of the detail gets lost in the cloud of billboard particles. 10,000,000 was taking 8,780 ms per frame with 2,840 ms OpenCL time.

Try It Yourself

If use Windows you can download Visions of Chaos and see the simulations run yourself. Here are a few quick steps to get you going;

1. Open Visions of Chaos
2. Select Mode->Gravity->3D Gravity to change into the 3D Gravity mode
3. The 3D Gravity Settings dialog will appear
4. Change the number of objects to 1,000,000
5. Change the Time step to 0.02
6. Change the Size of objects to 0.2
7. Check Create AVI frames if you want to create an AVI movie from the simulation
8. Click OK

Make sure you have the latest video card drivers so the OpenCL code runs as optimal as possible. For NVidia go here and for AMD go here.

Jason.

Using Multiphase Smoothed-Particle Hydrodynamics to show the emergence of Rayleigh-Taylor instability patterns

Rayleigh-Taylor Instability

Rayleigh-Taylor instability (RT) occurs when a less dense fluid is forced into a heavier fluid. If a heavier fluid is resting on a lighter fluid then gravity pulls the heavier down through the lighter fluid resulting in fingering, mushrooming and swirling patterns.

Nicole Sharp from FYFD has this into video to RT.

Simulating Rayleigh-Taylor Instability

Here is an exmaple image courtesy of Wikipedia showing some steps from simulating RT.

Rayleigh-Taylor Instability

This is a much more complex example from a supercomputer run at the Laboratory for Computational Science and Engineering, University of Minnesota. Also check out their movie gallery for more incredible fluid simulation examples.

Rayleigh-Taylor Instability

RT patterns also emerge in supernova simulations like the following two images.

Rayleigh-Taylor Instability

Rayleigh-Taylor Instability

Mark J Stock uses his own fluid simulation code to create incredibly detailed RT examples like this

thunabrain has this example of using the GPU to simulate fluids showing RT

Real Life Rayleigh-Taylor Instabilities

Pouring milk into coffee leads to RT patterns. I took these with my phone so they are not as crisp as I would have liked.

Milk and coffee

Milk and coffee

Dropping ink into water also leads to RT patterns as in these photos by Alberto Seveso

Rayleigh-Taylor Instability

Rayleigh-Taylor Instability

Using SPH to simulate RT

I had some previous success with implementing Multiphase Smoothed-Particle Hydrodynamics so I was curious to see what sorts of RT like results the SPH code could create. I have now added the options to generate RT setups in the SPH mode of Visions of Chaos.

The following SPH RT simulations use approximately 500,000 discreet individual particles to make up the fluids. They are all full HD 1080p 1920×1080 60fps videos. It was very tedious to try various settings and wait for them to render. I spent the last few weeks tweaking code and (99.99% of that time) rendering test movies to see the changes before I was happy with the following three example movies.

The code is single threaded CPU only at this stage, so much patience was required for these movies.

For this first example the top half of the screen was filled with heavier purple particles and the lower half with lighter yellow particles. A very small random movement was added to each of the particles (just enough to stop a perfect grid of particles) and then the simulation was started. 73 hours (!!) later the calculations were completed for the 3000 frames making up the movie.

The next example took around 105 hours for the 4000 frames. This time three fluids are used. Heaviest on top, medium in the middle and lightest on the bottom.

And a final three fluid example that took 74 hours for the 3000 frames.

If you click the title text of the movies they will open in a new tab allowing them to be viewed in full screen HD resolution.

Jason.

Visions Of Chaos for Android updated

Visions Of Chaos for Android

It took a lot longer than I wanted, but the new Visions Of Chaos for Android v1.0 is now available for download. It is 100% free and ad free.

Visions Of Chaos for Android

The main new feature is support for running OpenGL ES shaders on your Android device. There are over 1000 sample shaders included with the app.

Visions Of Chaos for Android

Visions Of Chaos for Android

So, if you own one of the 85% market share Android devices download the app from the Visions Of Chaos for Android web page or directly from Google Play now.

Jason.

Pendulum Plots

This is a quick post showing an alternative way to display the result of plotting double, triple and quadruple pendulums.

Based on my previous magnetic pendulum simulation and plots I had the idea to try a similar plot style for the double, triple and quadruple pendulums.

If you simulate a pendulum attached to another pendulum in zero gravity without any friction you get a system that runs continuously and creates a plot like the following gif animation.

Double Pendulum Simulation

With 3 pendulums the plot is more complex.

Triple Pendulum Simulation

With 4 it is even more complex.

Quadruple Pendulum Simulation

Another way to visualize this is to plot a 2D image with the X axis being 0 to 360 degrees of the first pendulum and the Y axis being 0 to 360 degrees of the second pendulum. The simulations are run for 5000 steps at each pixel location. Depending on which quadrant of the screen the pendulum is in after the 5000 steps determines the color of the pixel (red, green, blue or yellow). The top left pixel sets the pendulum angles to both 0, runs the simulation for 5000 steps and because the end of the two pendulums is located in the lower left quarter of the screen the pixel is colored green. This process is then repeated for the remaining pixels of the image.

Here is the result for the double pendulum

Double Pendulum

and the triple

Triple Pendulum

and the quadruple

Quadruple Pendulum

The original code was taking 12 minutes for a 320×240 image using the simplest double pendulum code. I am patient, but not that patient. A quick recode into GLSL and the GPU took over the number crunching and now it is rendering 640×480 results in under 2 seconds.

Here is a gif animation of the double pendulum plot with the number of simulation iterations increasing each frame.

Double Pendulum Plot Animation

If you are interested in seeing the GLSL shader source code click here.

The above plotting and shader code is now included with Visions Of Chaos if you just want to experiment without having to do any coding.

Jason.

Coupled Cellular Automata

Origins

Back in 2007 I was trying to figure out the algorithms behind Jonathan McCabe’s cellular automata pictures. I was never able to determine the algorithm to get the same results and coloring as Jonathan, but this is an explanation of my own Coupled Cellular Automata that arose from trying.

Algorithms

The principal of this method is to have 3 CAs with different settings running mostly independently of each other, but have their values interact with each other to create a new interesting result.

Coupled Cellular Automata settings

To start with you need 3 arrays to keep track of the 3 separate CAs. I used a 3D array to store them, ie c[0,x,y] c[1,x,y] and c[2,x,y].

Each cell is updated using a kernel which is very similar to an image processing kernel. For example, this kernel

Coupled Cellular Automata kernel

is like a weighted blur image processing kernel.

Initialise a value to 0. The current cell value is multiplied by 4 and added to the total. The north, south, east and west neighbour cell values are mutlipled by 2 and added to the total. The corner cell values are mutliplied by 1 and added to the total.

Depending on which of the 3 CA layers is being processed, the value is updated by

case level of
0:value:=value div k1total-(c[2,x,y] mod k1mod+1);
1:value:=value div k2total-(c[0,x,y] mod k2mod+1);
2:value:=value div k3total-(c[1,x,y] mod k3mod+1);
end;

k1total, k2total and k3total are the total of all the kernel values. For the above kernel the total value is 16 (4+2+2+2+2+1+1+1+1).

k1mod, k2mod and k3mod are the 3 “Mod value” settings that can be customised.

The value is also modified by using the cell value in another layer. This gets the CAs feeding through each other and causes the multiple layered look of the CA.

Once you have the new value for the cell, it is then kept within the range of 0 to 255 by the Wrap Method. The 3 wrap methods (Mod, Inverse and Clamp) make the following changes to the value

case wrapmethod of
0:value:=value mod 255;
1:if value > 255 then value:=-255 else if value < -255 then value:=255;
2:if value > 255 then value:=255 else if value < -255 then value:=-255;
end;

At this stage you now have a new value for the cell. Put this cell into a temp array and then swap the temp array into the cell array once all cells are processed (like any other CA you want to update all the cells simultaneously).

Repeat the above steps as long as you need to.

Display Methods

You now have the 3 CA layers updated with their new values. I use 3 different methods to display the CA.

1. Color Palette. Index a 256 color palette with abs(c[0,x,y]+c[1,x,y]+c[2,x,y] div 3) mod 255;

2. RGB. Convert the layer values to a color by using RGB(abs(c[0,x,y]),abs(c[1,x,y]),abs(c[2,x,y]));

3. YUV. Pass the layer values as YUV into a YUV to RGB converter routine YUVtoRGB(abs(c[0,x,y]),abs(c[1,x,y])-128,abs(c[2,x,y]-128),r1,g1,b1);

Results

Here are some more example kernels and the resulting images. The settings dialog screen captures also show off the new skinning theme support that Visions Of Chaos now includes.

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Coupled Cellular Automaton

Of course like any CA these need to be seen dynamically changing and updating. To see the above samples and others in motion download Visions Of Chaos.

If you are a coder who experiments with the above algorithms and has any other ideas or enhancements let me know.

Jason.