Jump to content

Some Color blending


Recommended Posts

Hiya!

I'm experimenting some with AutoIt now, and I would like to know how to do some color blending.

I need to start with like 2 variables, "StartColor" and "EndColor", basicly from color, blend to EndColor.

I know that the total steps is 315.

This is the script im using, it totally fails right now. The reason? I have no clue where to start. :(

HotKeySet("{ESC}", "_Exit")

Global $A = 375
Global $B = 275
Global $R = 200
Global $Angle = 0
Global $Pi = 3.14
Global $Draw = True
Global $StartColor = 0x000000
Global $EndColor = 0xFF0000
Global $Color
Global $objNum = 0

$GUI = GUICreate("", 800, 600)
$obj = GUICtrlCreateLabel("", 10, 580, 15, 15)
$Label = GUICtrlCreateLabel("", 10, 500, 200, 100)

GUISetState()
While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    EndSwitch

    $Angle += 0.02
    $X = Round($R * Sin($Angle), 0)
    $Y = Round($R * Cos($Angle), 0)
    
    If $Angle > $Pi * 2 Then
        $Angle = 0
        Draw()
        $Draw = False
    EndIf
    
    GUICtrlSetPos($obj, $X + $A, $Y + $B)
    Draw()
    GUICtrlSetData($Label, "Angle:      " & Round($Angle, 2) & @CRLF & _
                            "X Raw:     " & $X & @CRLF & _
                            "Y Raw:     " & $Y & @CRLF & _
                            "X Add:     " & $X + $A & @CRLF & _
                            "Y Add:     " & $Y + $B & @CRLF & _
                            "Color:     " & "0x" & Hex($Color, 6) & @CRLF & _
                            "objNum:        " & $objNum)
    Sleep(50)
WEnd

Func Draw()
    If $Draw Then
        $Color += $EndColor
        ; Do something with $Color
        GUICtrlCreateLabel("", $X + $A, $Y + $B, 15, 15)
        GUICtrlSetBkColor(-1, "0x" & Hex($Color, 6))
        $objNum += 1
    EndIf
EndFunc


Func _Exit()
    Exit
EndFunc

Where should I start, or does anyone eventually has an example for me?

AlmarM :mellow:

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

  • Moderators

AlmarM,

Here is your script modified a bit to show how i would go about getting the colours to change as you go round. I think the comments are clear enough: :mellow:

#Include <Color.au3>

HotKeySet("{ESC}", "_Exit")

Global $A = 375
Global $B = 275
Global $R = 200
Global $Angle = 0
Global $Pi = 3.14159265358979
Global $Draw = True
Global $StartColor = 0x805060
Global $EndColor = 0xFFA070
Global $sColor = $StartColor
Global $objNum = 0

; Get colour elements for StartColor
$iStartRed = _ColorGetRed($StartColor)
$nRed = $iStartRed
$iStartGreen = _ColorGetGreen($StartColor)
$nGreen = $iStartGreen
$iStartBlue = _ColorGetBlue($StartColor)
$nBlue = $iStartBlue

; Get colour elements for EndColor
$iEndRed = _ColorGetRed($EndColor)
$iEndGreen = _ColorGetGreen($EndColor)
$iEndBlue = _ColorGetBlue($EndColor)

; Determine delta to add to each colour at each iteration (set at 360)
$nDeltaRed = ($iEndRed - $iStartRed) / 360
$nDeltaGreen = ($iEndGreen - $iStartGreen) / 360
$nDeltaBlue = ($iEndBlue - $iStartBlue) / 360

$GUI = GUICreate("", 800, 600)
$obj = GUICtrlCreateLabel("", 10, 580, 15, 15)
$Label = GUICtrlCreateLabel("", 10, 500, 200, 100)

GUISetState()
Do
    Switch GUIGetMsg()
    Case -3
        Exit
    EndSwitch

    $Angle += 2 * $Pi / 360 ; 360 iterations
    $X = Round($R * Sin($Angle), 0)
    $Y = Round($R * Cos($Angle), 0)

    GUICtrlSetPos($obj, $X + $A, $Y + $B)

    Draw()

    GUICtrlSetData($Label, "Angle:      " & Round($Angle, 2) & @CRLF & _
                            "X Raw:     " & $X & @CRLF & _
                            "Y Raw:     " & $Y & @CRLF & _
                            "X Add:     " & $X + $A & @CRLF & _
                            "Y Add:     " & $Y + $B & @CRLF & _
                            "Color:     " & "0x" & Hex($sColor, 6) & @CRLF & _
                            "objNum:        " & $objNum)
    Sleep(50)
Until $Angle > 2 * $Pi ; Full circle reached

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

Func Draw()

    ; Add delta to each colour element
    $nRed += $nDeltaRed
    $nGreen += $nDeltaGreen
    $nBlue += $nDeltaBlue
    ; Construct colour
    $sColor = "0x" & Hex(Int($nRed), 2) & Hex(Int($nGreen), 2) & Hex(Int($nBlue), 2)
    GUICtrlCreateLabel("", $X + $A, $Y + $B, 15, 15)
    GUICtrlSetBkColor(-1, $sColor)
    $objNum += 1

EndFunc


Func _Exit()
    Exit
EndFunc

You might also want to look at Yashied's WinAPIEx.au3 UDF - it has some nice gradient functions which take away all of the hard work! :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...