### Author Topic: Lissajous Curve Table by FellippeHeitor  (Read 4875 times)

0 Members and 1 Guest are viewing this topic.

#### Qwerkey

• Forum Resident
• Posts: 755
##### Lissajous Curve Table by FellippeHeitor
« on: March 10, 2020, 11:00:24 am »
Lissajous Curve Table

Author: @FellippeHeitor
Source: qb64.org Forum
URL: https://www.qb64.org/forum/index.php?topic=683.0
Version: « Reply #8 on: October 09, 2018, 02:48:07 PM »
Tags: [2D], [Graphics], [Mathematics]

Description:
Graphical Lissajou's Figures.  For added eye-candy-ness, I've changed the plot line to paint using HSB colors so that ink color will vary according to the current rotational angle.

Source Code:
Code: QB64: [Select]
1. _TITLE "Lissajous Curve Table"
2.
3.
4. TYPE vector
5.
6. DIM SHARED angle
7. DIM SHARED rows, cols
8.
9. SCREEN _NEWIMAGE(800, 800, 32)
10.
11. setup:
12. angle = 0
13. w = 80
14. rows = INT(_HEIGHT / w) - 1
15. cols = INT(_WIDTH / w) - 1
16. REDIM dot(rows, cols) AS vector
17.
18. plot = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
19. _DEST plot
20.
21.         oldScreen = _DEST
22.         _FREEIMAGE oldScreen
23.         _FREEIMAGE plot
24.         GOTO setup
25.
26.     _PUTIMAGE , plot
27.
28.     d = w - 0.2 * w
29.     r = d / 2
30.
31.     FOR i = 0 TO cols
32.         cx = w + i * w + w / 2
33.         cy = w / 2
34.         CIRCLE (cx, cy), r
35.
36.         x = r * COS(angle * (i + 1) - _PI(.5))
37.         y = r * SIN(angle * (i + 1) - _PI(.5))
38.
39.         LINE (cx + x, 0)-(cx + x, _HEIGHT), _RGB32(127, 127, 127)
40.         CircleFill cx + x, cy + y, 4, _RGB32(28, 222, 50)
41.         CircleFill cx + x, cy + y, 2, _RGB32(11, 33, 249)
42.
43.         FOR j = 0 TO rows
44.             dot(j, i).x = cx + x
45.
46.     FOR i = 0 TO rows
47.         cx = w / 2
48.         cy = w + i * w + w / 2
49.         CIRCLE (cx, cy), r
50.
51.         x = r * COS(angle * (i + 1) - _PI(.5))
52.         y = r * SIN(angle * (i + 1) - _PI(.5))
53.
54.         LINE (0, cy + y)-(_WIDTH, cy + y), _RGB32(127, 127, 127)
55.         CircleFill cx + x, cy + y, 4, _RGB32(28, 222, 50)
56.         CircleFill cx + x, cy + y, 2, _RGB32(11, 33, 249)
57.
58.         FOR j = 0 TO cols
59.             dot(i, j).y = cy + y
60.
61.     _DEST plot
62.     LINE (0, 0)-(_WIDTH, _HEIGHT), _RGBA32(0, 0, 0, 4), BF
63.     FOR j = 0 TO rows
64.         FOR i = 0 TO cols
65.             CircleFill dot(j, i).x, dot(j, i).y, 1, hsb(_R2D(angle), 127, 127, 255)
66.
67.     angle = angle + 0.01
68.     IF angle > _PI(2) THEN angle = 0
69.
70.
71.     _LIMIT 30
72.
73. SUB CircleFill (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
74.     DIM x0 AS SINGLE, y0 AS SINGLE
75.
76.     x0 = R
77.     y0 = 0
78.     e = -R
79.     DO WHILE y0 < x0
80.         IF e <= 0 THEN
81.             y0 = y0 + 1
82.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
83.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
84.             e = e + 2 * y0
85.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
86.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
87.             x0 = x0 - 1
88.             e = e - 2 * x0
89.     LINE (x - R, y)-(x + R, y), C, BF
90.
91. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
92.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
93.
94. FUNCTION hsb~& (__H AS _FLOAT, __S AS _FLOAT, __B AS _FLOAT, A AS _FLOAT)
95.
96.     H = map(__H, 0, 255, 0, 360)
97.     S = map(__S, 0, 255, 0, 1)
98.     B = map(__B, 0, 255, 0, 1)
99.
100.     IF S = 0 THEN
101.         hsb~& = _RGBA32(B * 255, B * 255, B * 255, A)
102.
103.     DIM fmx AS _FLOAT, fmn AS _FLOAT
104.     DIM fmd AS _FLOAT, iSextant AS INTEGER
105.     DIM imx AS INTEGER, imd AS INTEGER, imn AS INTEGER
106.
107.     IF B > .5 THEN
108.         fmx = B - (B * S) + S
109.         fmn = B + (B * S) - S
110.         fmx = B + (B * S)
111.         fmn = B - (B * S)
112.
113.     iSextant = INT(H / 60)
114.
115.     IF H >= 300 THEN
116.         H = H - 360
117.
118.     H = H / 60
119.     H = H - (2 * INT(((iSextant + 1) MOD 6) / 2))
120.
121.     IF iSextant MOD 2 = 0 THEN
122.         fmd = (H * (fmx - fmn)) + fmn
123.         fmd = fmn - (H * (fmx - fmn))
124.
125.     imx = _ROUND(fmx * 255)
126.     imd = _ROUND(fmd * 255)
127.     imn = _ROUND(fmn * 255)
128.
129.     SELECT CASE INT(iSextant)
130.         CASE 1
131.             hsb~& = _RGBA32(imd, imx, imn, A)
132.         CASE 2
133.             hsb~& = _RGBA32(imn, imx, imd, A)
134.         CASE 3
135.             hsb~& = _RGBA32(imn, imd, imx, A)
136.         CASE 4
137.             hsb~& = _RGBA32(imd, imn, imx, A)
138.         CASE 5
139.             hsb~& = _RGBA32(imx, imn, imd, A)
140.             hsb~& = _RGBA32(imx, imd, imn, A)
141.
142.

« Last Edit: March 27, 2020, 05:58:15 am by Qwerkey »