BBC BASIC for Windows
« Bluey »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:54pm



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: Bluey  (Read 181 times)
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Bluey
« Thread started on: Dec 28th, 2017, 3:57pm »

Code:
      REM Bluey
      REM Works with BB4W & BBCSDL
      REM Relatively low CPU usage

      ON ERROR PROCerror

      WinW% = 360
      WinH% = 640
      VDU 23, 22, WinW%; WinH%; 8, 16, 16, 0 : OFF

      PRINT "Please wait..."

      REM Create a 256-colour (8 bits-per-pixel) bitmap to render graphics on:
      bmpSz% = 54 + 4*256 + WinW%*WinH% + 2
      DIM bmp% bmpSz%+6
      bmp% = ((bmp% + 3) AND -4) + 2
      bmp%?0 = ASC"B"
      bmp%?1 = ASC"M"
      bmp%!2 = bmpSz%
      bmp%!10 = 1078
      bmp%!14 = 40
      bmp%!18 = WinW%
      bmp%!22 = WinH%
      bmp%?26 = 1
      bmp%?28 = 8
      bmp%!34 = WinW%*WinH%

      bmp$ = STR$~bmp%

      REM Set up colour palette:
      FOR I% = 0 TO 255
        r& = 0.125 * I%
        g& = 0.25 * I%
        b% = 1.5 * I%
        IF b% > 255 b% = 255
        bmp%!(54 + 4*I%) = b% + (g&<<8) + (r&<<16)
      NEXT I%

      REM Generate pattern:
      A% = bmp% + 1078
      W% = WinW% - 1
      H% = WinH% - 1
      FOR Y% = 0 TO WinH%-1
        a = Y%/H%
        FOR X% = 0 TO WinW%-1
          b = X%/W%
          A%?(Y%*360+X%) = 255*(SIN(2*PI*a-5*PI*SQRb+3*PI*a^2) + COS(3*PI*b+9*PI*SQRa-2*PI*b^2))
        NEXT
      NEXT

      A% = bmp% + 54
      B% = A% + 1024

      REPEAT
        OSCLI "MDISPLAY " + bmp$
  
        T% = !A%
        FOR I% = A% TO B%-5 STEP 4
          !I% = !(I%+4)
        NEXT
        !(B%-4) = T%
  
        WAIT 1
      UNTIL FALSE
      END

      DEF PROCerror
      IF ERR=17 AND INKEY$(-256)<>"W" THEN CHAIN @lib$+"../examples/tools/touchide"
      OSCLI "REFRESH ON" : CLS : ON : SOUND 1, -15, 200, 3
      COLOUR 15, 255, 255, 255 : COLOUR 15
      PRINT '" " + REPORT$ + " at line " + STR$ERL
      COLOUR 15, 200, 200, 200
      PRINT ''" Closing in 3 seconds...";
      WAIT 300
      QUIT
      ENDPROC
 
User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: Bluey
« Reply #1 on: Dec 31st, 2017, 06:58am »

That is cool.
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: Bluey
« Reply #2 on: Dec 31st, 2017, 4:24pm »

on Dec 31st, 2017, 06:58am, michael wrote:
That is cool.


Here's a more sickly variation:

Code:
      REM Tutti Fruity
      REM Works with BB4W & BBCSDL
      REM Relatively low CPU usage

      ON ERROR PROCerror

      WinW% = 360
      WinH% = 640
      VDU 23, 22, WinW%; WinH%; 8, 16, 16, 0 : OFF

      PRINT "Please wait..."

      REM Create a 256-colour (8 bits-per-pixel) bitmap to render graphics on:
      bmpSz% = 54 + 4*256 + WinW%*WinH% + 2
      DIM bmp% bmpSz%+6
      bmp% = ((bmp% + 3) AND -4) + 2
      bmp%?0 = ASC"B"
      bmp%?1 = ASC"M"
      bmp%!2 = bmpSz%
      bmp%!10 = 1078
      bmp%!14 = 40
      bmp%!18 = WinW%
      bmp%!22 = WinH%
      bmp%?26 = 1
      bmp%?28 = 8
      bmp%!34 = WinW%*WinH%

      bmp$ = STR$~bmp%

      REM Set up colour palette:
      FOR I% = 0 TO 255
        k = PI*I%/255
        r& = 128 + 127*SIN(k)
        g& = 128 + 127*COS(2*k)
        b% = 128 + 127*SIN(4*k)
        IF b% > 255 b% = 255
        bmp%!(54 + 4*I%) = b% + (g&<<8) + (r&<<16)
      NEXT I%

      REM Generate pattern:
      A% = bmp% + 1078
      W% = WinW% - 1
      H% = WinH% - 1
      FOR Y% = 0 TO WinH%-1
        a = Y%/H%
        FOR X% = 0 TO WinW%-1
          b = X%/W%
          A%?(Y%*360+X%) = 255*(SIN(PI*a-3*PI*b+5*PI*a^3) + COS(2*PI*b+3*PI*a-4*PI*b^4))
        NEXT
      NEXT

      A% = bmp% + 54
      B% = A% + 1024

      REPEAT
  
        OSCLI "MDISPLAY " + bmp$
  
        T% = !A%
        FOR I% = A% TO B%-5 STEP 4
          !I% = !(I%+4)
        NEXT
        !(B%-4) = T%
  
        WAIT 1
  
      UNTIL FALSE
      END

      DEF PROCerror
      IF ERR=17 AND INKEY$(-256)<>"W" THEN CHAIN @lib$+"../examples/tools/touchide"
      OSCLI "REFRESH ON" : CLS : ON : SOUND 1, -15, 200, 3
      COLOUR 15, 255, 255, 255 : COLOUR 15
      PRINT '" " + REPORT$ + " at line " + STR$ERL
      COLOUR 15, 200, 200, 200
      PRINT ''" Closing in 3 seconds...";
      WAIT 300
      QUIT
      ENDPROC
 



I can't see an obvious way of making the colour-cycling 'frame-rate independent' so that it runs at the same speed across a wide range of devices.
« Last Edit: Dec 31st, 2017, 4:27pm by David Williams » 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