Recursion 2018
Pages: 1 2
Vince M Hudd (116) 398 posts 
Hmm… I’m sure I must have seen that at some point, but if I have I’ve forgotten. I’ll try to find some time to run it tomorrow to see it running for myself. However, I think even reducing PROCpoly would still result in something unwieldy, given that I want to put it on a four page A5 pamphlet, with accompanying text! :)
It might be too big for my little pamphlet, but it might be worth having it on one of the MUG machines as part of the code club idea of Doug’s, with some print outs of the program, and giving people a little challenge along those lines. 
Vince M Hudd (116) 398 posts 
No, that wasn’t just you. :) But that does remind me – just after the last Recursion, I discussed with Richard Ashbury that it would have been a nice idea to have some of his modified Jan Vibe programs running as a rolling demo on a spare machine if there was room to set one up. Something else to consider for this time around. (Though my one table didn’t really leave much room for that.) 
Doug Webb (190) 351 posts 
Already captured and yes we could have printouts on the stand and perhaps even stretch to a Pi Zero with RISC OS included as a prize. I’ll discuss this with the MUG team. 
mikko (3145) 72 posts 
How about 23 lines of BBC BASIC that render the Mandelbrot set? (Well, to be more accurate, lots of points that aren’t in the Mandelborot set, colour coded by their degree of separation from it.) This displays nicely in the centre of my 1920×1080 monitor via my Pi3 in about a minute but I’m no expert on MODE so I’m not sure if it’ll translate well to other environments. Even if it’s no use for Recursion 2018, I found it an educational way to explore my new BBC BASIC manual, so thanks for the excuse! MODE "X1280 Y1024 C256" width% = 2000 : height% = 1200 : max% = 32 : row% = 0 WHILE row% < height% col% = 0 WHILE col% < width% c_re = (col%  width%/2.0)*4.0/width% c_im = (row%  height%/2.0)*4.0/width% x = 0 : y = 0 iterations% = 0 WHILE x*x + y*y <= 4 AND iterations% < max% x_new = x*x  y*y + c_re y = 2*x*y + c_im x = x_new iterations% += 1 ENDWHILE IF iterations% < max% THEN GCOL iterations% * 4 POINT 300+col%,450+row% ENDIF col% += 1 ENDWHILE row% += 1 ENDWHILE EDIT: I should be clear that I just hacked one of the many implementations of this; I’m no mathematician! Specifically this one: Let’s draw the Mandelbrot set EDIT: For my own education, I’d like to know a) How to plot the points faster in BASIC. b) How to centralise the image without the clunky offset. (VDU command?) Any pointers / observations would be appreciated by me. 
Jeffrey Lee (213) 5025 posts 
There are a few easy optimisations you could make:
Slightly more complex optimisations would be to avoid calling GCOL or POINT for every pixel. E.g. only use GCOL when the number of iterations changes, and use LINE to render horizontal strips instead of individual pixels. Or you can have a go at rewriting it to use array arithmetic (I have an arraybased Mandlebrot renderer which I wrote as a performance test for BASICVFP)
Yes, you can change the graphics window origin using VDU 29 
mikko (3145) 72 posts 
Excellent. A range of optimisations I can get my baby BASIC teeth into. Thanks, Jeffrey! 
Steve Drain (222) 968 posts 
If you are doing the whole M set, which is symmetrical, you can double up by plotting the top and bottom at the same time. There are also other calculations to move to outside loops. However, the main user of time is the floating point complex number calculation. Back in the early days of the Archimedes there was some competition to write the fasted M set plotter, both in BASIC and machine code. This generated many ‘tricks’ such as Jeffrey is suggesting.
Perhaps you are following in the steps of Sophie Wilson. ;) During the development of ARM BASIC there was a keyword In 2010, after the death of Benoit Mandelbrot, I wrote a
Or, indeed, 
Steve Pampling (1551) 3917 posts 
If this is to be a demo to young /novice programmers then would it not be a good idea to show the difference between nonoptimal code and a set of optimising changes? 
mikko (3145) 72 posts 
All progress is achieved by making mistakes so hopefully my fumbling attempts with this program could serve as a guide. I don’t want to hijack this thread but I will post a slightly optimised version of the above later. (Array arithmetic I’ll take away for a closer look…) 
Steve Drain (222) 968 posts 
I have had a look, and it is not in v1.73, but it was in v1.29, appearing after 
mikko (3145) 72 posts 
I still think that seeing some simple BASIC render the Mandelbrot set can be an inspiring experience for kids so now that my code is less of a crime against efficiency, I’ll requote it: MODE "X1280 Y1024 C256" ORIGIN 300,450 width% = 2000 : height% = 1200 : max% = 32 half_width% = width%/2 : half_height% = height%/2 last_iterations% = 0 FOR row% = 0 TO height% STEP 2 FOR col% = 0 TO width% STEP 2 c_re = (col%  half_width%)*4.0 / width% c_im = (row%  half_height%)*4.0 / width% x = 0 : y = 0 iterations% = 0 WHILE x*x + y*y <= 4 AND iterations% < max% x_new = x*x  y*y + c_re y = 2*x*y + c_im x = x_new iterations% += 1 ENDWHILE IF iterations% < max% THEN IF iterations% <> last_iterations% THEN GCOL iterations%*4 last_iterations% = iterations% ENDIF POINT col%,row% ENDIF NEXT NEXT The massive saving was on compensatibg for the Eigen factor. 
andym (447) 287 posts 
I’ve been watching this thread with interest! As a programmer of just about the “Hello World” variety, I’m tempted to come to Recursion with a couple of Pi setups and some worksheets (like the above) for people to have a go on. Somewhere I have copies of the old Input magazine in digital format and could make worksheets from some of those listings for people to have a go at? A sort of “guess what it does” kind of thing. I also have access to a Robot Arm that can be used with RISC OS, if I can get hold of the software . 
Steve Drain (222) 968 posts 
It is just too tempting, sorry. ;)

Jeffrey Lee (213) 5025 posts 
Come on, Steve! x = c_re : y = c_im FOR iterations%=1 TO max% No point testing if 
mikko (3145) 72 posts 
No need to be sorry, I’m learning! I’ll try that out and I’m going to use this as an excuse to go on to learn some other skills and make it interactive… (err, off this thread.) 
Steve Drain (222) 968 posts 
Ah, yes, that is how I do it here, but you can have just too much cake at one time. ;) My next offering would be to chop off the right hand side of the plot with:
Then there is the representation of complex numbers by matrices. ;) 
John Williams (567) 549 posts 
Put time%=TIME near the start and PRINT TIMEtime% at the end and you’ll know how many centiseconds it took! Currently 2242 here, Jeffrey’s last mod saving 38cs, an improvement of 1.67%! 
mikko (3145) 72 posts 
Thanks everyone. Yes, I’m aware of TIME and had been using that to measure improvements. Matrices is my next step, so no spoilers on that front, please. :) 
Doug Webb (190) 351 posts 
andym, MUG would love to have you attend Recursion with us and why not bring along your robot arm as well. In the meantime thanks to everyone who has contributed to this thread and for the examples. 
Pages: 1 2
Reply
To post replies, please first log in.