Hey,
da mir vorhin etwas langweilig gewesen war, habe ich mal eine Ampelsteuerung geskriptet. Ich weiß, dass man noch einen großen Teil im Switch vereinfachen kann, dazu hatte ich aber bisher keine Lust.
Skript:
Spoiler anzeigen
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $a_colors[6] = ['0xFF0000','0xFFFF00','0x00FF00','0xDEDEDE', '0xE8E8E8','0x000'] ; red - amber - green - grey , dif grey - black
Global $a_lights[1][3][2]
Global $a_status[4][3] = [[1,0,0],[1,1,0],[0,0,1],[0,1,0]] ; red / amber-red / green / amber
Global $a_status_txt[4] = ['red','red-amber','green','amber']
Global $a_gui_size[2] = [500,500]
ConsoleWrite("__________________" & @CRLF & "Traffic Light Control" & @CRLF & ">> Jautois - Feb, 19, 2011" & @CRLF & @CRLF)
[/autoit] [autoit][/autoit] [autoit]$hWindow = GUICreate("Traffic Lights Control - Jautois", $a_gui_size[0],$a_gui_size[1])
GUISetBkColor(0x000000)
_CreateTrafficLight(230,350,0)
_CreateTrafficLight(300,200,1)
_CreateTrafficLight(230,50,2)
_CreateTrafficLight(100,200,3)
_InitLights()
GUISetState(@SW_SHOW)
_StartLoop()
[/autoit] [autoit][/autoit] [autoit]Func _InitLights()
; Light 1
_TurnTrafficLightToColor(0,2)
_TurnTrafficLightToColor(2,2)
; Light 2
_TurnTrafficLightToColor(1,0)
_TurnTrafficLightToColor(3,0)
EndFunc
Func _StartLoop()
; Light 1
_TurnTrafficLightToColor(0,2) ; green
_TurnTrafficLightToColor(2,2)
; Light 2
_TurnTrafficLightToColor(1,0) ; red
_TurnTrafficLightToColor(3,0)
Sleep(5000)
; Light 1
_TurnTrafficLightToColor(0,3) ; amber
_TurnTrafficLightToColor(2,3)
Sleep(2000)
; Light 1
_TurnTrafficLightToColor(0,0) ; red
_TurnTrafficLightToColor(2,0)
Sleep(2000)
; Light 2
_TurnTrafficLightToColor(1,1) ; amber - red
_TurnTrafficLightToColor(3,1)
Sleep(2000)
; Light 2
_TurnTrafficLightToColor(1,2) ; green
_TurnTrafficLightToColor(3,2)
Sleep(5000)
; Light 2
_TurnTrafficLightToColor(1,3) ; amber
_TurnTrafficLightToColor(3,3)
Sleep(2000)
; Light 2
_TurnTrafficLightToColor(1,0) ; red
_TurnTrafficLightToColor(3,0)
Sleep(2000)
; Light 1
_TurnTrafficLightToColor(0,1) ; amber - red
_TurnTrafficLightToColor(2,1)
Sleep(2000)
; Light 1
_TurnTrafficLightToColor(0,0)
_TurnTrafficLightToColor(2,0)
_StartLoop()
EndFunc
Func _TurnTrafficLightToColor($light_nr,$status)
For $i = 0 to 2
If $a_status[$status][$i] = 1 Then
GUICtrlSetState($a_lights[$light_nr][$i][1],$GUI_SHOW)
Else
GUICtrlSetState($a_lights[$light_nr][$i][1],$GUI_HIDE)
EndIf
Next
ConsoleWrite(">> Light: " & $light_nr & " turned to " & $a_status_txt[$status] & "!" & @CRLF)
EndFunc
Func _CreateTrafficLight( $x, $y, $direction = 0)
ReDim $a_lights[UBound($a_lights,1)+1][3][2]
Local $index = (UBound($a_lights,1)-1)-1
[/autoit] [autoit][/autoit] [autoit]Switch $direction
Case 0 ; up
$cont_y = 80
GUICtrlCreateGraphic($x, $y)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[3],$a_colors[3])
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 40, 100)
$Label1 = GUICtrlCreateLabel("Nr. " & $index, $x ,$y+100, 80, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
For $i = 0 to 2
$new_x = 5+ $x
$new_y = 5+ $y +(30*$i)
$a_lights[$index][$i][0] = GUICtrlCreateGraphic($new_x, $new_y)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[3])
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0,0, 30, 30)
$a_lights[$index][$i][1] = GUICtrlCreateGraphic($new_x, $new_y)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[$i])
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0,0, 30, 30)
Next
Case 1 ; right
$cont_x = 80
GUICtrlCreateGraphic( $x, $y)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[3],$a_colors[3])
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0,0,100,40)
$Label1 = GUICtrlCreateLabel("Nr. " & $index, $x+105 ,$y, 80, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
For $i = 0 to 2
$new_x = 5+ $x +(30*$i)
$new_y = 5+ $y
$a_lights[$index][$i][0] = GUICtrlCreateGraphic( $new_x, $new_y)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[3])
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0, 0, 30, 30)
$a_lights[$index][$i][1] = GUICtrlCreateGraphic( $new_x, $new_y)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[$i])
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0,0, 30, 30)
Next
Case 2 ; down
$cont_y = 80
GUICtrlCreateGraphic($x, $y)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[3],$a_colors[3])
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 40, 100)
$Label1 = GUICtrlCreateLabel("Nr. " & $index, $x ,$y-24, 80, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
For $i = 0 to 2
$new_x = 5+ $x
$new_y = 5+ $y -(30*$i) +60
$a_lights[$index][$i][0] = GUICtrlCreateGraphic($new_x, $new_y)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[3])
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0,0, 30, 30)
$a_lights[$index][$i][1] = GUICtrlCreateGraphic($new_x, $new_y)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[$i])
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0,0, 30, 30)
Next
Case 3 ; left
$cont_x = 80
GUICtrlCreateGraphic( $x, $y)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[3],$a_colors[3])
GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0,0,100,40)
$Label1 = GUICtrlCreateLabel("Nr. " & $index, $x-40 ,$y, 40, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
For $i = 0 to 2
$new_x = 5+ $x -(30*$i) + 60
$new_y = 5+ $y
$a_lights[$index][$i][0] = GUICtrlCreateGraphic( $new_x, $new_y)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[3])
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0, 0, 30, 30)
$a_lights[$index][$i][1] = GUICtrlCreateGraphic( $new_x, $new_y)
GUICtrlSetStyle(-1, $SS_NOTIFY)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[$i])
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0,0, 30, 30)
Next
EndSwitch
ConsoleWrite("+> Light: " & $index & " created!" & @CRLF)
EndFunc ;==>CreateChild
Das ganze sieht dann so aus:
[Blockierte Grafik: http://www7.pic-upload.de/20.02.11/8unx78vxkp4.gif]