Last active
April 26, 2020 06:42
-
-
Save nonkit/55e66434383e3c0ea65793b1c69b6fae to your computer and use it in GitHub Desktop.
Small Basic Pseudo Color Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Color_Blacken | |
' Color | Blacken given color | |
' param c - given color | |
' param rate - 0..1 | |
' return c - color blackened | |
Color_NameToColor() | |
Color_ColorToRGB() | |
r = Math.Floor(r * (1 - rate)) | |
g = Math.Floor(g * (1 - rate)) | |
b = Math.Floor(b * (1 - rate)) | |
c = GraphicsWindow.GetColorFromRGB(r, g, b) | |
EndSub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Color_ColorToRGB | |
' Color | convert color To RGB values | |
' param c - "#rrggbb" (hexadecimal values) | |
' return r, g, b - RGB values 0..255 | |
If Text.GetLength(c) = 9 Then | |
_alpha = 2 | |
Else | |
_alpha = 0 | |
EndIf | |
hex = Text.GetSubText(c, _alpha + 2, 2) | |
Math_Hex2Dec() | |
r = dec | |
hex = Text.GetSubText(c, _alpha + 4, 2) | |
Math_Hex2Dec() | |
g = dec | |
hex = Text.GetSubText(c, _alpha + 6, 2) | |
Math_Hex2Dec() | |
b = dec | |
EndSub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Color_NameToColor | |
' Color | convert color name to color | |
' param c - color name | |
' returns c -"#rrggbb" | |
If Text.StartsWith(c, "#") And 6 < Text.GetLength(c) Then | |
c = Text.ConvertToUpperCase(c) | |
Else | |
Stack.PushValue("local", GraphicsWindow.PenColor) | |
GraphicsWindow.PenColor = c | |
c = GraphicsWindow.PenColor | |
GraphicsWindow.PenColor = Stack.PopValue("local") | |
EndIf | |
EndSub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Color_PercentToRGB | |
' Color | convert percent to RGB | |
' param percent - percent | |
' param color[] - color table indexed percent | |
' param n - item count of color[] | |
' param index[] - all indices of color[] | |
For i = 1 To n | |
p1 = index[i] | |
If index[i] = percent Then | |
p2 = index[i] | |
i = n + 1 ' exit For | |
ElseIf index[i] < percent And percent < index[i + 1] Then | |
p2 = index[i + 1] | |
i = n + 1 ' exit For | |
EndIf | |
EndFor | |
c = color[p1] | |
Color_ColorToRGB() | |
If p1 <> p2 Then | |
r1 = r | |
g1 = g | |
b1 = b | |
c = color[p2] | |
Color_ColorToRGB() | |
r2 = r | |
g2 = g | |
b2 = b | |
r = Math.Floor(r1 + (r2 - r1) * (percent - p1) / (p2 - p1)) | |
g = Math.Floor(g1 + (g2 - g1) * (percent - p1) / (p2 - p1)) | |
b = Math.Floor(b1 + (b2 - b1) * (percent - p1) / (p2 - p1)) | |
EndIf | |
EndSub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Color_Whiten | |
' Color | Whiten given color | |
' param c - given color | |
' param rate - 0..1 | |
' return c - color whitened | |
Color_NameToColor() | |
Color_ColorToRGB() | |
r = 255 - Math.Floor((255 - r) * (1 - rate)) | |
g = 255 - Math.Floor((255 - g) * (1 - rate)) | |
b = 255 - Math.Floor((255 - b) * (1 - rate)) | |
c = GraphicsWindow.GetColorFromRGB(r, g, b) | |
EndSub |
Color_Blacken()
is useful for shading.
Changed to use c
instead of color
in Color_Blacken()
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Workaround
Color_ColorToRGB()
for Silverlight.