QB64 Phoenix Edition
Radian Ferris Wheel - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Programs (https://qb64phoenix.com/forum/forumdisplay.php?fid=7)
+---- Thread: Radian Ferris Wheel (/showthread.php?tid=1108)

Pages: 1 2


Radian Ferris Wheel - james2464 - 11-11-2022

I was messing around with radians and ended up making this.   Cheers.

Code: (Select All)
'radian ferris wheel
'james2464 - Nov 11 2022 - Radian Ferris Wheel

Screen _NewImage(800, 600, 32)
Const PI = 3.141592654#

Dim c(2) As Long
c(1) = _RGB(50, 255, 100)
c(2) = _RGB(0, 100, 0)

'origin
xx = 400
yy = 300
w = 120 'wheel radius
p = 10 'number of positions
'=====================================================
h = _Hypot(w, 0)
h1 = _Atan2(0, w)
'=====================================================
Do
    _Limit 30
    Cls
    Circle (xx, yy), w, c(2)
    Line (xx, yy)-(xx - 50, yy + w + 40), c(1)
    Line (xx, yy)-(xx + 50, yy + w + 40), c(1)
    Line (xx - 50, yy + w + 40)-(xx + 50, yy + w + 40), c(1)
    h1 = h1 + .002
    If h1 >= PI * 2 Then h1 = 0
    '-------------------------------------------------
    For t = 1 To p
        h2 = h1 + ((PI * 2) / p) * t
        x = Cos(h2) * h: y = Sin(h2) * h
        x2 = Cos(h2) * (h * 1.5): y2 = Sin(h2) * (h * 1.5)
        Line (xx, yy)-(xx + x, yy + y), c(2)
        Line (xx + x - 7, yy + y)-(xx + x + 7, yy + y), c(1)
        Line (xx + x, yy + y)-(xx + x, yy + y + 15), c(1)
        Line (xx + x - 7, yy + y + 15)-(xx + x + 7, yy + y + 25), c(1), B
        Locate 35 * ((yy + y2 + 50) / 600), 99 * ((xx + x2) / 800)
        If h2 >= PI * 2 Then h2 = h2 - PI * 2
        Print Using "#.##"; h2
    Next t
    _Display
Loop



RE: Radian Ferris Wheel - bplus - 11-12-2022

Cute!


RE: Radian Ferris Wheel - PhilOfPerth - 11-12-2022

Very nice!
Took me a while (slow learner) to understand what the numbers meant. Thought they were their horizontal positions.


RE: Radian Ferris Wheel - james2464 - 11-12-2022

Sorry, I should have explained a bit. Radians have been a bit confusing to me, and I found out recently that you can just take 2 * PI (6.28) and just consider that to be the same as 360 degrees. But it can still get confusing, especially when QB64 is capable of using higher numbers like 9.50 and it works just fine. Sort of like 1000 degrees I suppose. Then there are negative radians as well. So anyway I wanted to visualize the full radian circle and animate it, so this was the result.

The program uses _atan2 and _hypot to determine the line angle. But the interesting part to me is that only one line is calculated that way. The rest are just that initial radian value + whatever the interval is. Then sin and cos are used to find the line endpoints.


RE: Radian Ferris Wheel - PhilOfPerth - 11-12-2022

(11-12-2022, 03:48 AM)james2464 Wrote: Sorry, I should have explained a bit.  Radians have been a bit confusing to me, and I found out recently that you can just take 2 * PI (6.28) and just consider that to be the same as 360 degrees.  But it can still get confusing, especially when QB64 is capable of using higher numbers like 9.50 and it works just fine.  Sort of like 1000 degrees I suppose.  Then there are negative radians as well.  So anyway I wanted to visualize the full radian circle and animate it, so this was the result.

The program uses _atan2 and _hypot to calculate the line endpoints.  But the interesting part to me is that only one line is calculated that way.  The rest are just that initial radian value + whatever the interval is.  Then it uses sin and cos to find the line endpoints, using the new radian.

No need to be sorry James. It made me look a bit closer than I may have done if you explained it all. Great job!
(I had fun  fiddling with it a bit. Couldn't find a speed setting, so I guess that's just a function of the code loops etc.)


RE: Radian Ferris Wheel - james2464 - 11-12-2022

(11-12-2022, 03:53 AM)PhilOfPerth Wrote:
(11-12-2022, 03:48 AM)james2464 Wrote: Sorry, I should have explained a bit.  Radians have been a bit confusing to me, and I found out recently that you can just take 2 * PI (6.28) and just consider that to be the same as 360 degrees.  But it can still get confusing, especially when QB64 is capable of using higher numbers like 9.50 and it works just fine.  Sort of like 1000 degrees I suppose.  Then there are negative radians as well.  So anyway I wanted to visualize the full radian circle and animate it, so this was the result.

The program uses _atan2 and _hypot to calculate the line endpoints.  But the interesting part to me is that only one line is calculated that way.  The rest are just that initial radian value + whatever the interval is.  Then it uses sin and cos to find the line endpoints, using the new radian.

No need to be sorry James. It made me look a bit closer than I may have done if you explained it all. Great job!
(I had fun  fiddling with it a bit. Couldn't find a speed setting, so I guess that's just a function of the code loops etc.)

Oh you can adjust line 27 (h1 = h1 + .002) if you want to change the speed.   Something like .050 would be pretty fast.


RE: Radian Ferris Wheel - PhilOfPerth - 11-12-2022

(11-12-2022, 03:59 AM)james2464 Wrote:
(11-12-2022, 03:53 AM)PhilOfPerth Wrote:
(11-12-2022, 03:48 AM)james2464 Wrote: Sorry, I should have explained a bit.  Radians have been a bit confusing to me, and I found out recently that you can just take 2 * PI (6.28) and just consider that to be the same as 360 degrees.  But it can still get confusing, especially when QB64 is capable of using higher numbers like 9.50 and it works just fine.  Sort of like 1000 degrees I suppose.  Then there are negative radians as well.  So anyway I wanted to visualize the full radian circle and animate it, so this was the result.

The program uses _atan2 and _hypot to calculate the line endpoints.  But the interesting part to me is that only one line is calculated that way.  The rest are just that initial radian value + whatever the interval is.  Then it uses sin and cos to find the line endpoints, using the new radian.

No need to be sorry James. It made me look a bit closer than I may have done if you explained it all. Great job!
(I had fun  fiddling with it a bit. Couldn't find a speed setting, so I guess that's just a function of the code loops etc.)

Oh you can adjust line 27 (h1 = h1 + .002) if you want to change the speed.   Something like .050 would be pretty fast.
Thanks James.
I had a go a while back at explaining what pi was, using a "circular" shape with increasing numbers of arcs, from 3 to 1000, and summing the lengths of the arcs until they reached 6.28... but I eventually gave up (temporarily?).
Maybe someone cleverer than me will do this (hint, hint)?


RE: Radian Ferris Wheel - bplus - 11-12-2022

Quote:I had a go a while back at explaining what pi was, using a "circular" shape with increasing numbers of arcs, from 3 to 1000, and summing the lengths of the arcs until they reached 6.28... but I eventually gave up (temporarily?).

Maybe someone cleverer than me will do this (hint, hint)?


Pi is a ratio of the diameter of a circle to the circumference of a circle: d * Pi = circumference
since radius is 1/2 diameter 2 * r * Pi = circumference

If radius is 1, a unit circle they call it, the radian measure = the circumference of the arc
A unit circle (360 degrees) has  2 *Pi circumference ( 2 * 1 * Pi)
Half a unit circle (180 degrees) has Pi circumference (2 * Pi * 1/2)
1/4 unit circle (90 degrees) has Pi/2 circumference as is Pi/2 radians ( 2 * Pi * 1/4)

so 1/n unit circle is 2 * Pi * 1/n radians.


RE: Radian Ferris Wheel - james2464 - 11-12-2022

I added some background, so I could try a moving cloud effect.

Code: (Select All)
'ferris wheel with clouds
'james2464 - Nov 12 2022

Dim Shared scx, scy As Integer
scx = 800: scy = 600
Screen _NewImage(scx, scy, 32)

Const PI = 3.141592654#
Randomize Timer

Dim Shared bg&, cd&(20)
bg& = _NewImage(scx + 1, scy + 1, 32)
For ct = 1 To 20
    cd&(ct) = _NewImage(301, 101, 32)
Next ct

Dim Shared c(100) As Long
colour1

Type movingcloud
    x As Single
    y As Single
    xv As Single
End Type
Dim Shared cloud(20) As movingcloud
Dim Shared cloudtotal

cloudtotal = 6
makeclouds

background1
_PutImage (1, 1)-(scx - 1, scy - 1), 0, bg&, (1, 1)-(scx - 1, scy - 1) 'take snapshot of screen



'origin
xx = 400
yy = 300
w = 220 'wheel radius
p = 15 'number of positions
'=====================================================
h = _Hypot(w, 0)
h1 = _Atan2(0, w)
'=====================================================
Do
    _Limit 30
    Cls
    _PutImage (0, 0)-(scx, scy), bg&, 0 'draw background

    For ct = 1 To cloudtotal
        _PutImage (cloud(ct).x, cloud(ct).y)-(cloud(ct).x + 500, cloud(ct).y + 100), cd&(ct), 0 'cloud
        cloud(ct).x = cloud(ct).x + cloud(ct).xv
        If cloud(ct).x > 1000 Then
            cloud(ct).x = -600
            cloud(ct).y = Rnd * 200 - 20
            cloud(ct).xv = Rnd * .2 + .3
        End If
    Next ct

    Circle (xx, yy), w, c(0)
    Line (xx, yy)-(xx - 50, yy + w + 40), c(0)
    Line (xx, yy)-(xx + 50, yy + w + 40), c(0)
    Line (xx - 50, yy + w + 40)-(xx + 50, yy + w + 40), c(0)
    h1 = h1 + .002
    If h1 >= PI * 2 Then h1 = 0
    '-------------------------------------------------
    For t = 1 To p
        h2 = h1 + ((PI * 2) / p) * t
        x = Cos(h2) * h: y = Sin(h2) * h
        Line (xx, yy)-(xx + x, yy + y), c(0)
        Line (xx + x - 7, yy + y - 1)-(xx + x + 7, yy + y + 1), c(12), BF
        Line (xx + x, yy + y)-(xx + x, yy + y + 15), c(0)
        Line (xx + x - 7, yy + y + 15)-(xx + x + 7, yy + y + 25), c(12), BF
    Next t
    _Display
Loop

Sub background1
    Cls
    Line (1, 1)-(scx - 1, scy - 1), c(1), BF
    y = 400
    For t = 1 To y
        m = 255 * ((400 - t) / 400)
        c(99) = _RGBA(150, 150, 255, m)
        Line (1, t)-(scx - 1, t), c(99)
    Next t

    ty = scy - y
    For t = y To scy
        t2 = ((scy - t) * 2)
        m = 255 * ((scy - t2) / scy)
        c(99) = _RGBA(50, 150, 50, m)
        Line (1, t)-(scx - 1, t), c(99)
    Next t
End Sub



Sub colour1
    c(0) = _RGB(0, 0, 0)
    c(1) = _RGB(255, 255, 255)
    c(2) = _RGB(255, 255, 0)
    c(3) = _RGB(255, 0, 0)
    c(4) = _RGB(0, 255, 0)
    c(5) = _RGB(0, 255, 255)
    c(6) = _RGB(255, 0, 255)
    c(7) = _RGB(30, 30, 255)
    c(8) = _RGB(150, 150, 250)
    c(9) = _RGB(250, 150, 150)
    c(10) = _RGB(150, 250, 150)
    c(11) = _RGB(150, 150, 255) 'sky blue
    c(12) = _RGB(150, 75, 125) 'cars
    c(13) = _RGB(255, 0, 0)
    c(14) = _RGB(50, 150, 50) 'ground
End Sub



Sub makeclouds

    'create cloud images with clear background

    For ct = 1 To cloudtotal

        Cls 'cloud 1
        Line (0, 0)-(302, 102), c(1), B
        For t = 1 To 80
            x1 = Rnd * 260 - 130
            y1 = Rnd * 60 - 30
            d1 = Rnd * 12 + 7
            For d = d1 To .1 Step -.1
                c(99) = _RGB(250 - y1 * 1.2, 250 - y1 * 1.2, 250 - y1 * 1.2)
                Circle (150 + x1, 50 + y1), d, c(99) 'outline
            Next d
        Next t
        _PutImage (1, 1)-(301, 101), 0, cd&(ct), (1, 1)-(300, 100)
        _ClearColor c(0), cd&(ct)

        'starting position
        cloud(ct).x = Rnd * 800 - 400: cloud(ct).y = Rnd * 200 - 20
        'speed
        cloud(ct).xv = Rnd * .2 + .3
    Next ct

End Sub



RE: Radian Ferris Wheel - bplus - 11-12-2022

Nice effects!