Sign in to follow this  
Followers 0
corgano

Theo Jansen

8 posts in this topic

#1 ·  Posted (edited)

I was extremely bored, so I started working on this. Still needs a little polishing, but its mostly complete

The Theo Jansen Mechanism

Done:

-Change length of almost all rods

-Full rotation

-Allows multiple leg sets to be placed over each other

-Allows 3 settings for fading out back legs

-Color coded (yay)

-partial projecting circles (Tells a little about how the points are calculated)

To do

-Complete color coding and allow for all lengths to be changed (this is easy)

-Complete circle projecting

-Rename variables

-Suggestions?

Updates

-Drawing many (100+) sets on full is now significantly faster

-Drawing many (100+) sets on fade and dim is now faster (Thanks UEZ)

here is the code

#include <GUIConstantsEx.au3>
#include <GDIPLus.au3>
#include <WinAPI.au3>

Global $gui, $pic, $lev1x, $circ1y, $lev1l, $s4, $s5, $circ2r, $msg
Global $unit = 0.5 ;VERY IMPORTANT

$gui = GUICreate("Theo test",                                       850,    600)
$pic = GUICtrlCreatePic("",                         0,      0,      600,    600)

$Tab1 = GUICtrlCreateTab(                           610,    8,      230,    533)
$TabSheet1 = GUICtrlCreateTabItem("Global options")
    
    GUICtrlCreateLabel("Size ($unit)",              630,    40)
    $slev1l = GUICtrlCreateSlider(                  620,    55,     200,    30)
    GUICtrlSetBkColor(-1,0xffffff)
    GUICtrlSetLimit(-1, 200, 1)
    GUICtrlSetData(-1, 80)
    
    GUICtrlCreateLabel("Crank rotation ($angle)",   630,    90)
    $sRotation = GUICtrlCreateSlider(               620,    105,    200,    30)
    GUICtrlSetBkColor(-1,0xffffff)
    GUICtrlSetLimit(-1, 900, 0)
    GUICtrlSetData(-1, 90)

    GUICtrlCreateLabel("Crank length ($crankl)",    620,    140)
    $scrankl = GUICtrlCreateSlider(                 620,    155,    200,    30)
    GUICtrlSetBkColor(-1,0xffffff)
    GUICtrlSetLimit(-1, 300, 0)
    GUICtrlSetData(-1, 120)

    GUICtrlCreateLabel("Bodyrod width ($bodywidth)",620,    190)
    $sBodyWidth = GUICtrlCreateSlider(              620,    205,    200,    30)
    GUICtrlSetBkColor(-1,0xffffff)
    GUICtrlSetLimit(-1, 500, 0)
    GUICtrlSetData(-1, 286)

;~  GUICtrlCreateLabel("sssssss",                   620,    240)
;~  $sss = GUICtrlCreateSlider(                     620,    255,    200,    30)
;~  GUICtrlSetBkColor(-1,0xffffff)
;~  GUICtrlSetLimit(-1, 300, 10)
;~  GUICtrlSetData(-1, 120)

;~  GUICtrlCreateLabel("ddddddddd",                 620,    290)
;~  $ddd = GUICtrlCreateSlider(                     620,    305,    200,    30)
;~  GUICtrlSetBkColor(-1,0xffffff)
;~  GUICtrlSetLimit(-1, 300, 10)
;~  GUICtrlSetData(-1, 120)
    
    GUICtrlCreateLabel("Show....",                  620,    340)
    
    $chkcircles = GUICtrlCreateCheckbox("Circles?", 620,    370)
    $chkColors = GUICtrlCreateCheckbox("Colors?", 720, 370)
    GUICtrlSetState(-1,$GUI_CHECKED)
    $chklines = GUICtrlCreateCheckbox("Lines?",     620,    400)
    GUICtrlSetState(-1,$GUI_CHECKED)
    $chkpnt = GUICtrlCreateCheckbox("Points?", 620,     430)
    
    
    $radFull = GUICtrlCreateRadio("Full",           620,    475)
    $radDim = GUICtrlCreateRadio("Dim",             660,    475)
    $radFade = GUICtrlCreateRadio("Fade",           700,    475)
    GUICtrlSetState($radFull, $GUI_CHECKED)
    
    $inputsets = GUICtrlCreateInput("1",            620,    500,    200)
    

$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
    
    GUICtrlCreateLabel("Red", 630, 40)
    $sRED = GUICtrlCreateSlider(620, 55, 200, 30)
    GUICtrlSetBkColor(-1,0xffffff)
    GUICtrlSetLimit(-1, 600, 1)
    GUICtrlSetData(-1, 400)
    
    GUICtrlCreateLabel("Green", 630, 90)
    $green = GUICtrlCreateSlider(620, 105, 200, 30)
    GUICtrlSetBkColor(-1,0xffffff)
    GUICtrlSetLimit(-1, 900, 10)
    GUICtrlSetData(-1, 400)

    GUICtrlCreateLabel("BLUE", 620, 140)
    $sBLUE = GUICtrlCreateSlider(620, 155, 200, 30)
    GUICtrlSetBkColor(-1,0xffffff)
    GUICtrlSetLimit(-1, 600, 10)
    GUICtrlSetData(-1, 275)

    GUICtrlCreateLabel("Cyan", 620, 190)
    $sCYAN = GUICtrlCreateSlider(620, 205, 200, 30)
    GUICtrlSetBkColor(-1,0xffffff)
    GUICtrlSetLimit(-1, 600, 10)
    GUICtrlSetData(-1, 290)

;~  GUICtrlCreateLabel("tttttttttt", 620, 240)
;~  $ttt = GUICtrlCreateSlider(620, 255, 200, 30)
;~  GUICtrlSetBkColor(-1,0xffffff)
;~  GUICtrlSetLimit(-1, 300, 10)
;~  GUICtrlSetData(-1, 120)

;~  GUICtrlCreateLabel("yyyyyyy", 620, 290)
;~  $yyy = GUICtrlCreateSlider(620, 305, 200, 30)
;~  GUICtrlSetBkColor(-1,0xffffff)
;~  GUICtrlSetLimit(-1, 300, 10)
;~  GUICtrlSetData(-1, 120)

$TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
GUICtrlCreateTabItem("")


GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $lev1x, $circ1y, $lev1l, $lev1x, $sRotation
            refresh()
            Sleep(10)
        EndSwitch

WEnd


Func refresh()
    $unit = GUICtrlRead($slev1l) / 200              ;get size multiplier
    $vangle = GUICtrlRead($sRotation)               ;Crank rotation
    $vcrankl = GUICtrlRead($scrankl)                ;Crank length
    $vBodyrodwidth = GUICtrlRead($sBodyWidth)       ;Width of body
    
    $vPushrodL = GUICtrlRead($green)                ;green bars
    $vHypL = GUICtrlRead($sRED)                     ;Red bars   
    $vBotTril = GUICtrlRead($sBLUE)                 ;Blue bars  
    $vOutParl = GUICtrlRead($scyan)                 ;cyan bars  
    
    $tcirclesYN = GUICtrlRead($chkcircles)          ;show circles?
    $tlinesYN = GUICtrlRead($chklines)              ;Show lines?
    $tpntYN = GUICtrlRead($chkpnt)                  ;Show points?
    $tcolors = GUICtrlRead($chkColors)              ;Show pretty colors?
    
    If GUICtrlRead($radFull) = $GUI_CHECKED Then $vfademode = 1
    If GUICtrlRead($radDim) = $GUI_CHECKED Then $vfademode = 2
    If GUICtrlRead($radFade) = $GUI_CHECKED Then $vfademode = 3
    
    $vnumbersets = GUICtrlRead($inputsets)          ;how many sets of lags?
    
    
     test($pic,     $vangle,    $vcrankl,   $vBodyrodwidth,     $vPushrodL,     $vHypL,     $vBotTril,      $vOutParl,      $vnumbersets,       $vfademode,         $tcirclesYN,        $tlinesYN,      $tcolors,       $tpntYN)
EndFunc

Func test($ctrl,     $angle,    $crankl,    $Bodyrodwidth,      $PushrodL,      $HypL,      $BotTril,       $OutParl,       $number = 1,        $fademode = 1,      $circlesYN = 0,     $linesYN = 1,   $colorsYN = 1,  $pointsYN = 0)
    
    Local $hBmp, $hBitmap1, $hGraphic, $hBitmap2, $OldBmp, $one, $two

    $hBmp = _WinAPI_CreateBitmap(600, 600, 1, 32)
    _GDIPlus_Startup()
    
    $redpen = _GDIPlus_PenCreate(0xFFFF3333)
    $Greenpen = _GDIPlus_PenCreate(0xFF33ff33)
    $bluepen = _GDIPlus_PenCreate(0xFF3333ff)

    $hBitmap1 = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap1)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 4)
    
    
    $Bodyrodwidth *= $unit
    $crankl *= $unit
    $PushrodL *= $unit
    $HypL *= $unit
    $BotTril *= $unit
    $OutParl *= $unit
    
    $pcenterx = 300
    $pcentery = 200

    $pleftx = $pcenterx - $Bodyrodwidth
    $plefty = $pcentery

    $prightx = $pcenterx + $Bodyrodwidth
    $prighty = $pcentery


    $lev1l = 275 * $unit

    $llev2l = 290 * $unit
    $rlev2l = 290 * $unit

    $llev3l = 275 * $unit

    shaft($hGraphic, $pleftx, $plefty, $prightx, $prighty,$redpen);"body" bar
    
    
    
    If $number = "" Then $number = 1
    
    $fade = "0xFF";if somehow the fademode returns not 1, 2, or 3, this will draw it as full
    
    $hpen = _GDIPlus_PenCreate($fade&"FFFFFF")
    If $colorsYN = 1 Then 
        $Redpen = _GDIPlus_PenCreate($fade&"FF3333")
        $Greenpen = _GDIPlus_PenCreate($fade&"33ff33")
        $Bluepen = _GDIPlus_PenCreate($fade&"3333ff")
        $cyanpen = _GDIPlus_PenCreate($fade&"33ddff")
    Else
        $Redpen = $hpen
        $Greenpen = $hpen
        $Bluepen = $hpen
        $cyanpen = $hpen
    EndIf
    

    For $i = 0 to ($number-1) step 1
        
        ;If there is no need to fade the pens will be pre declaired once instead of every Step
        If $fademode <> 1 And $number > 1 Then
            $fade = "0xFF";if somehow the fademode returns not 1, 2, or 3, this will draw it as full
        
            If $fademode = 2 Then
                $fade = "0x" & Hex(175/$number+75,2)
            ElseIf $fademode = 3 Then
                $fade = "0x" & Hex(200/($i + 1)+50,2)
            EndIf   
            
            _GDIPlus_PenSetColor($hpen,$fade&"FFFFFF")
            If $colorsYN = 1 Then 
                _GDIPlus_PenSetColor($Redpen,$fade&"FF3333")
                _GDIPlus_PenSetColor($Greenpen,$fade&"33ff33")
                _GDIPlus_PenSetColor($Bluepen,$fade&"3333ff")
                _GDIPlus_PenSetColor($cyanpen,$fade&"33ddff")
            Else
                $Redpen = $hpen
                $Greenpen = $hpen
                $Bluepen = $hpen
                $cyanpen = $hpen
            EndIf
        EndIf
        
        $crankpos = Angle($pcenterx, $pcentery, $angle, $crankl, $circlesYN)
        
        shaft($hGraphic, $crankpos[0],$crankpos[1],$pcenterx, $pcentery,$hpen);crank
    
;~ ;=====================================================================================================,
;~ ||                                                                                                   ||
;~ ||                       MESUREMENTS : calculations for all the points                               ||
;~ ||                                                                                                   ||
;~ ;=====================================================================================================,

        $pTopRightTriTip = intcircles($prightx, $prighty, $lev1l, $crankpos[0], $crankpos[1], $PushrodL)        

        If ($pTopRightTriTip[0] + $pTopRightTriTip[2]) = 0  Then  Return 0

        $pTopRightHypPar = intcircles($prightx, $prighty, $rlev2l, $pTopRightTriTip[0],$pTopRightTriTip[1], $HypL)  
        
        $pBotRightHypPar = intcircles($pTopRightTriTip[2], $pTopRightTriTip[3], $rlev2l, $pTopRightHypPar[0],$pTopRightHypPar[1], $OutParl)
        
        $pBotRightTriTip = intcircles($pBotRightHypPar[0],$pBotRightHypPar[1], $HypL, $pTopRightTriTip[2],$pTopRightTriTip[3], $BotTril)
        
        
        $pTopLeftTriTip = intcircles($pLeftx, $pLefty, $lev1l, $crankpos[0], $crankpos[1], $PushrodL)       

        If ($pTopLeftTriTip[02] + $pTopLeftTriTip[0]) = 0  Then  Return 0

        $pTopLeftHypPar = intcircles($pLeftx, $pLefty, $rlev2l, $pTopLeftTriTip[2],$pTopLeftTriTip[3], $HypL)   
        
        $pBotLeftHypPar = intcircles($pTopLeftTriTip[0], $pTopLeftTriTip[1], $rlev2l, $pTopLeftHypPar[2],$pTopLeftHypPar[3], $OutParl)
        
        $pBotLeftTriTip = intcircles($pTopLeftTriTip[0],$pTopLeftTriTip[1],$BotTril ,$pBotLeftHypPar[2],$pBotLeftHypPar[3],$HypL)
        
        
;~ ;=====================================================================================================,
;~ ||                                                                                                   ||
;~ ||                       LINES : Actual drawing of the lines                                         ||
;~ ||                                                                                                   ||
;~ ;=====================================================================================================,
        If $linesYN = 1 Then
            
            shaft($hGraphic, $pTopRightTriTip[2], $pTopRightTriTip[3], $crankpos[0], $crankpos[1], $greenpen);top left pushrod
            shaft($hGraphic, $pTopRightTriTip[0], $pTopRightTriTip[1], $crankpos[0], $crankpos[1], $greenpen);bottom left pushrod
            
            shaft($hGraphic, $pTopRightTriTip[0], $pTopRightTriTip[1], $prightx,  $prighty, $hpen);Right side top triangle
            shaft($hGraphic, $pTopRightTriTip[0], $pTopRightTriTip[1], $pTopRightHypPar[0], $pTopRightHypPar[1], $redpen);long side top triangel
            shaft($hGraphic, $prightx,  $prighty, $pTopRightHypPar[0], $pTopRightHypPar[1], $hpen);Bottom side top triangle

            shaft($hGraphic, $pTopRightTriTip[2], $pTopRightTriTip[3], $prightx, $prighty, $hpen);inside parallel bar
            shaft($hGraphic, $pBotRightHypPar[0], $pBotRightHypPar[1], $pTopRightHypPar[0], $pTopRightHypPar[1], $cyanpen);outside parallel bar
            
            shaft($hGraphic, $pTopRightTriTip[2], $pTopRightTriTip[3], $pBotRightHypPar[0], $pBotRightHypPar[1], $hpen);top side bottom triangel
            shaft($hGraphic, $pBotRightHypPar[0], $pBotRightHypPar[1], $pBotRightTriTip[2], $pBotRightTriTip[3], $redpen);long side bottom triangel
            shaft($hGraphic, $pTopRightTriTip[2], $pTopRightTriTip[3], $pBotRightTriTip[2], $pBotRightTriTip[3], $Bluepen);right side bottom triangel
            
            

            shaft($hGraphic, $pTopLeftTriTip[0],$pTopLeftTriTip[1],$crankpos[0],$crankpos[1],$greenpen);top left pushrod
            shaft($hGraphic, $pTopLeftTriTip[2],$pTopLeftTriTip[3],$crankpos[0],$crankpos[1],$greenpen);bottom left pushrod
            
            shaft($hGraphic, $pTopLeftTriTip[2], $pTopLeftTriTip[3], $pLeftx,  $pLefty,  $hpen);Left side top triangle
            shaft($hGraphic, $pTopLeftTriTip[2], $pTopLeftTriTip[3], $pTopLeftHypPar[2], $pTopLeftHypPar[3], $redpen);long side top triangel
            shaft($hGraphic, $pLeftx,  $pLefty,  $pTopLeftHypPar[2], $pTopLeftHypPar[3], $hpen);Bottom side top triangle

            shaft($hGraphic, $pTopLeftTriTip[0], $pTopLeftTriTip[1], $pLeftx,  $pLefty,  $hpen); Inside parallel bar
            shaft($hGraphic, $pBotLeftHypPar[2], $pBotLeftHypPar[3], $pTopLeftHypPar[2], $pTopLeftHypPar[3], $cyanpen);Outside par bqr
            
            shaft($hGraphic, $pTopLeftTriTip[0], $pTopLeftTriTip[1], $pBotLeftHypPar[2], $pBotLeftHypPar[3], $hpen);top side bottom triangel
            shaft($hGraphic, $pBotLeftHypPar[2], $pBotLeftHypPar[3], $pBotLeftTriTip[2], $pBotLeftTriTip[3], $redpen);long side bottom triangel
            shaft($hGraphic, $pTopLeftTriTip[0], $pTopLeftTriTip[1], $pBotLeftTriTip[2], $pBotLeftTriTip[3], $Bluepen);Left side bottom triangel


        EndIf
        
;~ ;=====================================================================================================,
;~ ||                                                                                                   ||
;~ ||                       Circles : drawing of the Circles                                            ||
;~ ||                                                                                                   ||
;~ ;=====================================================================================================,
        If $circlesYN = 1 Then
            _GDIPlus_GraphicsDrawEllipse($hGraphic, $pleftx-$lev1l, $plefty-$lev1l, $lev1l*2, $lev1l*2, $hpen)
            _GDIPlus_GraphicsDrawEllipse($hGraphic, $prightx-$lev1l, $prighty-$lev1l, $lev1l*2, $lev1l*2, $hpen)
            _GDIPlus_GraphicsDrawEllipse($hGraphic, $crankpos[0]-$PushrodL, $crankpos[1]-$PushrodL, $PushrodL*2, $PushrodL*2, $hpen)
;~          
            _GDIPlus_GraphicsDrawEllipse($hGraphic, $pcenterx - ($crankl), $pcentery - ($crankl), $crankl*2, $crankl*2, $hpen)
;~          
            _GDIPlus_GraphicsDrawEllipse($hGraphic, $pTopRightTriTip[0] - ($HypL), $pTopRightTriTip[1] - ($HypL), $HypL*2, $HypL*2, $hpen)
            _GDIPlus_GraphicsDrawEllipse($hGraphic, $pTopRightHypPar[0] - ($lev1l), $pTopRightHypPar[1] - ($lev1l), $lev1l*2, $lev1l*2, $hpen)
;~          
            
            _GDIPlus_GraphicsDrawEllipse($hGraphic, $pBotRightHypPar[0] - ($HypL), $pBotRightHypPar[1] - ($HypL), $HypL*2, $HypL*2, $hpen)
            _GDIPlus_GraphicsDrawEllipse($hGraphic, $pTopRightTriTip[2] - ($lev1l), $pTopRightTriTip[3] - ($lev1l), $lev1l*2, $lev1l*2, $hpen)
            If $pointsYN = 1 Then $circlesYN = 5
        EndIf
        
;~ ;=====================================================================================================,
;~ ||                                                                                                   ||
;~ ||                       Points : Only drawn if lines are off                                        ||
;~ ||                                                                                                   ||
;~ ;=====================================================================================================,
        If $linesYN <> 1 And $pointsYN = 1 Then
            point($hGraphic,$prightx,$prighty,$hpen)
            point($hGraphic,$crankpos[0],$crankpos[1],$hpen)
            point($hGraphic,$pTopRightTriTip[2],$pTopRightTriTip[3],$hpen)
            point($hGraphic,$pTopRightTriTip[0],$pTopRightTriTip[1],$hpen)
            point($hGraphic,$pTopRightHypPar[0],$pTopRightHypPar[1],$hpen)
            point($hGraphic,$pBotRightHypPar[0],$pBotRightHypPar[1],$hpen)
            point($hgraphic,$pBotRightTriTip[2],$pBotRightTriTip[3],$hpen)


            
            point($hGraphic,$pLeftx,$pLefty,$hpen)
            point($hGraphic,$crankpos[0],$crankpos[1],$hpen)
            point($hGraphic,$pTopLeftTriTip[2],$pTopLeftTriTip[3],$hpen)
            point($hGraphic,$pTopLeftTriTip[0],$pTopLeftTriTip[1],$hpen)
            point($hGraphic,$pTopLeftHypPar[2],$pTopLeftHypPar[3],$hpen)
            point($hGraphic,$pBotLeftHypPar[2],$pBotLeftHypPar[3],$hpen)
            point($hgraphic,$pBotLeftTriTip[2],$pBotLeftTriTip[3],$hpen)
        EndIf
        
    
    $angle += (360 / $number)
    
    Next
    

    $hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1)
    $oldbmp = GUICtrlSendMsg($ctrl, 0x0172, 0, $hBitmap2)

    If $OldBmp Then _WinAPI_DeleteObject($OldBmp)

    _WinAPI_DeleteObject($hBitmap2)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BitmapDispose($hBitmap1)
    _GDIPlus_PenDispose($redpen)
    _GDIPlus_PenDispose($bluepen)
    _GDIPlus_PenDispose($greenpen)
    _GDIPlus_PenDispose($hpen)
    _GDIPlus_Shutdown()
    _WinAPI_DeleteObject($hBmp)
;~  Sleep(10)
EndFunc   ;==>fracircle



;~ ;=====================================================================================================,
;~ ||                                                                                                   ||
;~ ||                   Angle : point $return is $length away from $input XY @ $angle                   ||
;~ ||                                                                                                   ||
;~ ;=====================================================================================================,
Func Angle($x1, $y1, $Ang, $Length, $round = 0)
    If $Ang >= 360 Then $Ang -= 360
    Local $Return[2]
    $Return[0] = $x1 + ($Length * Cos($Ang / 180 * 3.14159265358979))
    $Return[1] = $y1 - ($Length * Sin($Ang / 180 * 3.14159265358979))
    If $round = 1 Then
        $Return[0] = Round($Return[0])
        $Return[1] = Round($Return[1])
    EndIf
    Return $Return
EndFunc   ;==>Angle

;~ ;=============================================================================================================,
;~ ||                                                                                                           ||
;~ ||   intcircles : Finds where circle at X/Y1 with a radius of R1 meats a circle at X/Y0 with a radius of R0  ||
;~ ||                   return[0/1] = x/y of 1rst point the circles meet                                        ||
;~ ||                   return[2/3] = x/y of 2rst point the circles meet                                        ||
;~ ||                                                                                                           ||
;~ ;=============================================================================================================,
func intcircles($x0,$y0,$r0,$x1,$y1,$r1)
    Local $xp2, $yp2, $dx, $dy, $d
    Local $return[4]
    $dx = $x1 - $x0;
    $dy = $y1 - $y0;
    $d = sqrt(($x1 - $x0)^2 + ($y1 - $y0)^2)
    if ($d > ($r0 + $r1)) Then
        ;no solution. circles do not intersect.
        SetError(1,"no solution. circles do not intersect.")
        ConsoleWrite($d & @crlf)
        Return $return
    Elseif ($d < $r0 - $r1) Then
        ;no solution. one circle is contained in the other */
        SetError(2);unsaluveable
        ConsoleWrite($d & @crlf)
        Return $return
    EndIf
    ;Determine the distance from point 0 to point 2.
    $a = ($r0^2 - $r1^2 + $d^2) / (2.0 * $d)
    ;Determine the coordinates of point 2. */
    $x2 = $x0 + ($dx * $a/$d);
    $y2 = $y0 + ($dy * $a/$d);
    ;Determine the distance from point 2 to either of the intersection points.
    $h = sqrt(($r0*$r0) - ($a*$a))
    ; Now determine the offsets of the intersection points from point 2.
    $rx = -$dy * ($h/$d);
    $ry = $dx * ($h/$d);
  ; Determine the absolute intersection points. ;
    $return[0] = ($x2 + $rx);+($d/2)
    $return[2] = ($x2 - $rx);+($d/2)
    $return[1] = ($y2 + $ry);-($d/2)
    $return[3] = ($y2 - $ry);-($d/2)
    If ($return[0] + $return[2]) = 0 Then
        SetError(3)
    EndIf
    return $return
EndFunc

;~ ;=====================================================================================================,
;~ ||                                                                                                   ||
;~ ||                           GetAngle : X/Y1 is $return degrees from X/Y2                            ||
;~ ||                                                                                                   ||
;~ ;=====================================================================================================,
Func GetAngle($X1, $Y1, $X2, $Y2)
Dim $XDiff
Dim $YDiff
Dim $TempAngle
$YDiff = Abs($Y2 - $Y1)
If $X1 = $X2 And $Y1 = $Y2 Then Return 0
If $YDiff = 0 And $X1 < $X2 Then
    Return 0
ElseIf $YDiff = 0 And $X1 > $X2 Then
    Return 3.14159265358979 * 57.2957795130823
EndIf
$XDiff = Abs($X2 - $X1)
$TempAngle = ATan($XDiff / $YDiff)
If $Y2 > $Y1 Then $TempAngle = 3.14159265358979 - $TempAngle
If $X2 < $X1 Then $TempAngle = -$TempAngle
$TempAngle = 1.5707963267949 - $TempAngle
If $TempAngle < 0 Then $TempAngle = 6.28318530717959 + $TempAngle
Return $TempAngle * 57.2957795130823
endFunc

;~ ;=====================================================================================================,
;~ ||                                                                                                   ||
;~ ||           shaft: use is same as drawing a line, output si a graphicly superior version            ||
;~ ||                                                                                                   ||
;~ ;=====================================================================================================,
Func shaft($hGraphic,$x1,$y1,$x2,$y2,$hpen)
    $angle = getangle($x1,$y1,$x2,$y2)
;~  ConsoleWrite($angle & @crlf)
    $dist = sqrt(($x2 - $x1)^2 + ($y2 - $y1)^2)
    $pos1 = Angle($x1, $y1, $angle + 90, 5)
    $pos2 = Angle($x1, $y1, $angle - 90, 5)
    $pos3 = Angle($x2, $y2, $angle + 90, 5)
    $pos4 = Angle($x2, $y2, $angle - 90, 5)
    _GDIPlus_GraphicsDrawLine($hGraphic,$pos1[0],$pos1[1],$pos3[0],$pos3[1],$hpen)
    _GDIPlus_GraphicsDrawLine($hGraphic,$pos2[0],$pos2[1],$pos4[0],$pos4[1],$hpen)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $x1-5, $y1-5, 10, 10, $hpen)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $x2-5, $y2-5, 10, 10, $hpen)
EndFunc

;~ ;=====================================================================================================,
;~ ||                                                                                                   ||
;~ ||                               Point : Because i am lazy                                           ||
;~ ||                                                                                                   ||
;~ ;=====================================================================================================,
Func point($hGraphic,$x,$y,$hpen,$r = 10)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $x-($r/2), $y-($r/2), $r, $r, $hpen)
EndFunc
Edited by corgano
1 person likes this

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Very nice implementation corgano ;)

For setting pixels (points) you can use (for your lazy part :evil:):

Func _GDIPlus_BitmapSetPixel($hBitmap, $iX, $iY, $iARGB = 0xFF000000)
    Local $aRet
    $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapSetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "dword", $iARGB)
    Return
EndFunc ;==>_GDIPlus_BitmapSetPixel

One more tip: use _GDIPlus_BrushSetSolidColor() / _GDIPlus_PenSetColor() to change color without creating everytime pens / brushes (memory hug)!

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

@UEZ

Could you provide me with an example?

I changed the conditions under which it creates the pens so when fade mode is full you can draw the image faster

Test this with the updated script by seting the input to 100 and have the full radio checked, then check the fade or dim radio

Something else you may want to try is check points, uncheck lines, and set the input to 100.


0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites

Here an simple example!

#include <GDIplus.au3>
Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()
Global $hwnd = GUICreate("GDI+: Pen", 300, 200, -1, -1, Default)
GUISetOnEvent(-3, "_Exit")
GUISetState()

Global $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)

$pen = _GDIPlus_PenCreate(0xFFFF0000)
_GDIPlus_GraphicsDrawLine($graphics, 0, 0, 300, 200, $pen)
_GDIPlus_PenSetColor($pen, 0xFF00FF00)
_GDIPlus_GraphicsDrawLine($graphics, 300, 0, 0, 200, $pen)

While Sleep(50)
WEnd


Func _Exit()
    _GDIPlus_PenDispose($pen)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Done! See first post

What does UEZ stand for?


0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites

What does UEZ stand for?

Initial of my name ;) because I was uninspired when I created an account here.

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Just curious, what else do you think I should go for, other than klann linkage?


0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
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
Sign in to follow this  
Followers 0