So why is the color change "permanent"?
#1
In the sample program attached I use a function to brighten the color of drawn elements. I noticed the color change is permanent even though I am not returning the color value to the color handle itself. Am I doing this wrong  or is there something buggy in how color handles are passed that I don't understand? I figured out a work arround for the situation but I don't care for it.  Any suggestions of comments would be welcome.

Code: (Select All)
Sc& = _NewImage(800, 500, 32)
Screen Sc&
Dim klr&, klr2&, klr3&

klr& = _RGB(27, 27, 128)
klr2& = _RGB(27, 27, 128)
klr3& = _RGB(150, 26, 28)

For n = 1 To 40
    Cls
    _Limit 20
    klr& = _RGB(27, 27, 128) 'if this line is commented out the color is permanently changed by the brighter function
    orb 400, 250, n * 2, klr&, 1.5
    ' klr2& = _RGB(128, 227, 128)   this one is commented out to show what would happen as above
    orb 200, 250, n * 2, klr2&, 1.5
    klr3& = _RGB(227, 26, 28) 'comment this out and the color changes
    orb 600, 250, 40, klr3&, 7 'an orb that is the same size to serve as an example without the scaling to distract with the viewer
    _Display
Next n


Function brighter& (ch&&, p)
    r = _Red(ch&&)
    b = _Blue(ch&&)
    g = _Green(ch&&)

    If p < 0 Then p = 0
    If p > 100 Then p = 100
    p = p / 100
    rdif = 255 - r: rc = rdif * p: brr = Int(r + rc): If brr > 255 Then brr = 255
    gdif = 255 - g: gc = gdif * p: bgg = Int(g + gc): If bgg > 255 Then bgg = 255
    bdif = 255 - b: bc = bdif * p: bbb = Int(b + bc): If bbb > 255 Then bbb = 255
    brighter& = _RGB(brr, bgg, bbb)
End Function

Sub orb (XX As Long, YY As Long, Rd As Long, KK As Long, brt As Integer)
    'for false shaded 3-D look
    'XX,YY arer screen position Rd is outermost radius of the orb KK is the startign color
    'brt is the factor by which color will chnage it is the diffeence from KK to RGB(255,255,255)
    'brt is applied each step so your orb will go to white if it is large or the brt value is high
    ps = _Pi
    p3 = _Pi / 3
    p4 = _Pi / 4
rdc = p4 / Rd
    If Rd < 10 Then ps = _Pi / 3 'so small radius orbs look cool too
    For c = 0 To Int(Rd * .87) Step ps
        KK = brighter&(KK, brt)
        CircleFill XX, YY, Rd - (c), KK
        XX = XX + rdc * (c * p3) ' could be fiddled with to move the center of the gradient
        YY = YY - rdc * (c * 2 * p4) ' could be fiddled with to move the center of the gradient
    Next c
End Sub

Sub CircleFill (CX As Long, CY As Long, R As Long, C As Long)
    'sub by SMcNeill makes a filled circle without worrying about using the paint command to fill an empty circle
    Dim Radius As Long, RadiusError As Long
    Dim X As Long, Y As Long

    Radius = Abs(R)
    RadiusError = -Radius
    X = Radius
    Y = 0

    If Radius = 0 Then PSet (CX, CY), C: Exit Sub

    ' Draw the middle span here so we don't draw it twice in the main loop,
    ' which would be a problem with blending turned on.
    Line (CX - X, CY)-(CX + X, CY), C, BF

    While X > Y
        RadiusError = RadiusError + Y * 2 + 1
        If RadiusError >= 0 Then
            If X <> Y + 1 Then
                Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
                Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
            End If
            X = X - 1
            RadiusError = RadiusError - X * 2
        End If
        Y = Y + 1
        Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
        Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
    Wend

End Sub
Reply


Messages In This Thread
So why is the color change "permanent"? - by James D Jarvis - 04-24-2022, 01:55 PM



Users browsing this thread: 5 Guest(s)