|
Post by bplus on Mar 26, 2024 23:40:54 GMT
can you draw this?
|
|
|
Post by Ultraman on Mar 27, 2024 15:47:16 GMT
No.
|
|
|
Post by bplus on Mar 28, 2024 22:21:16 GMT
Screen _NewImage(800, 600, 32) Print "Construction of a 'petal' between p1=(x1, y1) and p2=(x2, y2) from adj equal triangles"
' two test points, this code demo's how the drawPetal sub was created x1 = 400 y1 = 200 x2 = 400 y2 = 400
_PrintString (392, 180), "p1" ' display and label two test points Circle (x1, y1), 1 _PrintString (392, 404), "p2" Circle (x2, y2), 1
' a couple of calculations distance between and the angle the line makes from p2 dist = _Hypot(x1 - x2, y1 - y2) a = _Atan2(y1 - y2, x1 - y2) ' angle point 1 to point 2 -90 degrees here = -_pi/2 'Print a, -_Pi / 2 ' double check
xo = x2 + dist * Cos(a + _Pi(1 / 3)) ' calc the point that forms apex of equalateral triangle yo = y2 + dist * Sin(a + _Pi(1 / 3)) Circle (xo, yo), 1 _PrintString (600, 292), "po1" ' draw and label that and then show the sides of triangle Line (x1, y1)-(xo, yo), &HFF0000FF Line (x2, y2)-(xo, yo), &HFF0000FF 'Line (x1, y1)-(x2, y2), &HFF0000FF
' now calulate the perpendicular angle from po1 to midpoint of p1 and p2 mx = (x1 + x2) / 2 ' here is midpoint my = (y1 + y2) / 2
a1 = _Atan2(my - yo, mx - xo) ' the perpedicular angle or bisector of p1 and p2 a2 = a1 + _Pi(1 / 6) ' 30 degrees = _pi(1/6) of either side of the perpendicular a3 = a1 - _Pi(1 / 6)
' decide going clockwise which comes first a2 or a3 that is start angle and stop angle is the other If a2 < a3 Then starta = a2: stopa = a3 Else starta = a3: stopa = a2
' now we have all the info needed to draw one of the arcs arc xo, yo, dist, starta, stopa, &HFF0000FF 'arc x0, y0, dist + 1, starta, stopa, c~&
' do that same thing again for the other arc xo = x2 + dist * Cos(a - _Pi(1 / 3)) 'apex point on the oppsite triangle yo = y2 + dist * Sin(a - _Pi(1 / 3)) Circle (xo, yo), 1 _PrintString (186, 292), "po2" ' display and label it Line (x1, y1)-(xo, yo), &HFFFF8800 ' and show the triangle formed by point Line (x2, y2)-(xo, yo), &HFFFF8800
a1 = _Atan2(my - yo, mx - xo) ' now calc the angle made from apex to midpoint a2 = a1 + _Pi(1 / 6) ' 30 degrees both sides for arc swing start and stop a3 = a1 - _Pi(1 / 6)
' decide going clockwise which comes first a2 or a3 that is start angle and stop angle is the other If a2 < a3 Then starta = a2: stopa = a3 Else starta = a3: stopa = a2 ' draw 2nd arc arc xo, yo, dist, starta, stopa, &HFFFF8800
_PrintString (215, 560), "press any to see a demo of the drawPetal sub..." Sleep For i = 0 To 35 ' draw border x = 400 + 245 * Cos(i * _Pi(2 / 36)) y = 300 + 245 * Sin(i * _Pi(2 / 36)) If i = 0 Then savex = x: savey = y Else drawPetal lastx, lasty, x, y, &HFFFFFF00 lastx = x: lasty = y Next drawPetal lastx, lasty, savex, savey, &HFFFFFF00
Sub drawPetal (x1, y1, x2, y2, c~&) dist = _Hypot(x1 - x2, y1 - y2) a = _Atan2(y1 - y2, x1 - x2) x0 = x2 + dist * Cos(a + _Pi(1 / 3)) y0 = y2 + dist * Sin(a + _Pi(1 / 3)) mx = (x1 + x2) / 2 my = (y1 + y2) / 2 a1 = _Atan2(my - y0, mx - x0) a2 = a1 + _Pi(1 / 6) a3 = a1 - _Pi(1 / 6) If a2 < a3 Then starta = a2: stopa = a3 Else starta = a3: stopa = a2 arc x0, y0, dist, starta, stopa, c~& arc x0, y0, dist + 1, starta, stopa, c~& x0 = x2 + dist * Cos(a - _Pi(1 / 3)) y0 = y2 + dist * Sin(a - _Pi(1 / 3)) a1 = _Atan2(my - y0, mx - x0) a2 = a1 + _Pi(1 / 6) a3 = a1 - _Pi(1 / 6) If a2 < a3 Then starta = a2: stopa = a3 Else starta = a3: stopa = a2 arc x0, y0, dist, starta, stopa, c~& arc x0, y0, dist + 1, starta, stopa, c~& End Sub
'use radians Sub arc (x, y, r, raStart, raStop, c As _Unsigned Long) ' this does not check raStart and raStop like arcC does 'x, y origin, r = radius, c = color 'raStart is first angle clockwise from due East = 0 degrees ' arc will start drawing there and clockwise until raStop angle reached Dim al, a If raStop < raStart Then arc x, y, r, raStart, _Pi(2), c arc x, y, r, 0, raStop, c Else ' modified to easier way suggested by Steve 'Why was the line method not good? I forgot. al = _Pi * r * r * (raStop - raStart) / _Pi(2) For a = raStart To raStop Step 1 / al PSet (x + r * Cos(a), y + r * Sin(a)), c Next End If End Sub
|
|
|
Post by bplus on Mar 31, 2024 12:46:49 GMT
Happy Easter to all who celebrate it on this day!
Here is the first solution i came up with for Flower of Life:
_Title "Flower of life 2" ' b+ 2024-03-26 ' fix first version of flower of life around edges
Screen _NewImage(700, 700, 32) _ScreenMove 300, 40
'drawPetal 300, 350, 400, 350, &HFF8888FF 'End cx = _Width / 2: cy = _Height / 2: r = 100: c~& = &HFF8888FF drawflower6 cx, cy, r, c~& 'End For i = 0 To 5 px = cx + 2 * r * Cos(i * _Pi(1 / 3) - _Pi(.5)) py = cy + 2 * r * Sin(i * _Pi(1 / 3) - _Pi(.5)) If i <> 0 Then drawflower6 (px + lastpx) / 2, (py + lastpy) / 2, r, c~& Else savex = px: savey = py End If drawflower6 px, py, r, c~& lastpx = px: lastpy = py Next drawflower6 (savex + lastpx) / 2, (savey + lastpy) / 2, r, c~&
For i = 0 To 35 x = cx + 300 * Cos(i * _Pi(2 / 36)) y = cy + 300 * Sin(i * _Pi(2 / 36)) If i = 0 Then savex = x: savey = y Else drawPetal lastx, lasty, x, y, &HFFFFFF00 lastx = x: lasty = y Next drawPetal lastx, lasty, savex, savey, &HFFFFFF00 Sleep
Sub drawPetal (x1, y1, x2, y2, c~&) dist = _Hypot(x1 - x2, y1 - y2) a = _Atan2(y1 - y2, x1 - x2) x0 = x2 + dist * Cos(a + _Pi(1 / 3)) y0 = y2 + dist * Sin(a + _Pi(1 / 3)) mx = (x1 + x2) / 2 my = (y1 + y2) / 2 a1 = _Atan2(my - y0, mx - x0) a2 = a1 + _Pi(1 / 6) a3 = a1 - _Pi(1 / 6) If a2 < a3 Then starta = a2: stopa = a3 Else starta = a3: stopa = a2 arc x0, y0, dist, starta, stopa, c~& arc x0, y0, dist + 1, starta, stopa, c~& x0 = x2 + dist * Cos(a - _Pi(1 / 3)) y0 = y2 + dist * Sin(a - _Pi(1 / 3)) a1 = _Atan2(my - y0, mx - x0) a2 = a1 + _Pi(1 / 6) a3 = a1 - _Pi(1 / 6) If a2 < a3 Then starta = a2: stopa = a3 Else starta = a3: stopa = a2 arc x0, y0, dist, starta, stopa, c~& arc x0, y0, dist + 1, starta, stopa, c~& End Sub
Sub drawflower6 (x, y, r, c~&) Dim px(5), py(5) For i = 0 To 5 px(i) = x + r * Cos(i * _Pi(1 / 3) - _Pi(.5)) py(i) = y + r * Sin(i * _Pi(1 / 3) - _Pi(.5)) Next For i = 0 To 5 drawPetal x, y, px(i), py(i), c~& drawPetal px(i), py(i), px((i + 1) Mod 6), py((i + 1) Mod 6), c~& Next End Sub
'use radians Sub arc (x, y, r, raStart, raStop, c As _Unsigned Long) ' this does not check raStart and raStop like arcC does Dim al, a 'x, y origin, r = radius, c = color
'raStart is first angle clockwise from due East = 0 degrees ' arc will start drawing there and clockwise until raStop angle reached
If raStop < raStart Then arc x, y, r, raStart, _Pi(2), c arc x, y, r, 0, raStop, c Else ' modified to easier way suggested by Steve 'Why was the line method not good? I forgot. al = _Pi * r * r * (raStop - raStart) / _Pi(2) For a = raStart To raStop Step 1 / al PSet (x + r * Cos(a), y + r * Sin(a)), c Next End If End Sub
i solved by first drawing a petal then drawing a flower then overlapping the flower drawings. To get the edges right, I had to calc the midpoints between the current flower to draw and the last one drawn, this part:
If i <> 0 Then drawflower6 (px + lastpx) / 2, (py + lastpy) / 2, r, c~& Else savex = px: savey = py End If
|
|
|
Post by bplus on Mar 31, 2024 13:25:58 GMT
vince challenged me at discord to do it without overlap. i decided i had to skip the flower drawing part and do all petals individually BUT to avoid duplicate petal drawing i had to get all the points the flower petals connect. i did that in an unusual way by collecting all the points I used in flower drawing and then removing the duplicates, 36 + 1 points THEN if i drew the petal from point 23 to point 24 i did Not want to duplicate drawing from point 24 to point 23.
index i runs through all the points but the last and index j runs through all the points after i to the last, if the distance between point i and point j is just r then draw the petal. This gets all the petals drawn without duplication.
_Title "Flower of Life" ' b+ 2024-03-27 ' the challenge here is to do this without overlapping circles ' to do this we need all the points and drawPetal Screen _NewImage(700, 700, 32) _ScreenMove 300, 40
cx = _Width / 2: cy = _Height / 2: r = 100: c~& = &HFF8888FF
Dim px(42), py(42) For i = 0 To 5 ' just collect the points p = p + 1 x = cx + 2 * r * Cos(i * _Pi(1 / 3) - _Pi(.5)) y = cy + 2 * r * Sin(i * _Pi(1 / 3) - _Pi(.5)) px(p) = x: py(p) = y For j = 0 To 5 p = p + 1 px(p) = x + r * Cos(j * _Pi(1 / 3) - _Pi(.5)) py(p) = y + r * Sin(j * _Pi(1 / 3) - _Pi(.5)) Next Next px(0) = cx: py(0) = cy Dim qx(36), qy(36) Print "Here are all the points we need to connect with petals if distance between them = r." For i = 0 To 42 'remove repeated points If i <> 14 And i <> 16 And i <> 24 And i <> 32 And i <> 38 And i <> 40 Then qx(q) = px(i): qy(q) = py(i) Circle (qx(q), qy(q)), 1 q = q + 1 End If Next _PrintString (100, 680), "press any, to see the petals drawn to fill out Flower of Life..." Sleep Line (0, 0)-(_Width, 18), &HFF000000, BF ' black out text Line (0, 679)-(_Width, _Height), &HFF000000, BF For i = 0 To 35 For j = i + 1 To 36 If _Hypot(qx(i) - qx(j), qy(i) - qy(j)) - r < .1 Then drawPetal qx(i), qy(i), qx(j), qy(j), &HFF8888FF _Limit 3 End If Next Next For i = 0 To 35 ' draw border x = cx + 300 * Cos(i * _Pi(2 / 36)) y = cy + 300 * Sin(i * _Pi(2 / 36)) If i = 0 Then savex = x: savey = y Else drawPetal lastx, lasty, x, y, &HFFFFFF00 lastx = x: lasty = y Next drawPetal lastx, lasty, savex, savey, &HFFFFFF00 Sleep
Sub drawPetal (x1, y1, x2, y2, c~&) dist = _Hypot(x1 - x2, y1 - y2) a = _Atan2(y1 - y2, x1 - x2) x0 = x2 + dist * Cos(a + _Pi(1 / 3)) y0 = y2 + dist * Sin(a + _Pi(1 / 3)) mx = (x1 + x2) / 2 my = (y1 + y2) / 2 a1 = _Atan2(my - y0, mx - x0) a2 = a1 + _Pi(1 / 6) a3 = a1 - _Pi(1 / 6) If a2 < a3 Then starta = a2: stopa = a3 Else starta = a3: stopa = a2 arc x0, y0, dist, starta, stopa, c~& arc x0, y0, dist + 1, starta, stopa, c~& x0 = x2 + dist * Cos(a - _Pi(1 / 3)) y0 = y2 + dist * Sin(a - _Pi(1 / 3)) a1 = _Atan2(my - y0, mx - x0) a2 = a1 + _Pi(1 / 6) a3 = a1 - _Pi(1 / 6) If a2 < a3 Then starta = a2: stopa = a3 Else starta = a3: stopa = a2 arc x0, y0, dist, starta, stopa, c~& arc x0, y0, dist + 1, starta, stopa, c~& End Sub
'use radians Sub arc (x, y, r, raStart, raStop, c As _Unsigned Long) ' this does not check raStart and raStop like arcC does 'x, y origin, r = radius, c = color 'raStart is first angle clockwise from due East = 0 degrees ' arc will start drawing there and clockwise until raStop angle reached Dim al, a If raStop < raStart Then arc x, y, r, raStart, _Pi(2), c arc x, y, r, 0, raStop, c Else ' modified to easier way suggested by Steve 'Why was the line method not good? I forgot. al = _Pi * r * r * (raStop - raStart) / _Pi(2) For a = raStart To raStop Step 1 / al PSet (x + r * Cos(a), y + r * Sin(a)), c Next End If End Sub
|
|
|
Post by bplus on Mar 31, 2024 15:43:08 GMT
Here is Easter Bonus, random coloring from a Plasma palette _Title "Flower of Life 4" ' b+ 2024-03-27 ' the challenge here is to do this without overlapping circles ' to do this we need all the points and drawPetal ' try a random coloring from a plasma palette
Screen _NewImage(700, 700, 32) _ScreenMove 300, 40 Randomize Timer cx = _Width / 2: cy = _Height / 2: r = 100: c~& = &HFF8888FF
' create plasma palette Dim Shared CN, PR, PG, PB ReDim Shared Pal(1 To 144) As _Unsigned Long
Dim px(42), py(42) For i = 0 To 5 ' just collect the points p = p + 1 x = cx + 2 * r * Cos(i * _Pi(1 / 3) - _Pi(.5)) y = cy + 2 * r * Sin(i * _Pi(1 / 3) - _Pi(.5)) px(p) = x: py(p) = y For j = 0 To 5 p = p + 1 px(p) = x + r * Cos(j * _Pi(1 / 3) - _Pi(.5)) py(p) = y + r * Sin(j * _Pi(1 / 3) - _Pi(.5)) Next Next px(0) = cx: py(0) = cy Dim qx(36), qy(36) Print "Here are all the points we need to connect with petals if distance between them = r." For i = 0 To 42 'remove repeated points If i <> 14 And i <> 16 And i <> 24 And i <> 32 And i <> 38 And i <> 40 Then qx(q) = px(i): qy(q) = py(i) Circle (qx(q), qy(q)), 1 q = q + 1 End If Next _PrintString (100, 680), "press any, to see the petals drawn to fill out Flower of Life..." Sleep Line (0, 0)-(_Width, 18), &HFF000000, BF ' black out text Line (0, 679)-(_Width, _Height), &HFF000000, BF Do createPal For i = 0 To 35 For j = i + 1 To 36 If _Hypot(qx(i) - qx(j), qy(i) - qy(j)) - r < .1 Then drawPetal qx(i), qy(i), qx(j), qy(j), Pal(Int(Rnd * 144) + 1) ' _Limit 3 End If Next Next For i = 0 To 35 ' draw border x = cx + 310 * Cos(i * _Pi(2 / 36)) y = cy + 310 * Sin(i * _Pi(2 / 36)) If i = 0 Then savex = x: savey = y Else drawPetal lastx, lasty, x, y, &HFFFFFF00 lastx = x: lasty = y Next drawPetal lastx, lasty, savex, savey, &HFFFFFF00 Sleep Loop Until _KeyDown(27)
Sub drawPetal (x1, y1, x2, y2, c~&) dist = _Hypot(x1 - x2, y1 - y2) a = _Atan2(y1 - y2, x1 - x2) x0 = x2 + dist * Cos(a + _Pi(1 / 3)) y0 = y2 + dist * Sin(a + _Pi(1 / 3)) mx = (x1 + x2) / 2 my = (y1 + y2) / 2 a1 = _Atan2(my - y0, mx - x0) a2 = a1 + _Pi(1 / 6) a3 = a1 - _Pi(1 / 6) If a2 < a3 Then starta = a2: stopa = a3 Else starta = a3: stopa = a2 arc x0, y0, dist, starta, stopa, c~& arc x0, y0, dist + 1, starta, stopa, c~& x0 = x2 + dist * Cos(a - _Pi(1 / 3)) y0 = y2 + dist * Sin(a - _Pi(1 / 3)) a1 = _Atan2(my - y0, mx - x0) a2 = a1 + _Pi(1 / 6) a3 = a1 - _Pi(1 / 6) If a2 < a3 Then starta = a2: stopa = a3 Else starta = a3: stopa = a2 arc x0, y0, dist, starta, stopa, c~& arc x0, y0, dist + 1, starta, stopa, c~& End Sub
'use radians Sub arc (x, y, r, raStart, raStop, c As _Unsigned Long) ' this does not check raStart and raStop like arcC does 'x, y origin, r = radius, c = color 'raStart is first angle clockwise from due East = 0 degrees ' arc will start drawing there and clockwise until raStop angle reached Dim al, a If raStop < raStart Then arc x, y, r, raStart, _Pi(2), c arc x, y, r, 0, raStop, c Else ' modified to easier way suggested by Steve 'Why was the line method not good? I forgot. al = _Pi * r * r * (raStop - raStart) / _Pi(2) For a = raStart To raStop Step 1 / al PSet (x + r * Cos(a), y + r * Sin(a)), c Next End If End Sub
Function Plasma~& () CN = CN + .3 'dim shared cN as _Integer64, pR as long, pG as long, pB as long Plasma~& = _RGB32(127 + 127 * Sin(PR * CN), 127 + 127 * Sin(PG * CN), 127 + 127 * Sin(PB * CN)) End Function
Sub resetPlasma () PR = Rnd ^ 2: PG = Rnd ^ 2: PB = Rnd ^ 2 End Sub
Sub createPal resetPlasma CN = 0 For i = 1 To 144 Pal(i) = Plasma~& Next End Sub
|
|
Aaditya Parashar
Full Member
Just somebody with an abnormal coding routine.
Posts: 127
|
Post by Aaditya Parashar on Apr 3, 2024 3:04:20 GMT
The second image is quite challenging to illustrate without using the draw command. 😄
|
|
|
Post by bplus on Apr 5, 2024 13:05:43 GMT
|
|
|
Post by bplus on Apr 5, 2024 17:43:21 GMT
man that guy blew me away with the one constant lecture!
|
|
|
Post by aurelvz on Apr 6, 2024 5:21:32 GMT
is 3d your new obsession?
|
|
|
Post by bplus on Apr 6, 2024 11:27:29 GMT
No not 3d. i still avoid it, so much more complex, ie you start having to worry about which you can draw first, what actually will show up in the perspective view. in 2D there is no worry about that.
always had a soft spot for geometry that might be next obsession, of course making my own functions won't change ;-))
this guy [in the link i gave above] showed a connection between all the constants of universe plus predicted another 12 or so elements plus claims to be able to predict primes [but i did see a prime formula on one of the math you-tubes] doing all this through geometry maybe more number theory oriented than compass and straight edge. that opening diagram that prompted me to post the link immediately here was just the beginning of a mind blowing lecture,
repeat he made a connection between all the constants of the universe.
i sure would like to see STATIC's take on that link and lecture.
|
|
|
Post by bplus on Apr 7, 2024 21:00:02 GMT
yeah interesting, i tried this guy before possible on 3d engine or something else don't remember.
i quit watching when he started talking about tools not available to us qb64 coders only 7 minutes into the thing.
|
|
|
Post by bplus on Apr 7, 2024 21:11:45 GMT
The second image is quite challenging to illustrate without using the draw command. 😄 you know if you change the angle just a little bit so that the back bottom left corner sits exactly behind the top front right corner, you have a hexagon, maybe 2 concentric ones for frame thickness... now i am curious...
|
|
|
Post by bplus on Apr 7, 2024 23:24:33 GMT
ok i have a ways to go, right now just mapping points
_Title "Impossible cube" ' b+ 2024-04-07
Screen _NewImage(600, 600, 32) _ScreenMove 340, 60
cx = 300: cy = 300: thick = 10: r = 200 a = _Pi(2 / 6) Dim px1(5), py1(5), px2(5), py2(5), px3(5), py3(5) For i = 0 To 5 px1(i) = cx + r * Cos(a * i - _Pi / 2): py1(i) = cy + r * Sin(a * i - _Pi / 2) px2(i) = cx + (r - thick) * Cos(a * i - _Pi / 2): py2(i) = cy + (r - thick) * Sin(a * i - _Pi / 2) px3(i) = cx + (r - 2 * thick) * Cos(a * i - _Pi / 2): py3(i) = cy + (r - 2 * thick) * Sin(a * i - _Pi / 2) Line (cx, cy)-(px1(i), py1(i)) If i > 0 Then Line (px1(i - 1), py1(i - 1))-(px1(i), py1(i)) Line (px2(i - 1), py2(i - 1))-(px2(i), py2(i)) Line (px3(i - 1), py3(i - 1))-(px3(i), py3(i)) End If Next
Line (px1(5), py1(5))-(px1(0), py1(0)) Line (px2(5), py2(5))-(px2(0), py2(0)) Line (px3(5), py3(5))-(px3(0), py3(0)) Sleep
Sub PALline (BaseX, BaseY, RAngle, Lngth, K As _Unsigned Long) ' point angle length line Dim x1, y1 x1 = BaseX + Lngth * Cos(RAngle) y1 = BaseY + Lngth * Sin(RAngle) Line (BaseX, BaseY)-(x1, y1), K End Sub
|
|
Aaditya Parashar
Full Member
Just somebody with an abnormal coding routine.
Posts: 127
|
Post by Aaditya Parashar on Apr 8, 2024 9:27:37 GMT
As far a 3D goes bplus this guy might be able to help you and others a lot! From what I can read he get's to the core of the problem without the complicated explanation,as one person wrote below... "@lennybird91 4 years ago As a Junior software engineer whose coverage of graphics consisted of one course utilizing OpenGL in college, I'm very grateful for this series. Exploring the underlying theory devoid of simplifying libraries is exactly what I'm after. Thanks!" Code-It-Yourself! 3D Graphics Engine Part #1 - Triangles & Projection www.youtube.com/watch?v=ih20l3pJoeU I tried to make something and just managed to do the first two parts, the third part includes clipping and textures but it wasn't important, so I just left it. 3d_part1.bas (5.11 KB) 3d_part2.bas (8 KB)
|
|