Luigi Posted January 1, 2015 Share Posted January 1, 2015 Hello forum! Happy new year! 8D In this code, I think draw a line is simple, but I can't... How to draw a line from the point(2,4) until point(18,10)? (line 26): line(2, 4, 18, 10) Obs: use GDI to draw its easy, but I need know the code/alghorithm to do this... I was use some parts of geometry alalitic, like: y - ya = m(x - xa) But not work fine when you try draw a line like this: (2, 4, 18, 4) Obs2: if you clieck over square, the code print the current position (line, column). code expandcollapse popup#include-once #include <Array.au3> #include <Misc.au3> #include <GUIConstantsEx.au3> OnAutoItExitRegister("on_exit") Opt('GUIOnEventMode', 1) Opt('GUIEventOptions', 1) Opt('MustDeclareVars', 1) Global $aGuiSize[2] = [800, 600] Global $sGuiTitle = "GuiTitle" Global $hGui Global $aDot[60][40] Global $oDot = ObjCreate("Scripting.Dictionary") $hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1]) GUISetOnEvent($GUI_EVENT_CLOSE, 'quit') For $ii = 0 To UBound($aDot, 1) - 1 For $jj = 0 To UBound($aDot, 2) - 1 $aDot[$ii][$jj] = GUICtrlCreateLabel("", ($ii) * 8 + $ii, ($jj) * 8 + $jj, 8, 8) GUICtrlSetBkColor($aDot[$ii][$jj], 0xFFFFFF) $oDot.Add($aDot[$ii][$jj], "[" & $ii & "," & $jj & "]") GUICtrlSetOnEvent($aDot[$ii][$jj], "tip") Next Next Func tip() ConsoleWrite($oDot.Item(@GUI_CtrlId) & @LF) EndFunc ;==>tip line(2, 4, 8, 9) Func line($xa, $ya, $xb, $yb) Local $mm = ($yb - $ya) / ($xb - $xa) Local $yy For $ii = $xa To $xb For $jj = $ya To $yb $yy = $mm * ($ii - $xa) + $ya GUICtrlSetBkColor($aDot[$ii][$yy], 0x0000FF) Next Next EndFunc ;==>line GUISetState(@SW_SHOW, $hGui) While Sleep(10) WEnd Func quit() Exit EndFunc ;==>quit Func on_exit($sInput = 0) GUIDelete($hGui) EndFunc ;==>on_exit Visit my repository Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 1, 2015 Moderators Share Posted January 1, 2015 Detefon,How about using a graphic control? #include <GUIConstantsEx.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) GUISetBkColor(0xC4C4C4) $cGraphic = GUICtrlCreateGraphic(10, 10, 480, 400) GUICtrlSetColor($cGraphic, 0x000000) GUICtrlSetBkColor($cGraphic, 0xCCFFCC) GUICtrlSetGraphic($cGraphic, $GUI_GR_COLOR, 0xFF0000) $cButton = GUICtrlCreateButton("Draw", 10, 450, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton _GR_Move(2, 4) _GR_Line(18, 10) _GR_Line(200, 200) _WinAPI_RedrawWindow($hGUI) EndSwitch WEnd Func _GR_Move($iX, $iY) $iY = 400 - $iY GUICtrlSetGraphic($cGraphic, $GUI_GR_MOVE, $iX, $iY) EndFunc Func _GR_Line($iX, $iY) $iY = 400 - $iY GUICtrlSetGraphic($cGraphic, $GUI_GR_LINE, $iX, $iY) EndFuncI have used functions for each operation to get the Y coordinate to work in the correct sense. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Luigi Posted January 1, 2015 Author Share Posted January 1, 2015 (edited) Hi Melba, I need know the code/algorithm to draw a line... Sorry, Detefon. Edited January 1, 2015 by Detefon Visit my repository Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 1, 2015 Moderators Share Posted January 1, 2015 Detefon,Then if:How to draw a line from the point(2,4) until point(18,10)?is not your question, please explain what exactly you do want to know. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
UEZ Posted January 1, 2015 Share Posted January 1, 2015 (edited) This is only a partly solution: Func line($xa, $ya, $xb, $yb) Local $mm = ($yb - $ya) / ($xb - $xa) * 0.03333, $fDelta = 0.1 While $xa < $xb - $fDelta Or $ya < $yb - $fDelta GUICtrlSetBkColor($aDot[Int($xa)][Int($ya)], 0x0000FF) $xa += ($xb - $xa) * $mm $ya += ($yb - $ya) * $mm WEnd EndFunc ;==>line for $xa < $xb and $ya < $yb. The rest is homework for you. Br, UEZ Edited January 1, 2015 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Danyfirex Posted January 1, 2015 Share Posted January 1, 2015 (edited) hi. happy new year guys. Another way. Func DrawLine($x1,$y1,$x2,$y2) Local $x=0,$y=0 For $x = $x1 To $x2 $y=$y1+((($y2-$y1)/($x2-$x1))*($x-$x1)) ;DrawDot($x,$y) Next EndFunc Saludos Edited January 1, 2015 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Luigi Posted January 1, 2015 Author Share Posted January 1, 2015 is not your question, please explain what exactly you do want to know. In parts, not all... Draw a line is not simple a draw, it's check if there are a collision in an array, and let or not a moviment in this direction. A full idea is >here and here. https://www.youtube.com/watch?v=dq8UWEDU7q8 @UEZ, thank you, your code work fine! Visit my repository Link to comment Share on other sites More sharing options...
Luigi Posted January 1, 2015 Author Share Posted January 1, 2015 (edited) @Danyfirex, happy new year too! Thank you for your reply! Edited January 1, 2015 by Detefon Visit my repository Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now