Author Topic: MYOFS2  (Read 3419 times)

0 Members and 1 Guest are viewing this topic.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
MYOFS2
« on: December 15, 2020, 06:17:13 am »
Not to be confused with a neighboring post, this one is "Make your own Fibonacci Spiral".

It's not a spiral, by the way.

Code: QB64: [Select]
  1.  
  2. _TITLE "Fibonacci Spiral Explorer"
  3.  
  4. SCREEN _NEWIMAGE(800, 600, 32)
  5.  
  6. pi = 4 * ATN(1)
  7.  
  8. TYPE Vector
  9.     x AS DOUBLE
  10.     y AS DOUBLE
  11.  
  12. DIM SHARED CompassCart AS Vector
  13. DIM SHARED CompassTheta AS Vector
  14.  
  15. FOR p = 0 TO 1 - .002 STEP .002
  16.     zoom = 50 * (1.9 - .9 * p)
  17.     CALL DrawEverything
  18.     _DISPLAY
  19.     _LIMIT 60
  20.  
  21.  
  22.     IF (_KEYDOWN(18432) = -1) THEN ' Up-arrow
  23.         zoom = zoom * (1 + 0.01)
  24.     END IF
  25.     IF (_KEYDOWN(20480) = -1) THEN ' Down-arrow
  26.         zoom = zoom * (1 - 0.01)
  27.     END IF
  28.     IF (_KEYDOWN(19200) = -1) THEN ' Left-arrow
  29.         IF (p > 0) THEN p = p - .005
  30.         _DELAY .025
  31.     END IF
  32.     IF (_KEYDOWN(19712) = -1) THEN ' Right-arrow
  33.         p = p + .005
  34.         _DELAY .025
  35.     END IF
  36.     _KEYCLEAR
  37.  
  38.     CALL DrawEverything
  39.     LOCATE 1, 50: PRINT "Adjust Parameter and Zoom with arrow keys."
  40.  
  41.     _DISPLAY
  42.     _LIMIT 60
  43.  
  44.  
  45. SUB DrawEverything
  46.     DIM LastPoint AS Vector
  47.     DIM x1 AS DOUBLE
  48.     DIM y1 AS DOUBLE
  49.     DIM x2 AS DOUBLE
  50.     DIM y2 AS DOUBLE
  51.     DIM j AS INTEGER
  52.     DIM Step1 AS DOUBLE
  53.     DIM Step2 AS DOUBLE
  54.     DIM StepTemp AS DOUBLE
  55.  
  56.     CompassCart.x = 1
  57.     CompassCart.y = -1
  58.     CompassTheta.x = pi
  59.     CompassTheta.y = 3 * pi / 2
  60.     Step1 = 0
  61.     Step2 = 1
  62.  
  63.     LastPoint.x = 0
  64.     LastPoint.y = 0
  65.  
  66.     CLS
  67.     LOCATE 1, 1: PRINT "Parameter="; p
  68.     LOCATE 2, 1: PRINT "Zoom="; zoom
  69.     FOR j = 1 TO 10
  70.  
  71.         CALL StepCompass
  72.         StepTemp = Step2
  73.         Step2 = p * Step2 + Step1
  74.         Step1 = StepTemp
  75.  
  76.         x1 = LastPoint.x
  77.         y1 = LastPoint.y
  78.         x2 = x1 + SQR(2) * Step2 * CompassCart.x
  79.         y2 = y1 + SQR(2) * Step2 * CompassCart.y
  80.         CALL clineb(x1 * zoom, y1 * zoom, x2 * zoom, y2 * zoom, _RGBA(255, 255, 255, 155))
  81.  
  82.         IF (CompassCart.x = 1) AND (CompassCart.y = 1) THEN
  83.             CALL ccircle(x1 * zoom, y2 * zoom, SQR(2) * Step2 * zoom, _RGBA(255, 0, 255, 255), CompassTheta.x, CompassTheta.y)
  84.         END IF
  85.         IF (CompassCart.x = -1) AND (CompassCart.y = 1) THEN
  86.             CALL ccircle(x2 * zoom, y1 * zoom, SQR(2) * Step2 * zoom, _RGBA(255, 0, 255, 255), CompassTheta.x, CompassTheta.y)
  87.         END IF
  88.         IF (CompassCart.x = -1) AND (CompassCart.y = -1) THEN
  89.             CALL ccircle(x1 * zoom, y2 * zoom, SQR(2) * Step2 * zoom, _RGBA(255, 0, 255, 255), CompassTheta.x, CompassTheta.y)
  90.         END IF
  91.         IF (CompassCart.x = 1) AND (CompassCart.y = -1) THEN
  92.             CALL ccircle(x2 * zoom, y1 * zoom, SQR(2) * Step2 * zoom, _RGBA(255, 0, 255, 255), CompassTheta.x, CompassTheta.y)
  93.         END IF
  94.  
  95.         LastPoint.x = x2
  96.         LastPoint.y = y2
  97.     NEXT
  98.  
  99.  
  100. SUB StepCompass
  101.     DIM xx AS INTEGER
  102.     DIM yy AS INTEGER
  103.     xx = CompassCart.x
  104.     yy = CompassCart.y
  105.     IF (xx = 1) AND (yy = 1) THEN
  106.         CompassCart.x = -1
  107.         CompassCart.y = 1
  108.         CompassTheta.x = 0
  109.         CompassTheta.y = pi / 2
  110.     END IF
  111.     IF (xx = -1) AND (yy = 1) THEN
  112.         CompassCart.x = -1
  113.         CompassCart.y = -1
  114.         CompassTheta.x = pi / 2
  115.         CompassTheta.y = pi
  116.     END IF
  117.     IF (xx = -1) AND (yy = -1) THEN
  118.         CompassCart.x = 1
  119.         CompassCart.y = -1
  120.         CompassTheta.x = pi
  121.         CompassTheta.y = 3 * pi / 2
  122.     END IF
  123.     IF (xx = 1) AND (yy = -1) THEN
  124.         CompassCart.x = 1
  125.         CompassCart.y = 1
  126.         CompassTheta.x = 3 * pi / 2
  127.         CompassTheta.y = 2 * pi
  128.     END IF
  129.  
  130. SUB cpset (x1 AS DOUBLE, y1 AS DOUBLE, col AS _UNSIGNED LONG)
  131.     PSET (_WIDTH / 2 + x1, -y1 + _HEIGHT / 2), col
  132.  
  133. SUB clineb (x1 AS DOUBLE, y1 AS DOUBLE, x2 AS DOUBLE, y2 AS DOUBLE, col AS _UNSIGNED LONG)
  134.     LINE (_WIDTH / 2 + x1, -y1 + _HEIGHT / 2)-(_WIDTH / 2 + x2, -y2 + _HEIGHT / 2), col, B
  135.  
  136. SUB ccircle (x1 AS DOUBLE, y1 AS DOUBLE, rad AS DOUBLE, col AS _UNSIGNED LONG, ang1 AS DOUBLE, ang2 AS DOUBLE)
  137.     CIRCLE (_WIDTH / 2 + x1, -y1 + _HEIGHT / 2), rad, col, ang1, ang2
ss1.png
* ss1.png (Filesize: 2.93 KB, Dimensions: 218x183, Views: 243)
ss2.png
* ss2.png (Filesize: 12.09 KB, Dimensions: 802x626, Views: 266)
« Last Edit: December 15, 2020, 06:18:15 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MYOFS2
« Reply #1 on: December 15, 2020, 10:39:04 am »
Definitely interesting like the other posted, MYOSF, I am bookmarking both.