Stars on a sphere

Here's another example of a (nearly) generic BBC BASIC program, it displays 500 'stars' randomly distributed over the surface of a rotating sphere. The cursor up and cursor down keys move the 'camera' closer to (even inside) or further from the sphere, respectively,

The program will run without modification in BBC BASIC for Windows, BBC BASIC for SDL 2.0 and Matrix Brandy. To run in ARM BASIC 5 the *REFRESH OFF and *REFRESH commands must be deleted, and WAIT 1 changed to WAIT; it will also need a *FX 4,1 added for the cursor keys to work.
   10 MODE 8
   20 ORIGIN 640,512
   30 GCOL 15
   40 OFF
   50
   60 NSTARS = 500
   70 Radius = 300
   80 Scale  = 1000
   90 Camera = 1000
  100
  110 DIM s(2, NSTARS-1), q(2, NSTARS-1)
  120 DIM a(2,2), b(2,2), c(2,2), r(2,2)
  130
  140 FOR I% = 0 TO NSTARS-1
  150   lon = 2 * PI * RND(1)
  160   lat = ASN(2 * RND(1) - 1)
  170   s(0, I%) = Radius * COS(lon) * COS(lat) : REM x
  180   s(2, I%) = Radius * SIN(lon) * COS(lat) : REM z
  190   s(1, I%) = Radius * SIN(lat)            : REM y
  200 NEXT
  210
  220 *REFRESH OFF
  230 REPEAT
  240   CASE INKEY(0) OF
  250     WHEN 138,142: Camera += 20
  260     WHEN 139,143: Camera -= 20
  270   ENDCASE
  280
  290   a = 0        : REM pitch
  300   b = TIME/500 : REM yaw
  310   c = 0        : REM roll
  320
  330   a() = 1, 0, 0, 0, COS(a), -SIN(a), 0, SIN(a), COS(a)
  340   b() = COS(b), 0, SIN(b), 0, 1, 0, -SIN(b), 0, COS(b)
  350   c() = COS(c), -SIN(c), 0, SIN(c), COS(c), 0, 0, 0, 1
  360   r() = b() . a()
  370   r() = c() . r()
  380   q() = r() . s()
  390
  400   CLS
  410   FOR I%=0 TO NSTARS-1
  420     z = (Camera - q(2,I%)) / Scale
  430     IF z>0 THEN
  440       X% = q(0,I%) / z
  450       Y% = q(1,I%) / z
  460       LINE X%,Y%,X%,Y%
  470     ENDIF
  480   NEXT
  490   *REFRESH
  500   WAIT 1
  510 UNTIL FALSE

Comments

  • Soruk
    edited October 2023
    Here's a patch to make it work on ARM BBC BASIC without breaking the existing setup.
        5 A%=FALSE: IF (INKEY(-256) AND &F0)=&A0 THEN A%=TRUE: *FX4,1
      220 IF NOT A% THEN *REFRESH OFF
      490   IF NOT A% THEN *REFRESH
      500   IF A% THEN WAIT ELSE WAIT 1
    
  • Soruk wrote: »
    Here's a patch to make it work on ARM BBC BASIC without breaking the existing setup.
    The context, which I didn't copy over from the Discussion Group where it originated, was that somebody asked ChatGPT to "write a BB4W program to display stars on a sphere".

    Not surprisingly its attempt was pathetic (largely gibberish) and this program was my suggestion of what a sufficiently competent AI might generate - although when that will be achieved is anybody's guess.

    So I quite deliberately didn't include anything that an AI couldn't be expected to write, including code to support multiple platforms (especially as the prompt explicitly mentioned BB4W).

    Although ChatGPT's attempt was awful, when one considers that it was never intended to understand BBC BASIC code (let alone write it from scratch), the fact that it made an attempt at all is quite fascinating.

    It also exhibited a characteristic of ChatGPT, which is to have a surprisingly rich 'imagination'! It 'invented' SYS calls to a BB4W library that (as far as I know) doesn't exist, and decided that VDU 5 is something to do with display synchronisation!
  • The way ChatGPT gets things wrong is in itself quite entertaining, and quite conducive to getting a bruised forehead from the number of times your head hits your desk!
  • Soruk wrote: »
    The way ChatGPT gets things wrong is in itself quite entertaining
    Entertaining, I suppose, but also thought provoking. I've tried using Google to find the possible source of the training data that leads ChatGPT to create the code it does, and generally not found any. For example take this line of code:
    vdu 5 ; Synchronize with the display refresh rate
    
    Leaving to one side that ChatGPT thinks BBC BASIC uses a semicolon as a comment delimiter (many BASICs do) why might it link VDU 5 with display refresh? I've tried searching for something that could be a source, but without success.

    It seems to me that ChatGPT is far more than an engine for regurgitating training data, as some people like to claim. There's 'something else' going on, call it 'emergent behaviour' or whatever, but I find it very interesting.

    I'll go back to watching the sights of Charlottetown, Prince Edward Island, from our cruise ship balcony now!
  • Enjoy your trip! Seems like your internet access this time round is rather better than last time.
  • Soruk wrote: »
    Enjoy your trip! Seems like your internet access this time round is rather better than last time.
    It is. This time their Starlink connection is working (I expect the constellation is larger too), last time it was broken and we were back on the old, slow Inmarsat connectivity.

    The constantly-changing IP address resulting from the Starlink network has however caused a few problems with overly-zealous security checks, which consider this to be suspicious.