Basically I need to make something that is sort of like the Color picker because - well I use an IDE that DOESNT have “Insert Color” as one of its tools (go figure)
So I quickly write a Xojo app (yeah yeah) and had it do RGB colors and automatically just puts whatever color you change the slider to on the clipboard so its “select color go back to other IDE & paste”
That works dandy
Then I though “Gee I should make an HSV picker as well since its a lt more visual in terms of the colors etc.”
And the ever famous “How hard can that be ?”
Well the initial code to draw the color wheel - icky but decently quick
And even after hand tweaking code & moving things out of the loops I could etc its still not fast
Even with compiling using agressive - not super fast
Fast enough to not be totally annoying but not as fast was it might be
So the quest is a way, on macOS to draw using HSV colors the color wheel
I have two sliders on the page
sliderAlphaHSV live scrolling on min = 0 max = 255
sliderValue live scrolling on min = 0 max = 100
Any takers on making this code super fast ?
the one parameter it takes is a picture created as
p = new picture( 200, 200)
everything else should be local
tried to make it faster by drawing 8 points each pass but not sure that helped or not
Protected Sub DrawHSV(p as picture)
#Pragma NilObjectChecking False
#Pragma BackgroundTasks False
#Pragma BoundsChecking False
#Pragma StackOverflowChecking False
Dim g As graphics = p.graphics
g.ClearRect 0, 0, g.width, g.height
Const drawLabels = False
Const Pi = 3.14159
Const maxDegrees = 45
Dim toRadValue As Double = pi/180
Dim maxRadius As Integer = (g.width/2) - (.1 * (g.width/2) )
Dim xpos As Double = g.width / 2
Dim ypos As Double = g.height / 2
Dim alphaValue As Integer = sliderAlphaHSV.value
Dim colorValue As Double = sliderValue.value / sliderValue.Maximum
For saturation As Integer = 0 To maxRadius
Dim osize As Double = Max(1, .1 * saturation)
Dim satValue As Double = saturation / maxRadius
For hue As Integer = 0 To maxDegrees
Dim tmpHueQ1a As Double = hue
Dim tmpHueQ1b As Double = tmpHueQ1a + 45
Dim tmpHueQ2a As Double = tmpHueQ1b + 45
Dim tmpHueQ2b As Double = tmpHueQ2a + 45
Dim tmpHueQ3a As Double = tmpHueQ2b + 45
Dim tmpHueQ3b As Double = tmpHueQ3a + 45
Dim tmpHueQ4a As Double = tmpHueQ3b + 45
Dim tmpHueQ4b As Double = tmpHueQ4a + 45
Dim xoffs As Double
Dim yoffs As Double
xoffs = Cos(tmpHueQ1a*toRadValue) * saturation
yoffs = Sin(tmpHueQ1a*toRadValue) * saturation
' |
' |
' ----|----
' | 1a
' |
g.ForeColor = HSV( tmpHueQ1a / 360 , satValue , colorValue, alphaValue )
g.FillOval xpos + xoffs, ypos + yOffs , osize, osize
If drawLabels And saturation = maxRadius Then
g.forecolor = &cffffff
g.DrawString Str(tmpHueQ1a), xpos + xoffs, ypos + yOffs
End If
' |
' |
' ----|----
' |
' 2a|
g.ForeColor = HSV( tmpHueQ2a / 360 , satValue , colorValue, alphaValue )
g.FillOval xpos - yoffs, ypos + xOffs , osize, osize
If drawLabels And saturation = maxRadius Then
g.forecolor = &cffffff
g.DrawString Str(tmpHueQ2a), xpos - yoffs, ypos + xOffs
End If
' |
' 3a |
' ----|----
' |
' |
g.ForeColor = HSV( tmpHueQ3a / 360 , satValue , colorValue, alphaValue )
g.FillOval xpos - xoffs, ypos - yOffs , osize, osize
If drawLabels And saturation = maxRadius Then
g.forecolor = &cffffff
g.DrawString Str(tmpHueQ3a), xpos - xoffs, ypos - yOffs
End If
' |4a
' |
' ----|----
' |
' |
g.ForeColor = HSV( tmpHueQ4a / 360 , satValue , colorValue, alphaValue )
g.FillOval xpos + yoffs, ypos - xOffs , osize, osize
If drawLabels And saturation = maxRadius Then
g.forecolor = &cffffff
g.DrawString Str(tmpHueQ4a), xpos + yoffs, ypos - xOffs
End If
' |
' |
' ----|----
' |
' |1b
xoffs = Cos(tmpHueQ1b*pi/180) * saturation
yoffs = Sin(tmpHueQ1b*pi/180) * saturation
g.ForeColor = HSV( tmpHueQ1b / 360 , satValue , colorValue, alphaValue )
g.FillOval xpos + xoffs, ypos + yOffs , osize, osize
If drawLabels And saturation = maxRadius Then
g.forecolor = &cffffff
g.DrawString Str(tmpHueQ1b), xpos + xoffs, ypos + yOffs
End If
' |
' |
' ----|----
' 2b |
' |
g.ForeColor = HSV( tmpHueQ2b / 360 , satValue , colorValue, alphaValue )
g.FillOval xpos - yoffs, ypos + xOffs , osize, osize
If drawLabels And saturation = maxRadius Then
g.forecolor = &cffffff
g.DrawString Str(tmpHueQ2b), xpos - yoffs, ypos + xOffs
End If
' 3b|
' |
' ----|----
' |
' |
g.ForeColor = HSV( tmpHueQ3b / 360 , satValue , colorValue, alphaValue )
g.FillOval xpos - xoffs, ypos - yOffs , osize, osize
If drawLabels And saturation = maxRadius Then
g.forecolor = &cffffff
g.DrawString Str(tmpHueQ3b), xpos - xoffs, ypos - yOffs
End If
' |
' | 4b
' ----|----
' |
' |
g.ForeColor = HSV( tmpHueQ4b / 360 , satValue , colorValue, alphaValue )
g.FillOval xpos + yoffs, ypos - xOffs , osize, osize
If drawLabels And saturation = maxRadius Then
g.forecolor = &cffffff
g.DrawString Str(tmpHueQ4b), xpos + yoffs, ypos - xOffs
End If
Next
Next
End Sub