BBC BASIC for Windows
« Rotating ice crystals »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:18pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Rotating ice crystals  (Read 377 times)
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Rotating ice crystals
« Thread started on: Oct 26th, 2016, 09:52am »

Code:
      *ESC OFF
      *FLOAT 64
      MODE 8 : OFF
      ORIGIN @vdu%!208, @vdu%!212

      ON ERROR OSCLI "REFRESH ON":ON:CLS:PRINT'" ";:REPORT:PRINT" at line ";ERL:VDU7:END

      MinRadials% = 3
      MaxRadials% = 15
      QuadsPerRadial% = 10
      MaxPts% = 4 * QuadsPerRadial% * MaxRadials%
      DIM p(MaxPts%-1,2), q(MaxPts%-1,2), m(2,2)
      DIM col{(QuadsPerRadial%-1) r%, g%, b%}

      rho% = 700 : REM added to all rotated Z co-ordinates

      REM Time-dependent scale function parameters:
      MaxScale% = 1000
      t1% = 50  : REM object reaches full scale at time = t1%
      t2% = 750 : REM object remains at full scale while t1% <= time < t2%
      t3% = 800 : REM scale diminished to zero when t2% <= time < t3%
      c = MaxScale% - (MaxScale%/(t3%-t2%))*t2%

      newObj% = TRUE : REM Create a new object when this flag is TRUE

      *REFRESH OFF

      R% = RND(-TIME)

      time0% = TIME

      REPEAT
  
        CLS
  
        IF newObj% THEN
          numPts% = FNBuildNewObject
          newObj% = FALSE
        ENDIF
  
        T% = TIME
  
        dt% = T% - time0%
  
        REM A time-dependent compound function to control the scale of the object:
        IF dt% < t1% THEN scale = (MaxScale%/t1%)*dt%
        IF dt% >= t1% AND dt% < t2% THEN scale = MaxScale%
        IF dt% >= t2% AND dt% < t3% THEN scale = MaxScale% - (dt%-t2%)*MaxScale%/(t3%-t2%)
        IF dt% >= t3% THEN
          time0% = T%
          scale = 0
          newObj% = TRUE
        ENDIF
  
        REM Define time-dependent rotation angles:
        A = T%/122
        B = T%/176
        C = T%/100
        D = 2*PI*SIN(T%/520)
        E = 3*PI*COS(T%/720)
        sA = SIN(A)
        cA = COS(A)
        sB = SIN(B)
        cB = COS(B)
        sC = SIN(C)
        cC = COS(C)
  
        REM Rotate all of the object's points:
        m() = (cB*cC), -cB*sC, sB,  cA*sC+sA*sB*cC, cA*cC-sA*sB*sC, -sA*cB, sA*sC-cA*sB*cC, sA*cC+cA*sB*sC, cA*cB
        q() = p().m()
  
        REM Render all the polygons (quads) in the current object:
        colIndex% = 0
        n% = 0
        FOR I% = 0 TO numPts%-1 STEP 4
          IF n% = 0 THEN
            COLOUR 7, col{(colIndex%)}.r%, col{(colIndex%)}.g%, col{(colIndex%)}.b%
          ENDIF
          z0 = scale / (rho%+q(I%,2))
          z1 = scale / (rho%+q(I%+1,2))
          z2 = scale / (rho%+q(I%+2,2))
          z3 = scale / (rho%+q(I%+3,2))
          MOVE z0*q(I%,0), z0*q(I%,1)
          MOVE z1*q(I%+1,0), z1*q(I%+1,1)
          PLOT 85, z2*q(I%+2,0), z2*q(I%+2,1)
          PLOT 85, z3*q(I%+3,0), z3*q(I%+3,1)
          n% += 1
          IF n% = NumRadials% THEN
            colIndex% += 1
            n% = 0
          ENDIF
        NEXT
  
        *REFRESH
        WAIT 1
  
      UNTIL FALSE
      END

      DEF FNBuildNewObject
      LOCAL I%, J%, K%
      LOCAL r1, r2, r3, a, da, x1, y1, x2, y2, x3, y3, x4, y4
      NumRadials% = MinRadials% + RND(MaxRadials% - MinRadials% )
      FOR I% = 0 TO QuadsPerRadial%-1
        col{( I% )}.r% = 150 + RND(105)
        col{( I% )}.g% = col{(I%)}.r% + 1 - RND(10)
        col{( I% )}.b% = 220 + RND(35)
      NEXT I%
      FOR J% = 1 TO QuadsPerRadial%
        r1 = 256 * RND(1)
        r2 = r1 + 30 + 50*RND(1)
        r3 = r2 + 40 + 100*RND(1)
        da = 3 + 12*RND(1)
        FOR I% = 0 TO NumRadials%-1
          a = I% * (360/NumRadials%)
          x1 = r1*SINRAD(a)
          y1 = r1*COSRAD(a)
          x2 = r2*SINRAD(a-da)
          y2 = r2*COSRAD(a-da)
          x3 = r2*SINRAD(a+da)
          y3 = r2*COSRAD(a+da)
          x4 = r3*SINRAD(a)
          y4 = r3*COSRAD(a)
          p(K%,0) = x1
          p(K%,1) = y1
          p(K%+1,0) = x2
          p(K%+1,1) = y2
          p(K%+2,0) = x3
          p(K%+2,1) = y3
          p(K%+3,0) = x4
          p(K%+3,1) = y4
          K% += 4
        NEXT I%
      NEXT J%
      = K%
 
User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: Rotating ice crystals
« Reply #1 on: Oct 26th, 2016, 2:14pm »

You have amazing programming skill.. Hey.... how about a driving through a world sim? (maybe a racetrack?)
User IP Logged

I like making program generators and like reinventing the wheel
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Rotating ice crystals
« Reply #2 on: Oct 26th, 2016, 5:38pm »

Here's some pretty old 3D stuff (from several years ago), all made with BB4W. The trouble is, I seem to have lost the source code for most of them. sad Most BB4W users will have already seen these, I think.


3D Tour Demo (This takes you on a tour of a small 3D world; after 3 or 4 minutes, you take off and fly around in the sky):

https://drive.google.com/open?id=0B3j5sIQi9SskWGJVUjBPXzBCRWc


3D Maze (a.k.a. 'Viewer_2') - use the Arrow keys, and hold down the 'Ctrl' key to move faster:

https://drive.google.com/open?id=0B3j5sIQi9SskMjRBWlZsZjN5UDg


3D Maze Demo II (Use the arrow keys to explore the maze)

https://drive.google.com/open?id=0B3j5sIQi9SskdWNJNVhnVDk0T0k


Crystaloids Demo (This was meant to become a full game - it's just a demo; use the arrow keys and press 'Z' to fire):

https://drive.google.com/open?id=0B3j5sIQi9SskSU1tLTR3dnRERFE


Xmas Demo II (Includes a rotating 3D snowman):

https://drive.google.com/open?id=0B3j5sIQi9SskV2dUbFBuVTNrNjQ


Just a colourful, fuzzy pseudo-3D tunnel:

https://drive.google.com/open?id=0B3j5sIQi9SskbW91aWtpRlM5N1U



David.
--

User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Rotating ice crystals
« Reply #3 on: Nov 7th, 2016, 7:13pm »

Here is a modified version of the 'Ice Crystals' program (EXE only - sorry), in which a translucent 'ice crystal' is rendered over a wintry background image.

OneDrive: https://1drv.ms/u/s!Asv5H0sZTvQ-jQJNUPJDbyXkn6Eq

Google Drive: https://drive.google.com/open?id=0B3j5sIQi9SskQ1ctbENBTms1R1E

Because it's an EXE file from an 'untrusted' source (i.e. me), Windows might prevent you from running it. You may have to tell Windows that you trust the file. I did scan it for viruses/malware using F-Secure AV, with no problems detected.


David.
--
User IP Logged

KenDown
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 181
xx Re: Rotating ice crystals
« Reply #4 on: Nov 11th, 2016, 04:59am »

That's what Elite should have been - descend to the planet and "mine" it for resources by collecting the crystals before going into hyperspace and heading for the next planet!

A pity you've lost the source code for that 3D World.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls