Title: Sinclair BASIC Mandelbrot smooth colouring Post by: simon.snake on October 13, 2016, 06:45:46 PM Hi.
I am on a facebook group called BASIC Programming on the ZX Spectrum. For fun, I wrote a program to generate images of the Mandelbrot. The program is pretty slow (but the programming environment can speed it up substantially) and it was never written to be highly optimised. Due to a limitation on the original ZX Spectrum hardware, only two colours are allowed in every 8x8 character on the screen. Rather than try to add colouring and suffering from the aforementioned attribute clash, I have implemented two colouring methods: The first is simple plain monochrome alternating iteration bands. The second is white, checkerboard black/white, black and finally checkerboard white/black. It then cycles around these 4. Here are a couple of samples (of the same location) but with the different colouring options: EDIT: Sorry, I didn't know facebook image links expire after a certain time, so the link has been removed! Now, I'd like to experiment with smooth colouring. It will still use only two colours - in this case white and black (or any 2 of the 8 primary colours of the machine), but I'd like to be able to plot only some of the pixels in order to get some sort of dithering. In my mind I am looking for a value between 0 and 1, which when compared with a pseudo-random value from the machines RNG will be used to decide whether to plot the point or not, and that way I will achieve some sort of gradient. I've read up on it, and the closest I've got to something at my level of understanding is the following site: linas.org/art-gallery/escape/smooth.html (http://linas.org/art-gallery/escape/smooth.html) but the problem I have is knowing when to perform the code. Is it calculated every iteration or only at the end? I'm not very familiar with the notation used (I only ever got to GCSE C grade and didn't progress it further). ZX BASIC has a natural log function (LN) and I'm hoping this is what is required. In my code I have separate variables for the real and imaginary values of z, etc. so how do I convert what is being described on the site I have linked to (which looks more like FractInt formula parser code) into Sinclair BASIC? I don't know if it helps but I'm happy sharing the code I have written. It's in a format that is used by a programming environment for Windows called BasinC: Code: 10 REM Hires Mandelbrot In the code {vi} and z{vn} are directives that specify normal or inverse video (and can safely be ignored). The code between lines 180 and 340 is performing the maths for each point. Simon Title: Re: Sinclair BASIC Mandelbrot smooth colouring Post by: quaz0r on October 13, 2016, 07:19:32 PM it's just a calculation you do with the last value of Z after youve escaped, to compute a fractional value to add to your iteration count, which is what allows you to create the smooth coloring. i guess the main notation in the formula on that site is |Z|, which means the magnitude of Z, which is
Quote In my mind I am looking for a value between 0 and 1 so, this part is the fractional value between 0 and 1 then: 1 - (log (log |Z|) / log 2) with the formula usually stated as that plus N, or the iteration you escaped at. Title: Re: Sinclair BASIC Mandelbrot smooth colouring Post by: simon.snake on October 13, 2016, 10:43:06 PM 1 - (log (log |Z|) / log 2) with the formula usually stated as that plus N, or the iteration you escaped at. Ok, I think I get this. I entered what I believe to be the right code and it started to generate a screen, but then threw an error. It would appear that on the ZX Spectrum the number passed to LN (natural log) has to be positive. If I use instead 1-(log(abs(log(abs(|z|)))) / log 2) is it equivalent? I'll give it a go anyway as I've got nothing to lose. I will report back with any useful images I get. Title: Re: Sinclair BASIC Mandelbrot smooth colouring Post by: quaz0r on October 13, 2016, 11:14:33 PM taking the magnitude of a complex number always results in a positive value, as you are squaring the real and imaginary components and adding them together. if log|Z| is resulting in a negative, maybe your bailout isnt high enough ? personally i use the smoothing formula posted in this thread (http://www.fractalforums.com/index.php?topic=3499.msg77140#msg77140). its a little more complicated and im not sure what the difference between the different formulas are, in fact there are several smoothing formulas out there i think..
Title: Re: Sinclair BASIC Mandelbrot smooth colouring Post by: simon.snake on October 14, 2016, 02:04:31 AM I think the issue with LN is that it was producing a negative value. Not sure if it is meant to but the ABS have at least allowed it to run.
Here's the location in the original post but with the smoothing applied: EDIT: Sorry, I didn't know facebook image links expire after a certain time, so the link has been removed! And the initial starting location of the Mandelbrot (as a side effect of my code I now have shading for the inside colouring too): EDIT: Sorry, I didn't know facebook image links expire after a certain time, so the link has been removed! It's not as smooth as I was hoping, but that's either due to the low resolution, limitations within the floating point routines within Sinclair BASIC or maybe something else that can be resolved. For comparison, here is the start image (that the smooth one is based on) with the usual black/white stripes: EDIT: Sorry, I didn't know facebook image links expire after a certain time, so the link has been removed! And here's a zoom into the spike: EDIT: Sorry, I didn't know facebook image links expire after a certain time, so the link has been removed! As you can see, it's not that smooth really. One last thing, here's my updated code (it has become a bit of a mess but I'll attempt to tidy it up once it works): Code: 10 REM {vi}Hires Mandelbrot{vn}Title: Re: Sinclair BASIC Mandelbrot smooth colouring Post by: quaz0r on October 14, 2016, 07:31:46 AM i think the smoothing works better with a higher bailout, so maybe see if >100000 or something looks better than >4 ? though i dont know how buttery smooth dithered monotone is really going to get :D
what would probably work best for you actually is to use the distance estimate. iterate the derivative of Z alongside (but before) Z: Z0 = 0 Z'0 = 0 Z'n+1 = 2Zn'Zn + 1 Zn+1 = Zn2 + C then when you escape the distance estimate is Title: Re: Sinclair BASIC Mandelbrot smooth colouring Post by: DarkBeam on October 14, 2016, 08:49:36 AM Home computers still kick ... Great :beer:
Title: Re: Sinclair BASIC Mandelbrot smooth colouring Post by: simon.snake on October 14, 2016, 05:40:08 PM i think the smoothing works better with a higher bailout, so maybe see if >100000 or something looks better than >4 ? though i dont know how buttery smooth dithered monotone is really going to get :D Yes, I do agree. I tried to increase the bailout but that didn't look any better. I think my issue is the sharp turn from white to black at the edge of some of the iteration bands. What's strange is the other side looks fine. Once I implement my zoom out code I'll get a better view of the whole of the first iteration band - it may offer clues. The first image is with a bailout of 3, the second is with a bailout of 16. A bailout of 100 or even 1000 just gives me back a black/white striped image with no dithering. EDIT: Sorry, I didn't know facebook image links expire after a certain time, so the link has been removed! Am I supposed to be changing anything in the equation with all the LNs when I change the bailout? Title: Re: Sinclair BASIC Mandelbrot smooth colouring Post by: hermann on October 14, 2016, 10:40:29 PM A Sinclair ZX81 was my first computer! At a time I was still in University. About the mid of the eighties.
Hermann Title: Re: Sinclair BASIC Mandelbrot smooth colouring Post by: simon.snake on October 15, 2016, 12:28:41 AM Researching further, I'm getting errors because the output of the LN command on the ZX Spectrum is returning negative values. Whether it is meant to or not is something I have no idea about.
Subsequently, the LN function on the ZX Spectrum does not allow one to use a negative value. This is (from what I've read on the subject) the usual case for LN. Now I am at a loss on what to do. Whatever tweaks I make just don't seem to make the images look better than those I have already posted. I'm not going to give up though. It's keeping my grey matter active. Title: Re: Sinclair BASIC Mandelbrot smooth colouring Post by: quaz0r on October 15, 2016, 10:35:57 AM if you look at the graph (https://upload.wikimedia.org/wikipedia/commons/e/ea/Log.svg) you can see the range of inputs and outputs to the log function.
i think if you use a higher bailout you probably need to use the extended formula i linked to earlier which calculates the log(p) part instead of using log(2) or whatever. also i still think you might want to check out distance estimation since you are working with a b&w system anyway :) you can get nice b&w renders of the boundary like this (http://www.fractalforums.com/index.php?action=gallery;sa=view;id=19363) Title: Re: Sinclair BASIC Mandelbrot smooth colouring Post by: simon.snake on October 15, 2016, 05:11:20 PM I'm pretty happy with it now. The following code: smooth iter = iter + 1 + ( log(log(bailout)-log(log(cabs(z))) )/log(2) Was mentioned as a smoothing method for use in ultrafractal in the following site: https://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/MandelbrotSetExterior (https://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/MandelbrotSetExterior) So I tweaked my code to include this additional log(log(bailout)) (even with its missing closing bracket) and the following image was calculated: EDIT: Sorry, I didn't know facebook image links expire after a certain time, so the link has been removed! That's exactly how I envisioned the end result looking. |