ParoXsitiC Posted October 5, 2010 Share Posted October 5, 2010 I know using _GDIPlus_GraphicsDrawLine you can defined the start and stop of a line, but I want the line to go through these points, not just stop. something similar to this applet:http://www.cut-the-knot.org/Curriculum/Calculus/StraightLine.shtmlCan this be done? Link to comment Share on other sites More sharing options...
ParoXsitiC Posted October 5, 2010 Author Share Posted October 5, 2010 I know using _GDIPlus_GraphicsDrawLine you can defined the start and stop of a line, but I want the line to go through these points, not just stop. something similar to this applet:http://www.cut-the-knot.org/Curriculum/Calculus/StraightLine.shtmlCan this be done?I am thinking this should go in the GUI help...Please move it if you can Link to comment Share on other sites More sharing options...
jaberwacky Posted October 5, 2010 Share Posted October 5, 2010 Well, use the user's screen width and height to draw a complete line using the information you already have. You want to draw a line from (0,0) to (500,500) but you want to continue. The user has a screen resolution of 1000,1000 (this is all purely theoretical speculation), so use some math to get it 1000,1000. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
AlmarM Posted October 5, 2010 Share Posted October 5, 2010 (edited) I mayby know a method, but it take's some math and time. And time is what I don't have atm. EDIT: This is what i'm thinking: 1. Get the 2 points 2. Calculate the angle 3. Calculate the line down/up to screen width/height 4. Draw the line on the new calculated points. Edited October 5, 2010 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 5, 2010 Moderators Share Posted October 5, 2010 ParoXsitiC et al, Do you guys no longer do basic geometry at school! expandcollapse popup#include <GUIConstantsEx.au3> Global $X, $Y ; Define original points $X1 = 100 $Y1 = 100 $X2 = 400 $Y2 = 200 ; Gradient of line $nGradient = ATan(($Y2 - $Y1) / ($X2 - $X1)) ; Offset of line from origin $Y_Base = $X1 * Tan($nGradient) $nOffset = $Y1 - $Y_Base ; Line equation is therefore: $Y = ($X * Tan($nGradient)) + $nOffset ; Create GUI to draw line $hGUI = GUICreate("Test", 500, 500) ; Draw line using the equation from above For $i = 0 To 500 GUICtrlCreateLabel("", $i, ($i * Tan($nGradient)) + $nOffset, 2, 2) GUICtrlSetBkColor(-1, 0x0000FF) Next ; Show original points GUICtrlCreateLabel("", 100, 100, 4, 4) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlCreateLabel("", 400, 200, 4, 4) GUICtrlSetBkColor(-1, 0xFF0000) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd 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...
AlmarM Posted October 5, 2010 Share Posted October 5, 2010 I ruined my math classes. I never was interested by math, and now, since a while... I am. Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
czardas Posted October 5, 2010 Share Posted October 5, 2010 (edited) Do you guys no longer do basic geometry at school! It was a long time ago. Nice trig example, thanks!I think I'll use this to create an assortment of different shaped GUI controls, or just to paint. Edited October 5, 2010 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
UEZ Posted October 5, 2010 Share Posted October 5, 2010 Here a GDI+ version without trigonometry expandcollapse popup;fast hack by UEZ 2010 #include <GDIPlus.au3> #include <GUIConstantsEx.au3> Opt("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) _GDIPlus_Startup() Local $Width = 800 Local $Height = 600 Local $hGUI = GUICreate("GDI+ Math", $Width, $Height) Local $GUI_gbc = 0xF0F0F0 GUISetBkColor($GUI_gbc) GUISetState() Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $hGraphics) Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2) Local $hPen = _GDIPlus_PenCreate(0xFF0000FF, 1) Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000) Local $hBrush_size = 6 GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Local $rX1 = Random($Width * 0.2, $Width * 0.8) Local $rY1 = Random($Height * 0.2, $Height * 0.8) Local $rX2 = Random($Width * 0.2, $Width * 0.8) Local $rY2 = Random($Height * 0.2, $Height * 0.8) _GDIPlus_GraphicsClear($hBackbuffer, "0xFF" & $GUI_gbc) Local $slope_x = $rX2 - $rX1 Local $slope_y = $rY2 - $rY1 Local $len = 0.75 _GDIPlus_GraphicsDrawLine($hBackbuffer, $rX1, $rY1, $rX1 - $len * $slope_x, $rY1 - $len * $slope_y, $hPen) _GDIPlus_GraphicsDrawLine($hBackbuffer, $rX2, $rY2, $rX2 + $len * $slope_x, $rY2 + $len * $slope_y, $hPen) _GDIPlus_GraphicsDrawLine($hBackbuffer, $rX1, $rY1, $rX2, $rY2, $hPen) _GDIPlus_GraphicsFillEllipse($hBackbuffer, $rX1 - $hBrush_size / 2, $rY1 - $hBrush_size / 2, $hBrush_size, $hBrush_size, $hBrush) _GDIPlus_GraphicsFillEllipse($hBackbuffer, $rX2 - $hBrush_size / 2, $rY2 - $hBrush_size / 2, $hBrush_size, $hBrush_size, $hBrush) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $Width, $Height) While Sleep(1000) WEnd Func _Exit() _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hBackbuffer) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGUI) Exit EndFunc Br, 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...
AndyG Posted October 5, 2010 Share Posted October 5, 2010 (edited) Hi, there is no need to use the (slow) trigonometric functions!The function of a Line is y=m*x+b. So all you have to do is calculate m=deltay/deltax, put it into the transformed (is this the right expression in math?) equation, and calculate b.b=y-m*xso you have a formula, which calculates the right y to each x.expandcollapse popup#include <GUIConstantsEx.au3> Global $X, $Y ; Define original points $X1 = 100 $Y1 = 100 $X2 = 400 $Y2 = 200 ;y=mx+b $m=($y2-$y1)/($x2-$x1) ;deltay/deltax $b=$y1-$m*$x1 ; Create GUI to draw line $hGUI = GUICreate("Test", 500, 500) ; Draw line using the equation from above For $x = 0 To 500 $y=$m*$x+$b GUICtrlCreateLabel("", $x,$y , 2, 2) GUICtrlSetBkColor(-1, 0x0000FF) Next ; Show original points GUICtrlCreateLabel("", 100, 100, 4, 4) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlCreateLabel("", 400, 200, 4, 4) GUICtrlSetBkColor(-1, 0xFF0000) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd/edit/ this is also a quick way to determine whether a point is on a line Edited October 5, 2010 by AndyG Link to comment Share on other sites More sharing options...
czardas Posted October 5, 2010 Share Posted October 5, 2010 (edited) And to think that the Greeks did all this with a compas and an uncalibrated ruler. Examples like these are really clear. I must try to do something with GDI+, it seems so awesome. I do need some clickable controls of different shapes though. I was thinking that combining coloured labels as in Melba23's example would be a possibility, although perhaps there are easier solutions. Good thread! Edited October 5, 2010 by czardas operator64 ArrayWorkshop 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