Skip to content

Instantly share code, notes, and snippets.

@turbo
Created April 30, 2015 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turbo/be51ae55cdf25c99c692 to your computer and use it in GitHub Desktop.
Save turbo/be51ae55cdf25c99c692 to your computer and use it in GitHub Desktop.
AutoIt Realtime Node Framework (Prototype)
Opt("GUIOnEventMode", 1)
Global Const $iGUIWidth = 1000
Global Const $iGUIHeight = 600
GUICreate("Node Test", $iGUIWidth, $iGUIHeight, -1, -1, -1, 34078728)
GUISetBkColor(0x404040)
GUISetOnEvent(-3, "exut")
GUISetFont(7)
Dim $aMovables[1][7]
$g = GUICtrlCreateGraphic(0,0)
GUICtrlSetState(-1, 128)
$aMovables[0][0] = GUICtrlCreateButton("Render Framework" & @LF & "mode: init", 20, 20, 100, 40, 0x2000)
$aMovables[0][1] = 20
$aMovables[0][2] = 20
$aMovables[0][3] = 100
$aMovables[0][4] = 40
$aMovables[0][5] = "1,2,3"
$aMovables[0][6] = 0xFFFFFF
;AddObject(Text, Pos, Pos, Pos, Pos, Connected Nodes)
AddObject("type: value" & @LF & "mode: per frame" & @LF & "name: SunX", 160, 40, 100, 50, "4")
AddObject("type: value" & @LF & "mode: per frame" & @LF & "name: AmbientLight", 80, 140, 100, 50, "4")
AddObject("type: value" & @LF & "mode: per frame" & @LF & "name: SunRed", 20, 240, 100, 50, "4")
AddObject("type: loop" & @LF & "mode: general" & @LF & "name: ""MainLoop""", 300, 110, 100, 50, "5,6,7,18,23,28,32,37")
AddObject("type: value" & @LF & "mode: per pixel" & @LF & "name: DirectLight", 320, 20, 100, 50, "")
AddObject("type: variable" & @LF & "mode: per pixel" & @LF & "name: ColorARGB", 450, 20, 100, 50, "")
AddObject("type: element" & @LF & "mode: per pixel" & @LF & "name: Tree Trunks", 580, 20, 100, 50, "8")
AddObject("formula: tt_01", 740, 20, 100, 20, "9,17")
AddObject("bool: AND", 880, 35, 60, 20, "10")
AddObject("formula: tt_02", 740, 50, 100, 20, "11,17")
AddObject("bool: AND", 880, 65, 60, 20, "12")
AddObject("formula: tt_03", 740, 80, 100, 20, "13,17")
AddObject("bool: AND", 880, 95, 60, 20, "14")
AddObject("formula: tt_04", 740, 110, 100, 20, "15,17")
AddObject("bool: AND", 880, 125, 60, 20, "16")
AddObject("formula: tt_05", 740, 140, 100, 20, "17")
AddObject("type: modifier" & @LF & "mode: requested" & @LF & "name: SetColor", 580, 80, 100, 50, "40")
AddObject("type: element" & @LF & "mode: per pixel" & @LF & "name: Light Leaves", 450, 75, 100, 50, "19")
AddObject("formula: ll_01", 580, 140, 100, 20, "20,22")
AddObject("bool: AND", 740, 170, 60, 20, "21")
AddObject("formula: ll_02", 580, 170, 100, 20, "22")
AddObject("type: modifier" & @LF & "mode: requested" & @LF & "name: SetColor", 450, 135, 100, 50, "40")
AddObject("type: element" & @LF & "mode: per pixel" & @LF & "name: Dark Leaves", 880, 150, 100, 50, "24")
AddObject("formula: dl_01", 740, 200, 100, 20, "25,27")
AddObject("bool: AND", 880, 210, 60, 20, "26")
AddObject("formula: dl_02", 740, 230, 100, 20, "27")
AddObject("type: modifier" & @LF & "mode: requested" & @LF & "name: SetColor", 580, 200, 100, 50, "40")
AddObject("type: element" & @LF & "mode: per pixel" & @LF & "name: Ground", 320, 180, 100, 50, "29")
AddObject("formula: g_01", 450, 200, 100, 20, "30")
AddObject("bool: AND", 360, 240, 60, 20, "31")
AddObject("type: modifier" & @LF & "mode: requested" & @LF & "name: SetColor", 450, 230, 100, 50, "40")
AddObject("type: element" & @LF & "mode: per pixel" & @LF & "name: Water", 510, 290, 100, 50, "33")
AddObject("formula: w_01", 365, 290, 100, 20, "34,36")
AddObject("bool: AND", 270, 270, 60, 20, "35")
AddObject("formula: w_02", 365, 330, 100, 20, "36")
AddObject("type: modifier" & @LF & "mode: requested" & @LF & "name: SetColor", 230, 330, 100, 50, "40")
AddObject("type: element" & @LF & "mode: per pixel" & @LF & "name: Sun", 630, 260, 100, 50, "38")
AddObject("formula: s_01", 800, 310, 100, 20, "39")
AddObject("type: modifier" & @LF & "mode: requested" & @LF & "name: SetColor", 870, 240, 100, 50, "40")
AddObject("Render Framework" & @LF & "mode: flush", 800, 500, 100, 40, "")
Func AddObject($sText, $iLeft, $iTop, $iWidth, $iHeight, $sNodes, $iColor = 0xFFFFFF)
$Bound = UBound($aMovables)
ReDim $aMovables[$Bound+1][7]
$aMovables[$Bound][0] = GUICtrlCreateButton($sText, $iLeft, $iTop, $iWidth, $iHeight, 0x2000)
$aMovables[$Bound][1] = $iLeft
$aMovables[$Bound][2] = $iTop
$aMovables[$Bound][3] = $iWidth
$aMovables[$Bound][4] = $iHeight
$aMovables[$Bound][5] = $sNodes
$aMovables[$Bound][6] = $iColor
EndFunc
DrawBounds()
GUISetState()
While Sleep(20)
$cur = GUIGetCursorInfo()
If Not IsArray($cur) Then ContinueLoop
If $cur[2] = 1 Then
For $nCtrl = 0 To UBound($aMovables)-1
If $cur[4] = $aMovables[$nCtrl][0] Then
$end = GUIGetCursorInfo()
If Not IsArray($end) Then ContinueLoop
$dx = $end[0] - $aMovables[$nCtrl][1]
$dy = $end[1] - $aMovables[$nCtrl][2]
$iDrawn = 0
$iTimer = TimerInit()
Do
$end = GUIGetCursorInfo()
$aMovables[$nCtrl][1] = $end[0]-$dx
$aMovables[$nCtrl][2] = $end[1]-$dy
If $aMovables[$nCtrl][1] <= 6 Then $aMovables[$nCtrl][1] = 6
If $aMovables[$nCtrl][2] <= 6 Then $aMovables[$nCtrl][2] = 6
If $aMovables[$nCtrl][1]+$aMovables[$nCtrl][3] >= ($iGUIWidth-6) Then $aMovables[$nCtrl][1] = ($iGUIWidth-6)-$aMovables[$nCtrl][3]
If $aMovables[$nCtrl][2]+$aMovables[$nCtrl][4] >= ($iGUIWidth-26) Then $aMovables[$nCtrl][2] = ($iGUIHeight-26)-$aMovables[$nCtrl][4]
$aMovables[$nCtrl][6] = 0x00FF00
$back = $g
$g = GUICtrlCreateGraphic(0,0)
GUICtrlSetState(-1, 128)
DrawBounds()
For $tCtrl = 0 To UBound($aMovables)-1
If $aMovables[$tCtrl][5] <> "" Then
$aNodes = StringSplit($aMovables[$tCtrl][5], ",", 3)
For $nConnection = 0 To UBound($aNodes)-1
If Not IsNodeInObject($aNodes[$nConnection], $tCtrl) Then DrawConnection($tCtrl, $aNodes[$nConnection], $aMovables)
$iDrawn += 1
Next
EndIf
Next
GUICtrlDelete($back)
GUICtrlSetPos($aMovables[$nCtrl][0], $aMovables[$nCtrl][1], $aMovables[$nCtrl][2])
$aMovables[$nCtrl][6] = 0xFFFFFF
Until $end[2] = 0
EndIf
Next
EndIf
WEnd
Func IsNodeInObject(ByRef $iObj, $nNode)
If $aMovables[$iObj][5] = "" Then Return False
$f = StringSplit($aMovables[$iObj][5], ",", 3)
For $b = 0 To UBound($f)-1
If $f[$b] = $nNode Then Return True
Next
Return False
EndFunc
Func DrawConnection($n1,$n2, ByRef $a)
GUICtrlSetGraphic($g,8,$a[$n1][6])
If $a[$n1][1]+$a[$n1][3]<=$a[$n2][1] Then
$n=DrawWire(5+$a[$n1][1]+$a[$n1][3],$a[$n1][2]+($a[$n1][4]/2),$a[$n2][1]-5,$a[$n2][2]+($a[$n2][4]/2))+g($g,12,1+$a[$n1] _
[1]+$a[$n1][3],$a[$n1][2]+($a[$n1][4]/2)-4,9,9)+g($g,12,$a[$n2][1]-10,$a[$n2][2]+($a[$n2][4]/2)-4,9,9)
ElseIf $a[$n1][1]+$a[$n1][3]>=$a[$n2][1] And $a[$n1][1]<=$a[$n2][1]+$a[$n2][3] And $a[$n1][2]+$a[$n1][4]<=$a[$n2][2] Then
$n=DrawWire($a[$n1][1]+($a[$n1][3]/2),$a[$n1][2]+$a[$n1][4]+5,$a[$n2][1]+($a[$n2][3]/2),$a[$n2][2]-6)+g($g,12,$a[$n1][1 _
]+($a[$n1][3]/2)-4,$a[$n1][2]+$a[$n1][4]+1,9,9)+g($g,12,$a[$n2][1]+($a[$n2][3]/2)-4,$a[$n2][2]-10,9,9)
ElseIf $a[$n1][1]+$a[$n1][3]>=$a[$n2][1] And $a[$n1][1]<=$a[$n2][1]+$a[$n2][3] And $a[$n1][2]>=$a[$n2][2]+$a[$n2][4] Then
$n=DrawWire($a[$n1][1]+($a[$n1][3]/2),$a[$n1][2]-6,$a[$n2][1]+($a[$n2][3]/2),$a[$n2][2]+$a[$n2][4]+5)+g($g,12,$a[$n1][1 _
]+($a[$n1][3]/2)-4,$a[$n1][2]-10,9,9)+g($g,12,$a[$n2][1]+($a[$n2][3]/2)-4,$a[$n2][2]+$a[$n2][4]+1,9,9)
ElseIf $a[$n1][1]>=$a[$n2][1]++$a[$n2][3] Then
$n=DrawWire($a[$n1][1]-6,$a[$n1][2]+($a[$n1][4]/2),$a[$n2][1]+$a[$n2][3]+6,$a[$n2][2]+($a[$n2][4]/2))+g($g,12,$a[$n1][1 _
]-10,$a[$n1][2]+($a[$n1][4]/2)-4,9,9)+g($g,12,1+$a[$n2][1]+$a[$n2][3],$a[$n2][2]+($a[$n2][4]/2)-4,9,9)
EndIf
EndFunc
Func g($1, $2, $3, $4, $5, $6)
GUICtrlSetGraphic($1, $2, $3, $4, $5, $6)
EndFunc
Func DrawBounds()
GUICtrlSetGraphic($g, 8, 0xFFFFFF)
GUICtrlSetGraphic($g, 10, 5, 5, ($iGUIWidth-10), ($iGUIHeight-10))
EndFunc
Func DrawWire($x, $y, $x1, $y1)
$d = ($x1-$x) / 2
GUICtrlSetGraphic($g, 6, $x, $y)
GUICtrlSetGraphic($g, 4, $x1, $y1, $x+$d, $y, $x+$d, $y1)
EndFunc
Func exut()
Exit
EndFunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment