Platforms to show: All Mac Windows Linux Cross-Platform

/Picture/Colorize


Required plugins for this example: MBS Picture Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Picture/Colorize

This example is the version from Wed, 13th Nov 2012.

Project "Colorize.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control GroupBox2 Inherits GroupBox
ControlInstance GroupBox2 Inherits GroupBox
End Control
Control sdAlphaHue Inherits Slider
ControlInstance sdAlphaHue Inherits Slider
EventHandler Sub ValueChanged() Action_Update() End EventHandler
End Control
Control sdAlphaSat Inherits Slider
ControlInstance sdAlphaSat Inherits Slider
EventHandler Sub ValueChanged() Action_Update() End EventHandler
End Control
Control sdAlphaLight Inherits Slider
ControlInstance sdAlphaLight Inherits Slider
EventHandler Sub ValueChanged() Action_Update() End EventHandler
End Control
Control LabelSatWall Inherits Label
ControlInstance LabelSatWall Inherits Label
End Control
Control LabelLightWall Inherits Label
ControlInstance LabelLightWall Inherits Label
End Control
Control LabelHueWall Inherits Label
ControlInstance LabelHueWall Inherits Label
End Control
Control rectSample Inherits Rectangle
ControlInstance rectSample Inherits Rectangle
End Control
Control lbGreen Inherits Label
ControlInstance lbGreen Inherits Label
End Control
Control lbBlue Inherits Label
ControlInstance lbBlue Inherits Label
End Control
Control rectOut Inherits Rectangle
ControlInstance rectOut(0) Inherits Rectangle
ControlInstance rectOut(1) Inherits Rectangle
ControlInstance rectOut(2) Inherits Rectangle
ControlInstance rectOut(3) Inherits Rectangle
ControlInstance rectOut(4) Inherits Rectangle
End Control
Control lbRed Inherits Label
ControlInstance lbRed Inherits Label
End Control
Control lbRed1 Inherits Label
ControlInstance lbRed1 Inherits Label
End Control
Control lbRed11 Inherits Label
ControlInstance lbRed11 Inherits Label
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End Control
Control Canvas2 Inherits Canvas
ControlInstance Canvas2 Inherits Canvas
End Control
EventHandler Sub Close() quit() End EventHandler
EventHandler Sub Open() logo = LogoMBS(250) canvas1.Backdrop = logo Action_Update() End EventHandler
Private Sub Action_Update() dim c, rbgHue as color dim hue, sat, light as double dim lightness as double hue = sdAlphaHue.value/100 //range 0-1 sat = sdAlphaSat.Value/100 //range 0-1 light = (sdAlphaLight.Value)/100 //range 0-1 //get selected color for sample display c = HSV(hue,sat,light) rectSample.FillColor = c //colorize the 5 swatches rbgHue = HSV(hue, 1, 1) //get RGB value of selected hue at full saturation and lightness lightness = light*2 - 1 //convert from 0-1 range to -1..1 range //Colorize 5 different grey scale values and display results on screen rectOut(0).FillColor = Colorize(&c00000, rbgHue, sat, lightness) rectOut(1).FillColor = Colorize(&c3F3F3F, rbgHue, sat, lightness) rectOut(2).FillColor = Colorize(&c7F7F7F,rbgHue, sat, lightness) rectOut(3).FillColor = Colorize(&cBFBFBF, rbgHue, sat, lightness) rectOut(4).FillColor = Colorize(&cFFFFFF, rbgHue, sat, lightness) canvas2.Backdrop = logo.ColorizeMBS(hue, sat, light) return End Sub
Property logo As Picture
Property Private pChair As Picture
Property Private pChairColorOverlay As Picture
Property Private pLocal As Picture
Property Private pWall As Picture
Property Private pWallColorOverlay As Picture
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Module Module1
Function Colorize(original as color, newColor as color, saturation as double, lightness as double) As color dim refColor as color dim orgLightness as double //Ranges... // saturation 0..1 // lightness -1..1 orgLightness = original.Value //get lightness value of original color refColor = blend2(RGB(128,128,128), newColor, saturation) //get colorizing color as mid-grey reference color if (lightness <= -1) then return &c000000 elseif (lightness >= 1) then return &cFFFFFF elseif (lightness >= 0) then return blend3(&c000000, refColor, &cFFFFFF, 2 * (1 - lightness) * (orgLightness - 1) + 1) else return blend3(&c000000, refColor, &cFFFFFF, 2 * (1 + lightness) * orgLightness - 1) end End Function
Private Function blend2(left as color, right as color, value as double) As color dim r,g,b as integer r = round(left.Red * (1-value) + right.Red * value) g = round(left.Green * (1-value) + right.Green * value) b = round(left.Blue * (1-value) + right.Blue * value) return rgb(r,g,b) End Function
Private Function blend3(left as color, main as color, right as color, value as double) As color if value < 0 then return blend2(left, main, value+1) elseif value > 0 then return blend2(main, right, value) else return main end End Function
End Module
End Project

The items on this page are in the following plugins: MBS Picture Plugin.


The biggest plugin in space...