Ampelsteuerung

  • 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
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    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]

    [/autoit] [autoit][/autoit] [autoit]

    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)

    [/autoit] [autoit][/autoit] [autoit]

    _StartLoop()

    [/autoit] [autoit][/autoit] [autoit]

    Func _InitLights()
    ; Light 1
    _TurnTrafficLightToColor(0,2)
    _TurnTrafficLightToColor(2,2)
    ; Light 2
    _TurnTrafficLightToColor(1,0)
    _TurnTrafficLightToColor(3,0)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _StartLoop()
    ; Light 1
    _TurnTrafficLightToColor(0,2) ; green
    _TurnTrafficLightToColor(2,2)

    [/autoit] [autoit][/autoit] [autoit]

    ; 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)

    [/autoit] [autoit][/autoit] [autoit]

    _StartLoop()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    ConsoleWrite(">> Light: " & $light_nr & " turned to " & $a_status_txt[$status] & "!" & @CRLF)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateTrafficLight( $x, $y, $direction = 0)
    ReDim $a_lights[UBound($a_lights,1)+1][3][2]

    [/autoit] [autoit][/autoit] [autoit]

    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)

    [/autoit] [autoit][/autoit] [autoit]

    $Label1 = GUICtrlCreateLabel("Nr. " & $index, $x ,$y+100, 80, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 2
    $new_x = 5+ $x
    $new_y = 5+ $y +(30*$i)

    [/autoit] [autoit][/autoit] [autoit]

    $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)

    [/autoit] [autoit][/autoit] [autoit]

    $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)

    [/autoit] [autoit][/autoit] [autoit]

    $Label1 = GUICtrlCreateLabel("Nr. " & $index, $x+105 ,$y, 80, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 2
    $new_x = 5+ $x +(30*$i)
    $new_y = 5+ $y

    [/autoit] [autoit][/autoit] [autoit]

    $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)

    [/autoit] [autoit][/autoit] [autoit]

    $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)

    [/autoit] [autoit][/autoit] [autoit]

    $Label1 = GUICtrlCreateLabel("Nr. " & $index, $x ,$y-24, 80, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 2
    $new_x = 5+ $x
    $new_y = 5+ $y -(30*$i) +60

    [/autoit] [autoit][/autoit] [autoit]

    $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)

    [/autoit] [autoit][/autoit] [autoit]

    $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)

    [/autoit] [autoit][/autoit] [autoit]

    $Label1 = GUICtrlCreateLabel("Nr. " & $index, $x-40 ,$y, 40, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 2
    $new_x = 5+ $x -(30*$i) + 60
    $new_y = 5+ $y

    [/autoit] [autoit][/autoit] [autoit]

    $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)

    [/autoit] [autoit][/autoit] [autoit]

    $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

    [/autoit] [autoit][/autoit] [autoit]

    ConsoleWrite("+> Light: " & $index & " created!" & @CRLF)
    EndFunc ;==>CreateChild

    [/autoit]

    Das ganze sieht dann so aus:
    [Blockierte Grafik: http://www7.pic-upload.de/20.02.11/8unx78vxkp4.gif]

    • Offizieller Beitrag

    Vom Ampelverhalten her korrekt. Vielleicht willst Du das Skript noch um Fussgängerampeln erweitern!?

    Diese Funktion wird aber nicht allzu lange laufen:

    Spoiler anzeigen
    [autoit]


    Func _StartLoop()
    ; Light 1
    _TurnTrafficLightToColor(0,2) ; green
    _TurnTrafficLightToColor(2,2)

    [/autoit] [autoit][/autoit] [autoit]

    ; 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)

    [/autoit] [autoit][/autoit] [autoit]

    _StartLoop()
    EndFunc

    [/autoit]


    Am Ende der Funktion rufst Du die Funktion erneut auf. In AutoIt gibt es aber kein GoTo (zum Glück) und dieser Aufruf stellt einen rekursiven Funktionsaufruf dar. Nach spätestens 5100 Aufrufen wird sich Dein Skript verabschieden (AutoIt-Limit für rekursive Aufrufe).
    Eine Do...Until- oder While...WEnd-Schleife wäre hier die richtige Wahl gewesen.

    Achja und eine Möglichkeit zum beenden des Skripts wäre auch ganz schön. ;)

  • Danke Oscar für die Anmerkungen. Fußgängerampeln sind nun eingebaut, die Schleife ist drinnen und das Skript lässt sich beenden.

    Screenshot:
    [Blockierte Grafik: http://www7.pic-upload.de/20.02.11/vocg246gfbj.png]

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    Global $a_colors[6] = ['0xFF0000','0xFFFF00','0x00FF00','0xDEDEDE', '0xE8E8E8','0x000'] ; red - amber - green - grey , dif grey - black
    Global $a_p_colors[2] = ['0xFF0000','0x00FF00']
    Global $a_lights[1][3][2]
    Global $a_p_lights[1][2][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_p_status[2][2] = [[1,0],[0,1]]
    Global $a_status_txt[4] = ['red','red-amber','green','amber']
    Global $a_gui_size[2] = [600,600]
    Global $strokes = 0.5

    [/autoit] [autoit][/autoit] [autoit]

    ConsoleWrite("__________________" & @CRLF & "Traffic Light Control" & @CRLF & ">> Jautois - Feb, 19, 2011" & @CRLF & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    $hWindow = GUICreate("Traffic Lights Control - Jautois - {ESC to Exit}", $a_gui_size[0],$a_gui_size[1],100,100)
    _CreateArea()
    _CreateTrafficLight(375,455,0)
    _CreateTrafficLight(455,195,1)
    _CreateTrafficLight(195,75,2)
    _CreateTrafficLight(75,375,3)

    [/autoit] [autoit][/autoit] [autoit]

    _CreatePedestrianLight(420,370,2)
    _CreatePedestrianLight(370,410,3)
    _CreatePedestrianLight(420,180,0)
    _CreatePedestrianLight(370,160,3)
    _CreatePedestrianLight(160,180,0)
    _CreatePedestrianLight(180,150,1)
    _CreatePedestrianLight(150,370,2)
    _CreatePedestrianLight(180,410,1)

    [/autoit] [autoit][/autoit] [autoit]

    _InitLights()
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

    [/autoit] [autoit][/autoit] [autoit]

    EndSwitch
    Sleep(100)
    _TrafficLightLoop()
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateArea()
    GUICtrlCreateGraphic(230, 0)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[5])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 140,600)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateGraphic(0, 230)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[5])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 600,140)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateGraphic(150, 300)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[3],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 5,70)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateGraphic(230, 150)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[3],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 70,5)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateGraphic(445, 230)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[3],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 5,70)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateGraphic(300, 445)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[3],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 70,5)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 13
    GUICtrlCreateGraphic(160, 363-($i*10))
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[3],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 60,5)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 13
    GUICtrlCreateGraphic(233+($i*10), 160)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[3],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 5,60)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 13
    GUICtrlCreateGraphic(380, 233+($i*10))
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[3],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 60,5)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 13
    GUICtrlCreateGraphic(233+($i*10), 380)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[3],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 5,60)
    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _ConnectLights($light_nrs,$status,$mode)
    $cur_lights = StringSplit($light_nrs,".")
    If $mode = 0 Then
    For $i = 1 to $cur_lights[0]
    _TurnTrafficLightToColor($cur_lights[$i],$status)
    Next
    Else
    For $i = 1 to $cur_lights[0]
    _TurnPedestrainLightToColor($cur_lights[$i],$status)
    Next
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _InitLights()
    _ConnectLights('0.2',2,0)
    _ConnectLights('1.3',0,0)
    _ConnectLights('1.3.5.7',0,1)
    _ConnectLights('0.2.4.6',1,1)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _TrafficLightLoop()
    _ConnectLights('0.2',2,0) ; green
    _ConnectLights('1.3',0,0) ; red
    Sleep(5000*$strokes)
    _ConnectLights('0.2',3,0) ; amber
    Sleep(2000*$strokes)
    _ConnectLights('0.2',0,0) ; red
    Sleep(2000*$strokes)
    _ConnectLights('1.3',1,0) ; amber - red
    _ConnectLights('1.3.5.7',1,1)
    _ConnectLights('0.2.4.6',0,1)
    Sleep(2000*$strokes)
    _ConnectLights('1.3',2,0) ; green
    Sleep(5000*$strokes)
    _ConnectLights('1.3',3,0) ; amber
    Sleep(2000*$strokes)
    _ConnectLights('1.3',0,0) ; red
    Sleep(2000*$strokes)
    _ConnectLights('0.2',1,0) ; amber - red
    _ConnectLights('1.3.5.7',0,1)
    _ConnectLights('0.2.4.6',1,1)
    Sleep(2000*$strokes)
    _ConnectLights('0.2',0,0)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _TurnPedestrainLightToColor($light_nr,$status)
    For $i = 0 to 1
    If $a_p_status[$status][$i] = 1 Then
    GUICtrlSetState($a_p_lights[$light_nr][$i][1],$GUI_SHOW)
    Else
    GUICtrlSetState($a_p_lights[$light_nr][$i][1],$GUI_HIDE)
    EndIf
    Next
    ConsoleWrite(">> Pedestrain Light: " & $light_nr & " turned to " & $a_status_txt[$status] & "!" & @CRLF)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    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(">> Traffic Light: " & $light_nr & " turned to " & $a_status_txt[$status] & "!" & @CRLF)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreatePedestrianLight( $x, $y, $direction = 0)
    ReDim $a_p_lights[UBound($a_p_lights,1)+1][2][2]
    Local $index = (UBound($a_p_lights,1)-1)-1

    [/autoit] [autoit][/autoit] [autoit]

    Switch $direction
    Case 0 ; up
    GUICtrlCreateGraphic($x, $y)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 30, 50)
    #cs
    $Label1 = GUICtrlCreateLabel("Nr. " & $index, $x ,$y+100, 80, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    #ce

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 1
    $new_x = 5+ $x
    $new_y = 5+ $y +(20*$i)

    [/autoit] [autoit][/autoit] [autoit]

    $a_p_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, 20, 20)

    [/autoit] [autoit][/autoit] [autoit]

    $a_p_lights[$index][$i][1] = GUICtrlCreateGraphic($new_x, $new_y)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_p_colors[$i])
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0,0, 20, 20)
    Next
    Case 1 ; right
    GUICtrlCreateGraphic( $x, $y)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0,0,50,30)
    #cs
    $Label1 = GUICtrlCreateLabel("Nr. " & $index, $x+105 ,$y, 80, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    #ce

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 1
    $new_x = 5+ $x +(20*$i)
    $new_y = 5+ $y

    [/autoit] [autoit][/autoit] [autoit]

    $a_p_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, 20, 20)

    [/autoit] [autoit][/autoit] [autoit]

    $a_p_lights[$index][$i][1] = GUICtrlCreateGraphic( $new_x, $new_y)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_p_colors[$i])
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0,0, 20, 20)
    Next
    Case 2 ; down
    GUICtrlCreateGraphic($x, $y)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 30, 50)
    #cs
    $Label1 = GUICtrlCreateLabel("Nr. " & $index, $x ,$y-24, 80, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    #ce

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 1
    $new_x = 5+ $x
    $new_y = 5+ $y -(20*$i) + 20

    [/autoit] [autoit][/autoit] [autoit]

    $a_p_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, 20, 20)

    [/autoit] [autoit][/autoit] [autoit]

    $a_p_lights[$index][$i][1] = GUICtrlCreateGraphic($new_x, $new_y)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_p_colors[$i])
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0,0, 20, 20)
    Next
    Case 3 ; left
    GUICtrlCreateGraphic( $x, $y)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0,0,50,30)
    #cs
    $Label1 = GUICtrlCreateLabel("Nr. " & $index, $x-40 ,$y, 40, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    #ce

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 1
    $new_x = 5+ $x -(20*$i) + 20
    $new_y = 5+ $y

    [/autoit] [autoit][/autoit] [autoit]

    $a_p_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, 20, 20)

    [/autoit] [autoit][/autoit] [autoit]

    $a_p_lights[$index][$i][1] = GUICtrlCreateGraphic( $new_x, $new_y)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_p_colors[$i])
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0,0, 20, 20)
    Next
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    ConsoleWrite("+> Pedestrian Light: " & $index & " created!" & @CRLF)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    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
    GUICtrlCreateGraphic($x, $y)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 30, 70)

    [/autoit] [autoit][/autoit] [autoit]

    $Label1 = GUICtrlCreateLabel("Nr. " & $index, $x ,$y+80, 80, 24)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 2
    $new_x = 5+ $x
    $new_y = 5+ $y +(20*$i)

    [/autoit] [autoit][/autoit] [autoit]

    $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, 20, 20)

    [/autoit] [autoit][/autoit] [autoit]

    $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, 20, 20)
    Next
    Case 1 ; right
    GUICtrlCreateGraphic( $x, $y)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0,0,70,30)

    [/autoit] [autoit][/autoit] [autoit]

    $Label1 = GUICtrlCreateLabel("Nr. " & $index, $x+75 ,$y, 80, 24)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 2
    $new_x = 5+ $x +(20*$i)
    $new_y = 5+ $y

    [/autoit] [autoit][/autoit] [autoit]

    $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, 20, 20)

    [/autoit] [autoit][/autoit] [autoit]

    $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, 20, 20)
    Next
    Case 2 ; down
    GUICtrlCreateGraphic($x, $y)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, 0, 30, 70)

    [/autoit] [autoit][/autoit] [autoit]

    $Label1 = GUICtrlCreateLabel("Nr. " & $index, $x ,$y-24, 30, 24)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 2
    $new_x = 5+ $x
    $new_y = 5+ $y -(20*$i) + 40

    [/autoit] [autoit][/autoit] [autoit]

    $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, 20, 20)

    [/autoit] [autoit][/autoit] [autoit]

    $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, 20, 20)
    Next
    Case 3 ; left
    GUICtrlCreateGraphic( $x, $y)
    GUICtrlSetStyle(-1, $SS_NOTIFY)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $a_colors[5],$a_colors[3])
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0,0,70,30)

    [/autoit] [autoit][/autoit] [autoit]

    $Label1 = GUICtrlCreateLabel("Nr. " & $index, $x-40 ,$y, 40, 24)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to 2
    $new_x = 5+ $x -(20*$i) + 40
    $new_y = 5+ $y

    [/autoit] [autoit][/autoit] [autoit]

    $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, 20, 20)

    [/autoit] [autoit][/autoit] [autoit]

    $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, 20, 20)
    Next
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    ConsoleWrite("+> Traffic Light: " & $index & " created!" & @CRLF)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc

    [/autoit]

    Einmal editiert, zuletzt von Jautois (20. Februar 2011 um 10:44)

  • Zitat


    Wenn du willst kannst du ja noch Verkehr mit reinbauen ;).

    Ich glaube das würde den Rahmen sprengen und dem Skript eher "schaden". Da es bei zuvielen gezeichneten Graphics anfängt zu flackern. ;)

    Das Skript diente eher zum Spaß.

  • Um mal eine kleine Anekdote zum Besten zu geben (man beachte meinen Forentitel^^):
    1980 war ich in der 9. Klasse, damals hatte ich einen Mitschüler, der mit einer Ampelsteuerung für eine grosse Kreuzung in München (7 Zufahrten) einen Preis bei "Jugend forscht" gewonnen hat! Er hatte tatsächlich aus vielen kleinen Lämpchen ein funktionierendes Modell gebaut.
    Übrigens wurde diese Steuerung tatsächlich installiert, so dass in der Hauptverkehrszeit 10% mehr Autos pro Ampelperiode über die Kreuzung kamen als vorher!