Tricky pattern

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

Tricky pattern

Post by Richard Russell »

This was a tricky pattern to draw, because of the 'holes' and the way they are intertwined. I ended up doing it with several *GSAVEs and *DISPLAYs, which works - and is quite fast because the 'files' are cached in RAM - but isn't particularly elegant My attempts to do it using standard drawing commands (whether native BBC BASIC or in the gfxlib or imglib libraries) haven't been successful. I wonder if somebody else can do better.

Code: Select all

      VDU 23,22,720;720;8,16,16,0
      DIM x(3),y(3) : r = PI/5 : ORIGIN 720,720 : COLOUR 14,128,192,255
      x() = COS(r)-SIN(r),-SIN(r)-COS(r),-COS(r)+SIN(r),SIN(r)+COS(r)
      y() = SIN(r)+COS(r),COS(r)-SIN(r),-SIN(r)-COS(r),-COS(r)+SIN(r)
      x() *= 480 : y() *= 480 : GCOL 14
      MOVE x(0),y(0) : MOVE x(1),y(1) : PLOT 117,x(2),y(2) : GCOL 8
      DRAW x(3),y(3) : DRAW x(0),y(0) : DRAW x(1),y(1) : DRAW x(2),y(2)
      x() *= 0.5 : y() *= 0.5 : GCOL 0
      CIRCLE FILL x(0),y(0),180 : CIRCLE FILL x(1),y(1),180
      CIRCLE FILL x(2),y(2),180 : CIRCLE FILL x(3),y(3),180 : GCOL 8
      CIRCLE x(0),y(0),180 : CIRCLE x(1),y(1),180
      CIRCLE x(2),y(2),180 : CIRCLE x(3),y(3),180
      OSCLI "GSAVE """ + @tmp$ + "twisted"" -500,-500,998,998"
      GCOL 15 : RECTANGLE FILL -480,-480,960,960 : GCOL 0
      CIRCLE FILL -240,-240,180 : CIRCLE FILL -240,+240,180
      CIRCLE FILL +240,-240,180 : CIRCLE FILL +240,+240,180
      GCOL 8 : RECTANGLE -480,-480,960,960
      CIRCLE -240,-240,180 : CIRCLE -240,+240,180
      CIRCLE +240,-240,180 : CIRCLE +240,+240,180
      OSCLI "GSAVE """ + @tmp$ + "bridge1"" -280,280,240,240"
      OSCLI "GSAVE """ + @tmp$ + "bridge2""  300,40,240,240"
      OSCLI "GSAVE """ + @tmp$ + "bridge3""  0,-500,240,240"
      OSCLI "GSAVE """ + @tmp$ + "bridge4"" -500,-280,240,240"
      OSCLI "DISPLAY """ + @tmp$ + "twisted"" -500,-500,998,998,1000000"
      OSCLI "DISPLAY """ + @tmp$ + "bridge1"" -280,280,240,240,1000000"
      OSCLI "DISPLAY """ + @tmp$ + "bridge2""  300,40,240,240,1000000"
      OSCLI "DISPLAY """ + @tmp$ + "bridge3""  0,-500,240,240,1000000"
      OSCLI "DISPLAY """ + @tmp$ + "bridge4"" -500,-280,240,240,1000000"
intertwined.png
You do not have the required permissions to view the files attached to this post.