Parametric flower

Discussions related to graphics (2D and 3D), animation and games programming
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Parametric flower

Post by Richard Russell »

Found on the web, a nice example of parametric curves.

Code: Select all

   10 VDU 23,22,640;640;8,8,16,128
   20 ORIGIN 640,640
   30 GCOL 1
   40 FOR t = -8 TO +8 STEP 0.0001
   50   x = SIN(9.52 * t) + 1
   60   y = COS(9.52 * t) ^ 4 * SIN(SIN(4.8 * t))
   70   PLOT 320*x,320*y : PLOT -320*x,320*y
   80   PLOT 320*y,320*x : PLOT 320*y,-320*x
   90 NEXT
flower.png
You do not have the required permissions to view the files attached to this post.
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: Parametric flower

Post by Richard Russell »

Somebody has pointed out elsewhere that it's very slow in BBC BASIC for Windows. This is because plotting individual pixels using the VDU-stream-based graphics is inefficient: for example it involves sending 6 bytes to the VDU stream for each pixel, which then have to be decoded (the same was true on the BBC Micro, incidentally).

If you want it to run in BB4W at a speed comparable with how it runs in BBCSDL you must abandon the native graphics and instead write directly to an in-memory bitmap:

Code: Select all

   10 VDU 23,22,640;640;8,8,16,128
   20 DIM BMP{bfType{l&,h&}, bfSize%, bfReserved%, bfOffBits%, \
   30 \       biSize%, biWidth%, biHeight%, biPlanes{l&,h&}, biBitCount{l&,h&}, \
   40 \       biCompression%, biSizeImage%, biXPelsPerMeter%, biYPelsPerMeter%, \
   50 \       biClrUsed%, biClrImportant%, palette%(255), p&(639, 639)}
   60
   70 BMP.bfType.l& = ASC"B"
   80 BMP.bfType.h& = ASC"M"
   90 BMP.bfSize% = DIM(BMP{})
  100 BMP.bfOffBits% = ^BMP.p&(0,0) - BMP{}
  110 BMP.biSize% = 40
  120 BMP.biWidth% = 640
  130 BMP.biHeight% = 640
  140 BMP.biPlanes.l& = 1
  150 BMP.biBitCount.l& = 8
  160 BMP.palette%(0) = &FFFFFFFF
  170 BMP.palette%(1) = &FFC00000
  180
  190 FOR t = -8 TO +8 STEP 0.0001
  200   x = SIN(9.52 * t) + 1
  210   y = COS(9.52 * t) ^ 4 * SIN(SIN(4.8 * t))
  220   BMP.p&(320+160*x,320+160*y) = 1 : BMP.p&(320-160*x,320-160*y) = 1
  230   BMP.p&(320+160*y,320+160*x) = 1 : BMP.p&(320-160*y,320-160*x) = 1
  240 NEXT
  250 *HEX 64
  260 OSCLI "MDISPLAY " + STR$~BMP{}
This could no doubt be optimised further .