Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drawing Tools Subs or Functions with Demo
#59
OK a better? Rainbow with Modified MidInk~& for Alpha control and Modified ROY G BIV adding a much needed Cyan after Green and before Blue.

Code: (Select All)
_Title "Rainbow Test 2 Modified MidInk and ROY G BIV" ' b+ 2025-05-03 ROY G Cyan BIV with modified MidInk~&
Screen _NewImage(800, 600, 32)
_ScreenMove 250, 60
Const xmax = 800
Const ymax = 600

horizon% = Int(ymax * .6)
For a = 0 To 255 Step 5
    Cls
    For i = 600 To 0 Step -1 '                      the sun
        FC3 400, horizon% + 50, i, midInk~&(255, 255, 0, 50, 50, 208, i / 600, 200)
    Next

    For i = horizon% To ymax '              the land
        Line (0, i)-(xmax, i), midInk~&(200, 200, 60, 45, 48, 0, (i - horizon%) / (ymax - horizon%), 255)
    Next
    For r = 400 To 331 Step -.25
        If r > 390 Then
            c~& = midInk~&(255, 0, 0, 255, 127, 0, 1 - ((r - 390) / 10), a)
        ElseIf r > 380 Then
            c~& = midInk~&(255, 127, 0, 255, 255, 0, 1 - ((r - 380) / 10), a)
        ElseIf r > 370 Then
            c~& = midInk~&(255, 255, 0, 0, 255, 0, 1 - ((r - 370) / 10), a)
        ElseIf r > 360 Then
            c~& = midInk~&(0, 255, 0, 0, 255, 255, 1 - ((r - 360) / 10), a)
        ElseIf r > 350 Then
            c~& = midInk~&(0, 255, 255, 0, 0, 255, 1 - ((r - 350) / 10), a)
        ElseIf r > 340 Then
            c~& = midInk~&(0, 0, 255, 75, 0, 230, 1 - ((r - 340) / 10), a)
        Else
            c~& = midInk~&(75, 0, 230, 248, 0, 211, 1 - ((r - 330) / 10), a)
        End If

        drawArc 400, horizon% + 50, r, _Pi, _Pi, c~&
    Next
    _Display
    ' _Limit 100
Next
Sleep

' 2025-05-03 Modified MidInk~& to control Alpha out put
' blend 2 colors according to fractional distance of 2nd to first color
Function midInk~& (r1%, g1%, b1%, r2%, g2%, b2%, fr##, A%)
    midInk~& = _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##, A%)
End Function

Sub FC3 (cx As Long, cy As Long, r As Long, clr~&) ' fill circle #3 mod
    Dim As Long r2, x, y ' for Option _Explicit
    If r < 1 Then Exit Sub
    Line (cx - r, cy)-(cx + r, cy), clr~&, BF
    r2 = r * r
    Do
        y = y + 1
        x = Sqr(r2 - y * y)
        Line (cx - x, cy + y)-(cx + x, cy + y), clr~&, BF
        Line (cx - x, cy - y)-(cx + x, cy - y), clr~&, BF
    Loop Until y = r
End Sub

Sub drawArc (xc, yc, radius, rStart, rMeasure, colr As _Unsigned Long)
    ' xc, yc Center for arc circle
    ' rStart is the Radian Start Angle, use _D2R for conversion from Degrees to Radians
    ' rMeasure is the measure of Arc in Radain units, use _D2R for conversion from Degrees to Radians
    ' Arc will start at rStart and go clockwise around for rMeasure Radians

    Dim rEnd, stepper, a, x, y

    rEnd = rStart + rMeasure
    stepper = 1 / radius ' the bigger the radius the smaller  the steps
    For a = rStart To rEnd Step stepper
        x = xc + radius * Cos(a)
        y = yc + radius * Sin(a)
        If a > rStart Then Line -(x, y), colr Else PSet (x, y), colr
    Next
End Sub

   

Update:
At first I thought this was better than the Rainbow~&(fraction) coloring Function but now with Alpha setting added to maybe not better at all. Rainbow~&(fraction) coloring Function spreads color span very evenly OR I used a too dark a Green for MidInk~&() color Function.

Tweaking numbers and using less alpha, BTW this MidInk~&(fraction) coloring Function is also modified with an Alpha setting!
Code: (Select All)
_Title "Rainbow Test 2 Modified MidInk and ROY G BIV" ' b+ 2025-05-03 ROY G Cyan BIV with modified MidInk~&
Screen _NewImage(800, 600, 32)
_ScreenMove 250, 60
Const xmax = 800
Const ymax = 600

horizon% = Int(ymax * .6)
For a = 0 To 10 Step 5
    Cls
    For i = 600 To 0 Step -1 '                      the sun
        FC3 400, horizon% + 50, i, midInk~&(255, 255, 0, 50, 50, 208, i / 600, 200)
    Next

    For i = horizon% To ymax '              the land
        Line (0, i)-(xmax, i), midInk~&(200, 200, 60, 45, 48, 0, (i - horizon%) / (ymax - horizon%), 255)
    Next
    For r = 400 To 331 Step -.25
        If r > 390 Then
            c~& = midInk~&(255, 50, 50, 255, 127, 100, 1 - ((r - 390) / 10), a)
        ElseIf r > 380 Then
            c~& = midInk~&(255, 127, 100, 255, 255, 0, 1 - ((r - 380) / 10), a)
        ElseIf r > 370 Then
            c~& = midInk~&(255, 255, 0, 100, 255, 100, 1 - ((r - 370) / 10), a)
        ElseIf r > 360 Then
            c~& = midInk~&(100, 255, 100, 0, 255, 255, 1 - ((r - 360) / 10), a)
        ElseIf r > 350 Then
            c~& = midInk~&(0, 255, 255, 100, 100, 255, 1 - ((r - 350) / 10), a)
        ElseIf r > 340 Then
            c~& = midInk~&(100, 100, 255, 75, 0, 230, 1 - ((r - 340) / 10), a)
        Else
            c~& = midInk~&(75, 0, 230, 248, 0, 211, 1 - ((r - 330) / 10), a)
        End If

        drawArc 400, horizon% + 50, r, _Pi, _Pi, c~&
    Next
    _Display
    ' _Limit 100
Next
Sleep

' 2025-05-03 Modified MidInk~& to control Alpha out put
' blend 2 colors according to fractional distance of 2nd to first color
Function midInk~& (r1%, g1%, b1%, r2%, g2%, b2%, fr##, A%)
    midInk~& = _RGB32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##, A%)
End Function

Sub FC3 (cx As Long, cy As Long, r As Long, clr~&) ' fill circle #3 mod
    Dim As Long r2, x, y ' for Option _Explicit
    If r < 1 Then Exit Sub
    Line (cx - r, cy)-(cx + r, cy), clr~&, BF
    r2 = r * r
    Do
        y = y + 1
        x = Sqr(r2 - y * y)
        Line (cx - x, cy + y)-(cx + x, cy + y), clr~&, BF
        Line (cx - x, cy - y)-(cx + x, cy - y), clr~&, BF
    Loop Until y = r
End Sub

Sub drawArc (xc, yc, radius, rStart, rMeasure, colr As _Unsigned Long)
    ' xc, yc Center for arc circle
    ' rStart is the Radian Start Angle, use _D2R for conversion from Degrees to Radians
    ' rMeasure is the measure of Arc in Radain units, use _D2R for conversion from Degrees to Radians
    ' Arc will start at rStart and go clockwise around for rMeasure Radians

    Dim rEnd, stepper, a, x, y

    rEnd = rStart + rMeasure
    stepper = 1 / radius ' the bigger the radius the smaller  the steps
    For a = rStart To rEnd Step stepper
        x = xc + radius * Cos(a)
        y = yc + radius * Sin(a)
        If a > rStart Then Line -(x, y), colr Else PSet (x, y), colr
    Next
End Sub

   

Its very important to get your rainbows right Smile
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Messages In This Thread
RE: Drawing Tools Subs or Functions with Demo - by bplus - 05-03-2025, 02:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Dialog Tools bplus 4 1,467 02-18-2025, 12:18 AM
Last Post: bplus
  Item$ Tools for Getting Strings to Behave Like Arrays bplus 1 928 02-05-2024, 01:14 AM
Last Post: bobalooie

Forum Jump:


Users browsing this thread: 1 Guest(s)