πŸš€
REMΔ€Δ˜Δ†Δž$Č*Δ’Δ‰!ΔƒΔ›-Δ•'ď
MODE1:VDU5
FORN=8TO247:FORM=0TO319
X=0:Y=-.1:Z=3:U=(M-159.5)/160:V=(N-127.5)/160:W=1/SQR(U*U+V*V+1):U=U*W:V=V*W:I=SGNU:G=1
E=X-I:F=Y-I:P=U*E+V*F-W*Z:D=P*P-E*E-F*F-Z*Z+1:IFD>0T=-P-SQRD:IFT>0X=X+T*U:Y=Y+T*V:Z=Z-T*W:E=X-I:F=Y-I:G=Z:P=2*(U*E+V*F-W*G):U=U-P*E:V=V-P*F:W=W+P*G:I=-I:GOTO50
IFV<0P=(Y+2)/V:V=-V*((INT(X-U*P)+INT(Z-W*P)AND1)/2+.3)+.2
GCOL0,3-(48*SQRV+?(PAGE+5+M MOD4+N MOD4*4)/3)DIV16
PLOT69,4*M,4*N:NEXT,
#bbcmicrobot
I ran @coprolite9000's program and got this.
Source: https://bbcmic.ro/?t=9ctpk #bbcbasic
Owlet BBC BASIC Editor

@bbcmicrobot
Raytracing core borrowed from other people - I just added some ordered dithering!

(Yes, I'm rummaging through my old Twitter archives. This was originally posted back in late 2021...)

@coprolite9000 @bbcmicrobot that's awesome. Do you have an explanation of the code? I can't get my head round it.

@tgent_fens @bbcmicrobot
It's pretty much impenetrable - someone else wrote the raytracer core a while back, and I have only a vague understanding of how it works.

Main FOR loops iterate through screen pixels, raytracer calculates an intensity (with recursion for reflections) from a sky gradient and a checkerboard floor. (There's no 'real' lighting.)

Dithering (my addition) - there's a lookup table stuffed in the REM statement at the beginning - used as a 4x4 grid of intensity thresholds?

@coprolite9000 @tgent_fens @bbcmicrobot I wanted to understand it, but GOTO 50 on line 50 drives me into infinite loop and I can't go past that line.
@coprolite9000 @tgent_fens @bbcmicrobot Unless... IF condition false jumps to the next line? I thought it's only for next :-separated statement, but that would explain it a bit.
@tocisz @coprolite9000 @tgent_fens @bbcmicrobot
I started to expand this out a wee bit to help understanding, and I changed the REM statement dithering stuff to something that doesn't depend on PAGE+5 magic at least (although inline assmebler's hardly better).
https://bbcmic.ro/#%7B%22v%22%3A1%2C%22program%22%3A%22DIM%20lookup%25%2016%5CnP%25%20%3D%20lookup%25%5Cn%5B%5CnEQUB%200%3A%20EQUB%2024%3A%20EQUB%206%3A%20EQUB30%5CnEQUB%2036%3A%20EQUB%2012%3A%20EQUB%2042%3A%20EQUB%2018%5CnEQUB%209%3A%20EQUB%2033%3A%20EQUB%203%3A%20EQUB%2027%5CnEQUB%2045%3A%20EQUB%2021%3A%20EQUB%2039%3A%20EQUB%2015%5Cn%5D%5CnMODE1%5CnVDU5%5CnFOR%20N%3D8%20TO%20247%3A%20REM%20Row%5CnFOR%20M%3D0%20TO%20319%3A%20REM%20Column%5CnX%3D0%5CnY%3D-.1%5CnZ%3D3%5CnU%3D%28M-159.5%29%2F160%3A%20REM%20-1%20to%201%20scaled%20position%20X%5CnV%3D%28N-127.5%29%2F160%3A%20REM%20-1%20to%201%20scaled%20position%20Y%5CnW%3D1%2FSQR%28U*U%2BV*V%2B1%29%3A%20REM%20Reciprocal%20distance%20from%20centre.%5CnU%3DU*W%3A%20REM%20Normalise%20U%20and%20V.%5CnV%3DV*W%5CnI%3DSGN%20U%3A%20REM%20Left%20or%20Right%20half%20of%20screen.%5CnG%3D1%5CnE%3DX-I%3A%20REM%20Walk%20towards%20the%20opposite%20edge.%5CnF%3DY-I%3A%20REM%20walk%20towards%20the%20top%2Fbottom.%5CnP%3DU*E%2BV*F-W*Z%5CnD%3DP*P-E*E-F*F-Z*Z%2B1%5CnIF%20D%3C%3D0%20THEN%20GOTO%20420%5CnT%3D-P-SQR%28D%29%5CnIF%20T%3C%3D0%20THEN%20GOTO%20420%5CnX%3DX%2BT*U%5CnY%3DY%2BT*V%5CnZ%3DZ-T*W%5CnE%3DX-I%5CnF%3DY-I%5CnG%3DZ%5CnP%3D2*%28U*E%2BV*F-W*G%29%5CnU%3DU-P*E%5CnV%3DV-P*F%5CnW%3DW%2BP*G%5CnI%3D-I%5CnGOTO%20230%5CnIF%20V%3E%3D0%20THEN%20GOTO%20450%5CnP%3D%28Y%2B2%29%2FV%5CnV%3D-V*%28%28INT%28X-U*P%29%2BINT%28Z-W*P%29AND1%29%2F2%2B.3%29%2B.2%5CnREM%20Select%20from%20dithering%20pattern%20lookup%20based%20on%20M%2CN%20position%20in%20the%5CnREM%20lookup%20array.%5CnGCOL%200%2C3-%2848*SQR%28V%29%2B%3F%28lookup%25%2BM%20MOD4%2BN%20MOD4*4%29%2F3%29%20DIV%2016%5CnPLOT%2069%2C4*M%2C4*N%5CnNEXT%20M%2CN%22%7D
Owlet BBC BASIC Editor

@james_a_craig @coprolite9000 @tgent_fens @bbcmicrobot Nice. I haven't used basic in 30 years, but BBC Basic looks interesting! The basic in the Russian ZX Spectrum clone that I used wasn't so sophisticated.

@tocisz @james_a_craig @coprolite9000 @tgent_fens @bbcmicrobot

Sinclair BASIC was not bad, and with the Beta BASIC toolkit on top, I found it a pleasure to use. I wrote the original Wikipedia article:

https://en.wikipedia.org/wiki/Beta_BASIC

But BBC BASIC was _the_ best 8-bit version of the language, IMHO.

Beta BASIC - Wikipedia

@lproven @tocisz @james_a_craig @coprolite9000 @bbcmicrobot fun fact: I live in the same village as the guy who developed Sinclair Basic. Massive house, he clearly made a mint at some point, but not from any money Clive Sinclair gave him!
Retro spotlight: John Grant and Sinclair BASIC

At over five million units sold, the ZX Spectrum was England's most successful 8-bit computer. While Sir Clive Sinclair gets most of the credit, it wouldn't have happened without John Grant his company Nine Tiles.

@james_a_craig @tocisz @coprolite9000 @tgent_fens @bbcmicrobot seeing the lookup table in yours...you can see the numbers are a permutation of 0-15, multiplied by 3. Which the code then divides by 3 again. You can get a permutation like that by multiples of a number relatively prime to 16, mod 16. So you can get similar results with no lookup: https://bbcmic.ro/?t=9dnN2 (cos all you're trying to do is make sure each of the 16 threshold values appears in a 4x4 block, shuffled to make it less blocky)
Owlet BBC BASIC Editor

@james_a_craig @tocisz @coprolite9000 @tgent_fens @bbcmicrobot another way of getting a similar dither is to use a Kronecker sequence (fractional part of nΞ± for irrational Ξ±) https://bbcmic.ro/?t=9do1B https://en.wikipedia.org/wiki/Low-discrepancy_sequence#Additive_recurrence
Owlet BBC BASIC Editor

@bazzargh @james_a_craig @tocisz @tgent_fens @bbcmicrobot
These are great! Some nicely unfamiliar but good-looking dither patterns, from less code?

* Bookmarks *

@coprolite9000 @james_a_craig @tocisz @tgent_fens @bbcmicrobot I think like everyone else I learned a lot of dithering ideas from https://surma.dev/things/ditherpunk/ but realised there's a gap in those techniques between random sampling and bayer for low powered machines. I'm sure all this was common knowledge in the 80s. So I kept digging. https://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/ is good reading on the irrational number sequences
Ditherpunk β€” The article I wish I had about monochrome image dithering β€” surma.dev

I always loved the visual aesthetic of dithering but never knew how it’s done. So I did some research. This article may contain traces of nostalgia and none of Lena.

@james_a_craig @tocisz @tgent_fens @bbcmicrobot
Nice!

I've been having a go at dissecting the program myself - including that impenetrable raytracing core. I'm *starting* to understand it now, although there's some oddities with signs (particularly with the Z axis) and ordering of operations that I'm slowly rearranging into something saner...

https://bbcmic.ro/#%7B%22v%22%3A1%2C%22program%22%3A%22REM%C4%80%C4%98%C4%86%C4%9E%24%C4%8C*%C4%92%C4%89!%C4%83%C4%9B-%C4%95'%C4%8F%5CnREM%20ordered%20dither%20pattern%20stored%20in%20REM%20statement%20above%3B%204x4%20grid%20of%20thresholds%5CnMODE1%3AREM%20set%20320x256%2C%204%20colour%20graphics%20mode%5CnVDU5%3AREM%20hide%20flashing%20text%20cursor%20by%20enabling%20draw-text-at-graphics-cursor%20mode%5CnX%3D0%3AY%3D-.1%3AZ%3D3%3AREM%20camera%20position%5CnFOR%20N%3D8%20TO%20247%3AREM%20iterate%20over%20screen%20pixel%20rows%5CnFOR%20M%3D0%20TO%20319%3AREM%20iterate%20over%20screen%20pixel%20columns%5CnU%3D%28M-159.5%29%2F160%3AREM%20x%20component%20of%20ray%20vector%5CnV%3D%28N-127.5%29%2F160%3AREM%20y%20component%20of%20ray%20vector%5CnW%3D1%2FSQR%28U*U%2BV*V%2B1%29%3AREM%20z%20component%20of%20ray%20vector%5CnU%3DU*W%3AV%3DV*W%3AREM%20normalise%20x%20and%20y%20components%5CnI%3DSGNU%3AREM%20is%20ray%20facing%20left%20or%20right%3F%20I%20becomes%20x%20and%20y%20coordinates%20for%20sphere%5CnC%3DFNray%28X%2CY%2CZ%2CU%2CV%2CW%2CI%29%3AREM%20fire%20ray%20from%20X%2CY%2CZ%20along%20U%2CV%2CW%5CnGCOL0%2C3-%2848*SQRC%2B%3F%28PAGE%2B5%2BM%20MOD4%2BN%20MOD4*4%29%2F3%29DIV16%3AREM%20set%20draw%20colour%20using%20ordered%20dithering%5CnPLOT69%2C4*M%2C4*N%3AREM%20plot%20pixel%20%284x%20multiplier%20due%20to%20resolution-independent%20graphics%20coordinates%20-%201280x1024%29%5CnNEXT%5CnNEXT%5Cn%5CnDEFFNray%28X%2CY%2CZ%2CU%2CV%2CW%2CI%29%5CnE%3DX-I%3AF%3DY-I%3AG%3DZ%3AREM%20vector%20from%20sphere%20centre%20to%20ray%20start%5CnP%3DU*E%2BV*F-W*G%3AREM%20dot%20product%3F%20Z%20seems%20to%20be%20flipped%5CnD%3DP*P-E*E-F*F-G*G%2B1%5CnIF%20D%3C%3D0%20%3DFNc%28X%2CY%2CZ%2CU%2CV%2CW%29%3AREM%20didn't%20hit%20anything%3B%20return%20colour%5CnT%3D-P-SQRD%3AIF%20T%3C%3D0%20%3DFNc%28X%2CY%2CZ%2CU%2CV%2CW%29%3AREM%20still%20didn't%20hit%20anything%3B%20return%20colour%20%20%20%20%5CnX%3DX%2BT*U%3AY%3DY%2BT*V%3AZ%3DZ-T*W%3AREM%20new%20ray%20start%20position%5CnE%3DX-I%3AF%3DY-I%3AG%3DZ%3AREM%20vector%20from%20sphere%20centre%20to%20new%20ray%20start%5CnP%3D2*%28U*E%2BV*F-W*G%29%3AREM%20dot%20product%20shenanigans%3F%5CnU%3DU-P*E%3AV%3DV-P*F%3AW%3DW%2BP*G%3AREM%20new%20ray%20direction%20vector%5CnI%3D-I%3AREM%20we'd%20hit%20one%20sphere%2C%20so%20flip%20x%20and%20y%20coordinates%20to%20give%20other%5Cn%5Cn%3DFNray%28X%2CY%2CZ%2CU%2CV%2CW%2CI%29%3AREM%20return%20colour%20from%20new%20ray%5Cn%5CnDEFFNc%28X%2CY%2CZ%2CU%2CV%2CW%29%3AREM%20generate%20pixel%20colour%5CnIF%20V%3E%3D0%20%3DV%3AREM%20facing%20up%20at%20all%3F%20return%20ray%20Y%20component%20for%20simple%20sky%20gradient%5CnP%3D%28Y%2B2%29%2FV%3AREM%20use%20height%20for%20overall%20checkerboard%20scale%20and%20y%20component%20of%20vector%20for%20perspective%5Cn%3D-V*%28%28INT%28X-U*P%29%2BINT%28Z-W*P%29AND1%29%2F2%2B.3%29%2B.2%3AREM%20multiply%20simple%20gradient%20by%20checkerboard%5Cn%22%7D

Owlet BBC BASIC Editor

@coprolite9000 @james_a_craig @tocisz @tgent_fens @bbcmicrobot please stop nerd sniping me, or I’ll end up writing a fixed point math assembly version to see if I can make it faster. πŸ˜€

@coprolite9000 @bbcmicrobot ... huh ... when I saw a bit of code that produced this output, it was the winner of an Obfuscated PostScript competition back in ... the early 90s. likewise impenetrable, but I managed to futz with it to produce A4 renderings which were pretty cool ...
(edited to address dates and provide better link)

https://graphics.stanford.edu/pub/Graphics/RTNews/html/rtnv6n2.html#art11

Ray Tracing News, Volume 6, Number 2

@coprolite9000 @bbcmicrobot ... and my memory is fuzzy, because the image is similar, but not the same

@mherbert @bbcmicrobot
Mirrored spheres on checkerboard floors are *such* a trope of raytracing!

BBC BASIC thing above was an *incredibly* tight fit for the Twitter version of the bot. Mastodon's got a little more space to work with - now I'm wondering if I can upgrade it to something similar to the Postscript version you've shown. Hmmm....

@bbcmicrobot @coprolite9000 Ray tracing on an 8-bit computer, released 42 years ago, with a script short enough to fit in a Toot!
@arx @bbcmicrobot
It would take literally *hours* to run on original hardware - made implausibly faster by modern tech!
@coprolite9000 @bbcmicrobot Yeah, like the good old Mandelbrot set… wasn’t unheard of to let the computer run overnight.
@arx @bbcmicrobot
Speaking of which - I'll have to dig out some Mandelbrot stuff I wrote!

@coprolite9000 @arx @bbcmicrobot
Doubly impressive if you could raytrace a fractal in a toot.

This reminded me of the minimal raytracers written in C to fit on a business card
https://fabiensanglard.net/rayTracing_back_of_business_card/

Raytracing

@coprolite9000 @arx @bbcmicrobot How long do you think it would take on an Electron, and do you want me to try it and find out?
BBC Micro Bot - Data Cassette

@coprolite9000 @coregaze @bbcmicrobot Yeah, if programmed β€˜legally’ then it should. As for speed… it’ll prolly be a fair bit slower, sadly, due to slower RAM access by the CPU as it competes with the ULA.
@arx @coregaze @bbcmicrobot
Worst bit I can think of is the dither pattern data stuffed into the REM statement at the beginning - it's using 'PAGE+5' to get the base address of that, which sounds ... possibly portable?
@coprolite9000 @coregaze @bbcmicrobot Yes, I reckon so. The tokenisation will probably be the same as the Beeb’s and the OS will use the same PAGE method. I’d expect that bit to work without modification.

@arx @coprolite9000 @bbcmicrobot

The Electron runs (almost) the same BASIC as the BBC, and the ElkSD128 I've got here leaves PAGE at &E00 so there's no worries there. It looks like it's running...

@coprolite9000 @arx @bbcmicrobot Start the clock, it's running as of 14:45.

@coregaze @arx @bbcmicrobot
Oh, *brilliant*!

(You can do it, little Electron!)

@coprolite9000 @arx @bbcmicrobot Yep, definitely looks like it's working correctly

@coprolite9000 @arx @bbcmicrobot I just moved it over to AC power because this is going to take a while. So restart the clock at 15:00 on the dot...

This is running on an only slightly modified Issue 6 Electron. I made it USB type C powered for convenience, socketed the CPU and the gate array (it's a Synertek part, so not a ULA), swapped the CPU for a Synertek one that's in spec in the Electron (Rockwell ones aren't) and replaced a couple of the buffering logic chips that had died.

@coregaze @coprolite9000 @bbcmicrobot Such a cute little machine, the Electron. Nice how new games are still being made for it, too. There’s one called Electrobots by someone called 0xCODE which I think is great.

@arx @coprolite9000 @bbcmicrobot Yeah, think I've seen that (and also 0xC0DE, but I am not sure they made the jump away from Twitter when I did.)

45 minutes in and we have some progress.

@coprolite9000 @coregaze @arx I’m going to wager 5 hours on an Electron! I’m cheering it on πŸ˜ƒ
@bbcmicrobot @coprolite9000 @arx I'm guessing more like eight, given that it has so far done this much, and it's been going for an hour and twelve minutes.
@bbcmicrobot @coprolite9000 @arx Two hours, and it is apparent that the Electron's aspect ratio is slightly taller than the BBC's. I guess they don't want to keep the CPU halted longer than 40 Β΅s if they can avoid it...
@bbcmicrobot @coprolite9000 @arx Four hours and we're maybe halfway, or not quite halfway.

@coregaze @bbcmicrobot @arx
* Cheers on the little Electron *

(I wonder if it'll speed up a bit when it gets to the sky? The simpler gradient-only stuff might help a bit...)

@coprolite9000 @bbcmicrobot @arx It seems to be managing a little over a pixel per second, I think, so far...
@coprolite9000 @bbcmicrobot @arx the sky does indeed seem to be a little faster! Quite a bit, actually- maybe two or three times the speed. Five hours in and we're definitely past halfway!
@coregaze @bbcmicrobot @arx
Electron has achieved liftoff and is now soaring through the skies.

@coprolite9000 @bbcmicrobot @arx πŸš€ it is not.

But it's real.

My other Electron has a 2021 WDC 65C02S in it, it feels like that would be somehow less genuine; this Synertek part came from (another) Electron.

I don't know why I like the Electron so much. It makes me happy.

https://mstdn.social/@coregaze/109583561755712597

⚳ rapid unscheduled assembly ⚳ (@[email protected])

Attached: 1 image 1: I have done a thing. See, a while back when I was going through a pretty hard time (still am, tbh) my friend @erikarn gave me this Acorn Electron. This is one of the two most formative computers of my youth- the other being the Amstrad CPC (which @erikarn gave me a couple of years ago, dangit Adrian stop it). The problem was, though, that when I plugged an ElkSD128 into it, it... got very weird and unhappy. Like, biblically so. So I did this- but first I did some other stuff.

Mastodon 🐘