Hallo Com,
ich habe heute auch mal ein Graphenzeichnenscript geschrieben. Ich weiß auch, dass es das schon öfters hier gab;
Dennoch wollte ich euch meine Version einmal vorstellen, um auf Bugs, Fehler und Verbesserungsvorschläge aufmerksam gemacht zu werden.
Es gibt ein Menü, man kann Markierungen setzen und Graphen in versch. Farben zeichnen!
Script
#include <ButtonConstants.au3>
#include <SliderConstants.au3>
#include <GuiSlider.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <GDIPlus.au3>
#include <SliderConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
;###User Options Start
$sCoordfarbe = "0xFF800000" ;Gitterfarbe in ARGB
$sGridColor = "0xFF99FFFF" ;Koordinatensystemfarbe in ARGB
$sBackgroundcolor = "0x000000" ;Hintergrundfarbe in RGB
$sXColor = "0xFFFFFFFF" ;Farbe der X, die beim Klicken erscheinen in ARGB
$iLineWidth = 6 ;Graphenlinienbreite
;###User Options Ende
;###Options Start
Opt("GuiOnEventMode", 1)
HotKeySet("{ESC}", "ende")
OnAutoItExitRegister("ende")
Const $iNullx = Round(@DesktopWidth / 2)
Const $iNully = Round(@DesktopHeight / 2)
$sTitle = "Funktionsgraph"
$sTitle2 = "Einstellungsmenü"
$bDrawed = False
;###Options Ende
;###Gui Start
$hGui = GUICreate($sTitle, @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetBkColor($sBackgroundcolor, $hGui)
GUISetState(@SW_SHOW, $hGui)
;Neue Gui:
$hSettings = GUICreate($sTitle2, 350, 280, @DesktopWidth - 350, @DesktopHeight - 280, BitOR($WS_CAPTION, $WS_GROUP), $WS_EX_TOPMOST, $hGui)
GUISetBkColor(0xFFFFFF, $hSettings)
$cMousePos = GUICtrlCreateLabel("MousePos:", 0, 0, 300, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$cCGrid = GUICtrlCreateCheckbox("Grid", 0, 25, 50, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
GUICtrlSetState(-1, $GUI_CHECKED)
$cCUnitCircle = GUICtrlCreateCheckbox("Unit Circle", 52, 25, 85, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$cCScale = GUICtrlCreateCheckbox("Scale", 140, 25, 60, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateButton("Generate", 202, 25, 80, 20)
GUICtrlSetOnEvent(-1, "generate")
GUICtrlCreateButton("Add function", 0, 60, 90, 20)
GUICtrlSetOnEvent(-1, "addfunc")
GUICtrlCreateButton("Delete function", 95, 60, 100, 20)
GUICtrlSetOnEvent(-1, "deletefunc")
GUICtrlCreateButton("Quit", 200, 60, 100, 20)
GUICtrlSetOnEvent(-1, "ende")
$cObjektlist = GUICtrlCreateListView("Objekttyp |Wert |Farbe ", 0, 82, 300, 140)
$cZoom = GUICtrlCreateSlider(310, 55, 25, 165, $TBS_VERT)
GUICtrlSetLimit(-1, 200, 1)
GUICtrlSetData($cZoom, 20)
$cZoomlabel = GUICtrlCreateLabel("Zoom:" & @CRLF & GUICtrlRead($cZoom), 296, 0, 40, 60)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
For $i = 10 To 200 Step 10
_GUICtrlSlider_SetTic($cZoom, $i)
Next
$cButtonBk = GUICtrlCreateButton("Background", 0, 230, 60, 20)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, $sBackgroundcolor)
GUICtrlSetOnEvent(-1, "setbk")
$cButtonSystem = GUICtrlCreateButton("System", 65, 230, 40, 20)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, StringReplace($sCoordfarbe, "0xFF", "0x"))
GUICtrlSetOnEvent(-1, "setsystem")
$cButtonGrid = GUICtrlCreateButton("Grid", 110, 230, 30, 20)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, StringReplace($sGridColor, "0xFF", "0x"))
GUICtrlSetOnEvent(-1, "setgrid")
$cButtonMark = GUICtrlCreateButton("Mark", 145, 230, 30, 20)
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetBkColor(-1, StringReplace($sXColor, "0xFF", "0x"))
GUICtrlSetOnEvent(-1, "setmark")
ControlFocus($sTitle2, "", $cObjektlist)
GUISetState(@SW_SHOW, $hSettings)
;###Gui Ende
;###GDIPlus Start
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
$Pen2 = _GDIPlus_PenCreate($sGridColor, 1)
$Pen1 = _GDIPlus_PenCreate($sCoordfarbe, 1)
$Pen3 = _GDIPlus_PenCreate($sXColor, 1)
$Brush1 = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
;###GDIPlus Ende
;generate()
[/autoit] [autoit][/autoit] [autoit]While 1
$aPos = MouseGetPos()
$iZoom = GUICtrlRead($cZoom) ;Zoom
$iAbstand = Round(@DesktopHeight / $iZoom)
GUICtrlSetData($cMousePos, "Mousepos: (" & Round(($aPos[0] - $iNullx) / $iAbstand, 2) & "|" & Round(calcytocoords($aPos[1]) / $iAbstand, 2) & ")")
If _IsPressed(01) Then
drawX()
Do
Until Not _IsPressed(01)
EndIf
GUICtrlSetData($cZoomlabel, "Zoom:" & @CRLF & GUICtrlRead($cZoom))
Sleep(100)
WEnd
ende()
Func generate()
GUISetBkColor($sBackgroundcolor, $hGui)
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
If GUICtrlRead($cCGrid) = $GUI_CHECKED Then
$bGrid = True
Else
$bGrid = False
EndIf
If GUICtrlRead($cCScale) = $GUI_CHECKED Then
$bScale = True
Else
$bScale = False
EndIf
If GUICtrlRead($cCUnitCircle) = $GUI_CHECKED Then
$bEinheitskreis = True
Else
$bEinheitskreis = False
EndIf
;###Netz erstellen Start
For $i = 1 To @DesktopWidth / $iAbstand ;Beschriftung
If $bGrid = True Then
_GDIPlus_GraphicsDrawLine($hGraphics, $iNullx + $iAbstand * $i, 0, $iNullx + $iAbstand * $i, @DesktopHeight, $Pen2) ;x rechts
_GDIPlus_GraphicsDrawLine($hGraphics, 0, $iNully - $iAbstand * $i, @DesktopWidth, $iNully - $iAbstand * $i, $Pen2);y oben
_GDIPlus_GraphicsDrawLine($hGraphics, 0, $iNully + $iAbstand * $i, @DesktopWidth, $iNully + $iAbstand * $i, $Pen2);y unten
_GDIPlus_GraphicsDrawLine($hGraphics, $iNullx - $iAbstand * $i, 0, $iNullx - $iAbstand * $i, @DesktopWidth, $Pen2);x links
EndIf
If $bScale = True Then
_GDIPlus_GraphicsDrawLine($hGraphics, $iNullx + $iAbstand * $i, $iNully - 10, $iNullx + $iAbstand * $i, $iNully + 10, $Pen1) ;x rechts
_GDIPlus_GraphicsDrawLine($hGraphics, $iNullx - 10, $iNully - $iAbstand * $i, $iNullx + 10, $iNully - $iAbstand * $i, $Pen1);y oben
_GDIPlus_GraphicsDrawLine($hGraphics, $iNullx - 10, $iNully + $iAbstand * $i, $iNullx + 10, $iNully + $iAbstand * $i, $Pen1);y unten
_GDIPlus_GraphicsDrawLine($hGraphics, $iNullx - $iAbstand * $i, $iNully - 10, $iNullx - $iAbstand * $i, $iNully + 10, $Pen1);x links
EndIf
Next
_GDIPlus_GraphicsDrawLine($hGraphics, 0, $iNully, @DesktopWidth, $iNully, $Pen1) ;x-Achse
_GDIPlus_GraphicsDrawLine($hGraphics, $iNullx, 0, $iNullx, @DesktopHeight, $Pen1);y-Achse
If $bEinheitskreis = True Then
_GDIPlus_GraphicsDrawEllipse($hGraphics, $iNullx - ($iAbstand * 1), $iNully - ($iAbstand * 1), $iAbstand * 2, $iAbstand * 2, $Pen1)
EndIf
GUISetState(@SW_DISABLE, $hSettings)
Sleep(1000)
;###Netz erstellen Ende
For $i = 0 To _GUICtrlListView_GetItemCount($cObjektlist) - 1
Local $sY = _GUICtrlListView_GetItemTextString($cObjektlist, $i)
Local $aSplitted = StringSplit($sY, "|")
If $aSplitted[1] = "Function" Then
draw($aSplitted[2], $aSplitted[3])
Else
Local $aSplitted2 = StringSplit($aSplitted[2], "/")
$aSplitted2[1] = StringReplace($aSplitted2[1], "(", "")
$aSplitted2[2] = StringReplace($aSplitted2[2], ")", "")
drawX(Round(($aSplitted2[1] * $iAbstand) + $iNullx), Round((($aSplitted2[2] * (-1)) * $iAbstand) + $iNully))
EndIf
Next
GUISetState(@SW_ENABLE, $hSettings)
ToolTip("Done!")
Sleep(2000)
ToolTip("")
EndFunc ;==>generate
Func draw($sFunktion, $sColor)
Local $Brush1 = _GDIPlus_BrushCreateSolid($sColor)
$sFunktion = StringReplace($sFunktion, "x", "($i / $iAbstand)")
ToolTip(StringReplace(StringReplace($sFunktion, "$i", "x"), " / xAbstand", ""))
Sleep(2000)
For $i = -(@DesktopWidth / 2) To @DesktopWidth / 2
ToolTip("i = " & $i & "; X = " & Round(Calcxtocoords($i)) & "; Y = " & Round(calcytocoords(Execute($sFunktion))) & "; Funktionswert = " & Execute($sFunktion))
_GDIPlus_GraphicsFillEllipse($hGraphics, Round(Calcxtocoords($i) - ($iLineWidth / 2)), Round(calcytocoords(Execute($sFunktion) * ($iAbstand)) - ($iLineWidth / 2)), $iLineWidth, $iLineWidth, $Brush1)
Next
$bDrawed = True
EndFunc ;==>draw
Func drawX($iMousePosx = -1, $iMousePosy = -1)
If $bDrawed = False Then Return
If $iMousePosx = -1 And $iMousePosy = -1 Then
If WinGetState($sTitle2, "") = 8 Then Return
If _MousePosCheck() = 1 Then Return
Local $aPos = MouseGetPos()
$iMousePosx = $aPos[0]
$iMousePosy = $aPos[1]
_GDIPlus_GraphicsDrawLine($hGraphics, $aPos[0] - 7, $aPos[1] - 7, $aPos[0] + 7, $aPos[1] + 7, $Pen3)
_GDIPlus_GraphicsDrawLine($hGraphics, $aPos[0] + 7, $aPos[1] - 7, $aPos[0] - 7, $aPos[1] + 7, $Pen3)
GUICtrlCreateListViewItem("Mark|(" & Round(($aPos[0] - $iNullx) / $iAbstand, 2) & "/" & Round(calcytocoords($aPos[1]) / $iAbstand, 2) & ")|" & $sXColor, $cObjektlist)
Else
_GDIPlus_GraphicsDrawLine($hGraphics, $iMousePosx - 7, $iMousePosy - 7, $iMousePosx + 7, $iMousePosy + 7, $Pen3)
_GDIPlus_GraphicsDrawLine($hGraphics, $iMousePosx + 7, $iMousePosy - 7, $iMousePosx - 7, $iMousePosy + 7, $Pen3)
EndIf
EndFunc ;==>drawX
Func addfunc()
$bDrawed = False
Do
Local $sInputFunktion = InputBox("Function", "Enter a function, please!" & @CRLF & "Use x for the variable!" & @CRLF & "Y=", Default, Default, Default, Default, Default, Default, $hGui)
Until $sInputFunktion <> "" Or @error
If @error Then Return
Do
Local $sColor = _ChooseColor(2, 0x990000, Default, $hGui)
Until $sColor <> -1 Or @error
If @error Then Return
Local $sColor2 = StringReplace($sColor, "0x", "0xFF")
GUICtrlSetBkColor(GUICtrlCreateListViewItem("Function|" & $sInputFunktion & "|" & $sColor2, $cObjektlist), $sColor)
EndFunc ;==>addfunc
Func _MousePosCheck()
Local $aPos = WinGetPos($sTitle2)
$x_check = $aPos[0]
$y_check = $aPos[1]
$x_size = $aPos[2]
$y_size = $aPos[3]
If MouseGetPos(0) >= $x_check And MouseGetPos(0) <= $x_check + $x_size And MouseGetPos(1) >= $y_check And MouseGetPos(1) <= $y_check + $y_size Then
Return (1)
Else
Return (0)
EndIf
EndFunc ;==>_MousePosCheck
Func deletefunc()
_GUICtrlListView_DeleteItemsSelected($cObjektlist)
EndFunc ;==>deletefunc
Func setbk()
$sBackgroundcolor = _ChooseColor(2, 0x000000)
GUICtrlSetBkColor($cButtonBk, $sBackgroundcolor)
EndFunc ;==>setbk
Func setmark()
$sXColor = StringReplace(_ChooseColor(2, 0x000000), "0x", "0xFF")
GUICtrlSetBkColor($cButtonMark, $sXColor)
EndFunc ;==>setmark
Func setgrid()
$sGridColor = StringReplace(_ChooseColor(2, 0x000000), "0x", "0xFF")
GUICtrlSetBkColor($cButtonGrid, $sGridColor)
EndFunc ;==>setgrid
Func setsystem()
$sCoordfarbe = StringReplace(_ChooseColor(2, 0x000000), "0x", "0xFF")
GUICtrlSetBkColor($cButtonSystem, $sCoordfarbe)
EndFunc ;==>setsystem
Func calcxtocoords($iX)
Return $iX + $iNullx
EndFunc ;==>calcxtocoords
Func calcytocoords($iY)
Return (-$iY + $iNully)
EndFunc ;==>calcytocoords
Func ende()
_GDIPlus_PenDispose($Pen1)
_GDIPlus_PenDispose($Pen2)
_GDIPlus_PenDispose($Pen3)
_GDIPlus_BrushDispose($Brush1)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>ende