Refactor 2022 #10
Anyway, I imagine that someday I will find a way to use these, with much reduced contrast, as background, and then put something to serve as a focal point in the foreground.
Refactor 2022 #8
There is a lot of room between those two extremes, here are I few I feel are close to the middle.
Refactor 2022 #7
Nature abounds with good examples. I am not trying to reproduce nature per se, but rather the abstraction of an interplay between random and not random.
Refactor 2022 #6
The images could be a polished marble surface. I enjoy looking at the shapes and grain in stone and wood and similar surfaces. The patterns on a similar faux surface hold my interest only until I see where they repeat, then disappointment, as I can never not see the repetition again.
Refactor 2022 #5
So, what about these pictures?
I used simple things like lines to test my anti-alias code changes. When that was looking good I wanted a more complex example like a fractal. A fractal with a lot of details takes a while to generate, so I decided to look for something simpler and quicker. This is the result.
If you put the previous image side by side with this one you will see the difference that anti-aliasing makes. This one uses a simple average on four point on grid within a pixel. In sub-pixel coordinated, the sample points are (0.25, 0.25), (0.25,0.75), (0.75,0.25) and (0.75, 0.75).
Refactor 2022 #4
(Anti-Aliasing continued) In the line example it is possible to calculate the percentage of the pixel covered by the line. Then one can do anti-aliasing as described in the previous post. Squares and lines are simple things. The percentage calculation is not possible in general.
Generative art, such as fractals, but also anything more complex than simple geometric objects, also suffer from the equivalent of jagged lines. It is no longer a question of "in or out". That single pixel may contain many colors. Choosing just one of the colors generates noisy (sparkly) images. So in this case one samples several points within the pixel area and averages the results.
A very long time ago I set up an anti-alias method by sampling nine points on a 3x3 grid inside the pixel and then taking the simple average of the colors. That was the first thing that I tried, it worked well enough so I did not try anything else. I carried that code forward from program to program over the years.
There are other ways to the job. A 4x4 grid may give better results. A 2x2 grid would take less than half the time. Five points, four corners and the center may be good enough. Arguments could be made for a weighted average rather than a simple average. Also a good case can be made to use random points rather than points on a gird.
As part of this refactor journey I decided to add these options to my anti-alias code. I can then tweak the parameters and choose the best tradeoff between speed and noticeable quality improvement.
Refactor 2022 #3
All of the images in this blog, until recently, use a process called anti-aliasing. See https://en.wikipedia.org/wiki/Supersampling
If, for example, you want to draw a line on the computer screen, you could calculate which pixels are on the line and light them up. This almost works. We naturally think of a pixel as a zero-dimensional point, and the line as one dimensional. But a line needs some width, or it would be invisible, and a single pixel covers some small area of the display. A typical monitor has about 100 dpi, so a pixel is actually a 0.01 inch x 0.01 inch square. The pixels are very small, but if you build a diagonal line out of these square pixels, you will still see the corners of the individual pixels. The line looks jagged.
These edge pixels are not entirely on or entirely off the line. The line covers some intermediate portion of the pixel. A better way to draw these pixels is to consider the partial coverage. If the line covers 30% of the pixel, then give the pixel a blend of 30% the line color and 70% the background color.
Refactor 2022 #2
As with porting, when refactoring, the changes need testing. Sometimes the test cases generate interesting pictures. Sometimes they motivate the artistic side and the test case becomes a jumping off point for new creations. I like to explore the inspiration when it happens. But the program, being in the middle of an overhaul, is in a less stable state than usual.
Here the goal is to use the rugged terrain algorithm from early posts to add texture to a simple fractal. The previous picture looks like painting on a coarse canvas, or perhaps a needle point. Today's picture is the same design, but with the texture dialed back some.
Refactor 2022 #1
New Series, Refactor 2022.
Refactoring is for programmers who reject the advice "If it ain't broke, don't fix it".
Refactoring is actually a good thing. A working program may also be very fragile. A fragile program is difficult to modify without breaking it. Computer programs naturally tend to the state "working, but just barely". Refactoring cleans up the program, organizes it, makes it easier to understand and modify.
Refactor 2022 is a continuation or the Port 22 series. The porting task was finished some time ago, but as long as I had the hood open I decided to tinker with a few things. As usual one thing leads to another and two months later I feel like I am further away from my goal than when I started.
Port 22 #10
Inspired by topographical maps.
While working on an algorithm to detect the intersection of two objects, some tests were needed. I put together test cases for various simple 2d and 3d objects such as lines, planes, spheres. For a more challenging test case, I created an bumpy terrain and tried to intersect it with a flat rectangle.
The test passed immediately, but I headed off on a tangent to create interesting, surreal landscapes. The results of that foray make up the next few posts.