adamski Posted December 17, 2008 Share Posted December 17, 2008 (edited) Is there a way to have a gradient box with four colours, one at each corner? Eg. Red------Green |..............| |..............| |..............| |..............| Blue-------Black Or: Black-----Green |..............| |..............| |..............| |..............| Black------White Can a linear gradient have multiple colours? Eg. Red-------Green--------Blue------Red I have searched the forum but only found 2 colour gradients. Thanks Edited December 17, 2008 by adamski Link to comment Share on other sites More sharing options...
James Posted December 17, 2008 Share Posted December 17, 2008 (edited) GDI. Go search it - yes I know you did, but try work from there. Edited December 17, 2008 by JamesBrooks Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
weaponx Posted December 17, 2008 Share Posted December 17, 2008 GDI+LinearGradientBrushLinearGradientBrush::SetInterpolationColors Link to comment Share on other sites More sharing options...
adamski Posted December 17, 2008 Author Share Posted December 17, 2008 I got the multicolour linear part working. I kinda got something with the 4 corner colour but it is slow and not correct. expandcollapse popup; MAIN PROGRAM #include <Color.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Global Const $G_VERTICAL = 1 Global Const $G_HORIZONTAL = 2 Const $GUI_Width = 500 Const $GUI_Height = 500 Const $BTN_Width = 80 Const $BTN_Height = 40 Dim $Red = 0xff0000 Dim $Yellow = 0xffff00 Dim $Green = 0x00ff00 Dim $Cyan = 0x00ffff Dim $Blue = 0x0000ff Dim $Magenta = 0xff00ff Dim $Black = 0x000000 Dim $White = 0xffffff Dim $Purple = 0x800080 Dim $ColoursArray[7] $ColoursArray[0] = $Red $ColoursArray[1] = $Yellow $ColoursArray[2] = $Green $ColoursArray[3] = $Cyan $ColoursArray[4] = $Blue $ColoursArray[5] = $Magenta $ColoursArray[6] = $Red Dim $ColoursArray2[3] $ColoursArray2[0] = $Purple $ColoursArray2[1] = $Yellow $ColoursArray2[2] = $Purple Dim $ColoursArray3[4] $ColoursArray3[0] = $Red $ColoursArray3[1] = $Green $ColoursArray3[2] = $White $ColoursArray3[3] = $Black Dim $Button_1,$Button_2,$Button_3,$Button_4 $GUI_WIN = CreateWindow() _GUICtrlCreateGradientMultiColor($ColoursArray2, 0, 0, $GUI_Width,$GUI_Height,$G_HORIZONTAL) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $Button_1 ExitLoop Case $msg = $Button_2 GUIDelete($GUI_WIN) $GUI_WIN = CreateWindow() _GUICtrlCreateGradientFourColorBox($ColoursArray3, 0, 0, $GUI_Width,$GUI_Height,$G_HORIZONTAL) GUISetState() Case $msg = $Button_3 GUIDelete($GUI_WIN) $GUI_WIN = CreateWindow() _GUICtrlCreateGradientMultiColor($ColoursArray, 0, 0, $GUI_Width,$GUI_Height,$G_HORIZONTAL) GUISetState() Case $msg = $Button_4 GUIDelete($GUI_WIN) $GUI_WIN = CreateWindow() _GUICtrlCreateGradientMultiColor($ColoursArray, 0, 0, $GUI_Width,$GUI_Height,$G_VERTICAL) GUISetState() Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect Wend Func CreateWindow() $hwnd = GuiCreate("Gradient Demo", $GUI_Width, $GUI_Height,(@DesktopWidth-$GUI_Width)/2, (@DesktopHeight-$GUI_Height)/2 , $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS) $Button_1 = GuiCtrlCreateButton("Exit", $GUI_Width - ($BTN_Width + 20), $GUI_Height - ($BTN_Height + 20), $BTN_Width, $BTN_Height) $Button_2 = GuiCtrlCreateButton("4 Colour", 10, $GUI_Height - ($BTN_Height + 120), $BTN_Width, $BTN_Height) $Button_3 = GuiCtrlCreateButton("Horizontal", 10, $GUI_Height - ($BTN_Height + 70), $BTN_Width, $BTN_Height) $Button_4 = GuiCtrlCreateButton("Vertical", 10, $GUI_Height - ($BTN_Height + 20), $BTN_Width, $BTN_Height) Return $hwnd EndFunc Func _GUICtrlCreateGradientMultiColor($ColoursArray, $nX, $nY, $nWidth, $nHeight, $n_type = $G_VERTICAL) Local $nColors Local $colorR, $colorG, $colorB Local $nStepR, $nStepG, $nStepB $nColors = UBound($ColoursArray) - 1 If($n_type == $G_VERTICAL) Then For $x = 0 To $nColors - 1 GuiCtrlCreateGraphic($nX + ($x)*($nWidth/$nColors), $nY, $nWidth / $nColors, $nHeight) $colorR = _ColorGetRed($ColoursArray[$x]) $colorG = _ColorGetGreen($ColoursArray[$x]) $colorB = _ColorGetBlue($ColoursArray[$x]) $nStepR = (_ColorGetRed($ColoursArray[$x+1]) - $colorR) / ($nWidth / $nColors) $nStepG = (_ColorGetGreen($ColoursArray[$x+1]) - $colorG) / ($nWidth / $nColors) $nStepB = (_ColorGetBlue($ColoursArray[$x+1]) - $colorB) / ($nWidth / $nColors) For $i = 0 To $nWidth / $nColors $sColor = "0x" & StringFormat("%02X%02X%02X", $colorR+$nStepR*$i, $colorG+$nStepG*$i, $colorB+$nStepB*$i) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xffffff) GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $i, 0) GUICtrlSetGraphic(-1, $GUI_GR_LINE, $i, $nHeight) Next Next ElseIf($n_type == $G_HORIZONTAL) Then For $x = 0 To $nColors - 1 GuiCtrlCreateGraphic($nX, $nY + ($x)*($nHeight / $nColors), $nWidth / $nColors, $nHeight) $colorR = _ColorGetRed($ColoursArray[$x]) $colorG = _ColorGetGreen($ColoursArray[$x]) $colorB = _ColorGetBlue($ColoursArray[$x]) $nStepR = (_ColorGetRed($ColoursArray[$x+1]) - $colorR) / ($nWidth / $nColors) $nStepG = (_ColorGetGreen($ColoursArray[$x+1]) - $colorG) / ($nWidth / $nColors) $nStepB = (_ColorGetBlue($ColoursArray[$x+1]) - $colorB) / ($nWidth / $nColors) For $i = 0 To $nHeight / $nColors $sColor = "0x" & StringFormat("%02X%02X%02X", $colorR+$nStepR*$i, $colorG+$nStepG*$i, $colorB+$nStepB*$i) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xffffff) GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i) GUICtrlSetGraphic(-1, $GUI_GR_LINE, $nWidth, $i) Next Next EndIf EndFunc Func _GUICtrlCreateGradientFourColorBox($ColoursArray, $nX, $nY, $nWidth, $nHeight, $n_type = $G_VERTICAL) Local $nColors ;~ Local $amountA, $amountB, $amountC, $amountD Local $distanceA, $distanceB, $distanceC, $distanceD Local $pixelR, $pixelB, $pixelG $nColors = UBound($ColoursArray) If $nColors = 4 Then Local $colorAR = _ColorGetRed($ColoursArray[0]) Local $colorAG = _ColorGetGreen($ColoursArray[0]) Local $colorAB = _ColorGetBlue($ColoursArray[0]) Local $colorBR = _ColorGetRed($ColoursArray[1]) Local $colorBG = _ColorGetGreen($ColoursArray[1]) Local $colorBB = _ColorGetBlue($ColoursArray[1]) Local $colorCR = _ColorGetRed($ColoursArray[2]) Local $colorCG = _ColorGetGreen($ColoursArray[2]) Local $colorCB = _ColorGetBlue($ColoursArray[2]) Local $colorDR = _ColorGetRed($ColoursArray[3]) Local $colorDG = _ColorGetGreen($ColoursArray[3]) Local $colorDB = _ColorGetBlue($ColoursArray[3]) GuiCtrlCreateGraphic($nX, $nY, $nWidth, $nHeight) For $x = 0 To $nWidth For $y = 0 To $nHeight ;~ $amountA = (($nWidth/$nWidth)-($x/$nWidth))*(($nHeight/$nHeight)-($y/$nHeight)) ;~ $amountB = ($x/$nWidth)*(($nHeight/$nHeight)-($y/$nHeight)) ;~ $amountC = (($nWidth/$nWidth)-($x/$nWidth))*($y/$nHeight) ;~ $amountD = ($x/$nWidth)*($y/$nHeight) $distanceA = 1-(Sqrt($x^2 + $y^2)) / $nWidth $distanceB = 1-(Sqrt(($nWidth-$x)^2 + $y^2)) / $nWidth $distanceC = 1-(Sqrt($x^2 + ($nHeight-$y)^2)) / $nWidth $distanceD = 1-(Sqrt(($nWidth-$x)^2 + ($nHeight-$y)^2)) / $nWidth $pixelR = ($colorAR*$distanceA) + ($colorBR*$distanceB) + ($colorCR*$distanceC) + ($colorDR*$distanceD) $pixelG = ($colorAG*$distanceA) + ($colorBG*$distanceB) + ($colorCG*$distanceC) + ($colorDG*$distanceD) $pixelB = ($colorAB*$distanceA) + ($colorBB*$distanceB) + ($colorCB*$distanceC) + ($colorDB*$distanceD) $sColor = "0x" & StringFormat("%02X%02X%02X", $pixelR, $pixelG, $pixelB) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xffffff) GUICtrlSetGraphic(-1, $GUI_GR_PIXEL, $x, $y) Next Next EndIf EndFunc Link to comment Share on other sites More sharing options...
Kip Posted December 17, 2008 Share Posted December 17, 2008 AutoIt is slow. There's nothing you can do about it. MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
ProgAndy Posted December 17, 2008 Share Posted December 17, 2008 Maybe you want to look at this: http://www.autoitscript.com/forum/index.ph...mp;#entry551340and this: http://www.autoitscript.com/forum/index.php?showtopic=85481 *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
weaponx Posted December 17, 2008 Share Posted December 17, 2008 (edited) AutoIt is slow. There's nothing you can do about it.Sure there is. I posted the names of the two GDI+ functions that do this. There are even a few examples of the lineargradientbrush in the forum that do exactly what the OP wants. Edited December 17, 2008 by weaponx Link to comment Share on other sites More sharing options...
Kip Posted December 18, 2008 Share Posted December 18, 2008 I meant that there's nothing you can do about it that autoit is slow. MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now