Live data from Hacker News

BBC BASIC raytracer in 432 characters

mastodon.me.uk

51–60 of 96 posts

Re: BBC BASIC raytracer in 432 characters

#52
post #42
post #27

Earlier quoted context omitted.

…to elucidate a bit, when tracing the rays on the left side of the image, the sign of u is -1, so we're trying to intersect a sphere at (x-1, y-1, z), and on the right side similarly one at (x+1, y+1, z). This works because none of the left-side rays can even in theory hit the right-side sphere and vice versa. It's a very simple version of space partitioning optimization. And when tracing the reflected rays, we flip…

these comments were extremely helpful, thank you

No problem, this was a fun puzzle to solve =D

Re: BBC BASIC raytracer in 432 characters

#53
post #35

Can anybody provide de-obfuscated/minified source so those of us who understand the principle (tracing rays of light around a scene) can understand the maths?

here's my attempt 10 REMĀĘĆĞ$Č*Ēĉ!ăě-ĕ'ď rem dithering table in comment above consulted by GCOL line? rem raytracer from https://bbcmic.ro/?t=9ctpk by https://mastodon.me.uk/@coprolite9000 rem deobfuscated and possibly broken by kragen javier sitaker (untested) 20 MODE 1 VDU 5 30 FOR N = 8 TO 247 : rem loop over rows (n) and columns (m) of pixels FOR M = 0 TO 319 40 X = 0 : rem three-dimensional vector Y = -.1 Z = 3…

> rem if instead y component is negative, make a checkerboard of pieces of sky

I'd maybe phrase this a bit differently – in both cases it uses the v coordinate to calculate the shade but whereas the sky is a simple gradient, the plane has a "ground fog" type effect that can be adjusted with those +.3 and +.2 magic constants.

Re: BBC BASIC raytracer in 432 characters

#54
post #38
post #26

https://www.pouet.net/prod.php?which=78045 Incredible raytraced demo in 256 bytes.

last year i wrote a tetris in arm assembly https://asciinema.org/a/622461 and was pleased to get it down below 1024 bytes then i looked and rrrola's 4is256 https://www.pouet.net/prod.php?which=29286 is a working tetris in under 256 bytes, and it's better than mine because it has colors and scoring. i could blame a little bit of inflation on arm being 32-bit rather than 16-bit, but not 4×

You could try using Thumb instructions, they are 16 bit.

Re: BBC BASIC raytracer in 432 characters

#55
post #4

In the replies underneath, someone ran it on a real Acorn Electron computer (6502 at 1 MHz), where it completed in 8 hours and 40 minutes. Not too bad really.

that's astounding; i would have guessed months or years

I recreated a mandlebrot zoom I saw in a library book in bbc basic and the last image took two weeks. I had 8 of them saved on a floppy and that would slideshow them for a 2fps "movie"

Re: BBC BASIC raytracer in 432 characters

#56
post #54
post #38

Earlier quoted context omitted.

last year i wrote a tetris in arm assembly https://asciinema.org/a/622461 and was pleased to get it down below 1024 bytes then i looked and rrrola's 4is256 https://www.pouet.net/prod.php?which=29286 is a working tetris in under 256 bytes, and it's better than mine because it has colors and scoring. i could blame a little bit of inflation on arm being 32-bit rather than 16-bit, but not 4×

You could try using Thumb instructions, they are 16 bit.

i was, but i wasn't talking about the size of the instruction word, but the size of the registers

Re: BBC BASIC raytracer in 432 characters

#57
post #53
post #35

Earlier quoted context omitted.

here's my attempt 10 REMĀĘĆĞ$Č*Ēĉ!ăě-ĕ'ď rem dithering table in comment above consulted by GCOL line? rem raytracer from https://bbcmic.ro/?t=9ctpk by https://mastodon.me.uk/@coprolite9000 rem deobfuscated and possibly broken by kragen javier sitaker (untested) 20 MODE 1 VDU 5 30 FOR N = 8 TO 247 : rem loop over rows (n) and columns (m) of pixels FOR M = 0 TO 319 40 X = 0 : rem three-dimensional vector Y = -.1 Z = 3…

> rem if instead y component is negative, make a checkerboard of pieces of sky I'd maybe phrase this a bit differently – in both cases it uses the v coordinate to calculate the shade but whereas the sky is a simple gradient, the plane has a "ground fog" type effect that can be adjusted with those +.3 and +.2 magic constants.

i was trying to figure out how the ground fog happens, and i still don't

Re: BBC BASIC raytracer in 432 characters

#58

Earlier quoted context omitted.

I'm running this on a BBC micro emulator running at period-accurate speed, and it's taking just under a minute to draw one line. So I think it's going to finish in about 4 hours, which would make sense - approximately twice as fast as the Acorn Electron.

Update: Finished in only 2 hours 30 minutes.

The Electron runs extra slowly in MODE 1 as the video system needs 100% of the RAM bandwidth to form the display. The CPU essentially ends up paused during the visible portion of each scan line, so the effective speed is probably more like 0.6 MHz.

Re: BBC BASIC raytracer in 432 characters

#59
In a subthread, I got nerdsniped to figure out how this works, and for fun transcribed it ~faithfully to Rust – this one just outputs ASCII art instead of plotting pixels. You'll want to zoom out your browser as far as you can:

https://www.rustexplorer.com/b#Zm4gbWFpbigpIHsKICAgIC8vIHJvd...

Re: BBC BASIC raytracer in 432 characters

#60
post #32

a thing that puzzles me is how https://bbcmic.ro/?t=9ctpk is only 4× faster in emulation (about 30 seconds per scan line and so on the order of 2 hours for the whole image) i'm running this on a ryzen 5 3500u at 2400 megahertz. the acorn electron which supposedly takes 8 hours and 40 minutes is a 1 megahertz 6502 when running from ram, roughly, 262144 instructions per second. at 2 ipc one core of the ryzen should be…

The rocket ship icon seems to have disappeared. Maybe I used it too much, or maybe the site owner removed it? (was it serverside and overloaded?)
Post reply on HN