المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : رسم منحى بياني للدوال


ثامر أبو بلقيس
07-09-2013, 12:14 AM
السلام عليكم ورحمة الله
أعجبت كثيرا بهذه الأكواد التي تستطيع بنسخها في برنامج autoit
الحصول على أداة متكاملة ترسم منحى بياني لجل الدوال
إليك بالأكواد واذ رغبت أخي تحويلها لتنفيذي فلابأس
#NoTrayIcon
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <Misc.au3>

Global $DesktopWidth =@DesktopWidth ;Number(IniRead(@ScriptDir & "\conf.ini","Dimensiones","Ancho",800))
Global $DesktopHeight =@DesktopHeight ;Number(IniRead(@ScriptDir & "\conf.ini","Dimensiones","Alto",600))




Dim $CoordOrigen[2] = [$DesktopWidth/2+2,$DesktopHeight/2-2]
Global $escY
Global $escX
Global $ColorFondo = IniRead(@ScriptDir & "\conf.ini","Colores","Fondo",0xFFFFFF)
Global $ColorGrafica = IniRead(@ScriptDir & "\conf.ini","Colores","Grafica",0xFF0000)
Global $ColorCuadricula= IniRead(@ScriptDir & "\conf.ini","Colores","Cuadricula",0xE7E7E7)
Global $ColorEjes = IniRead(@ScriptDir & "\conf.ini","Colores","Ejes",0x000000)
Global $Main,$child
Global $MostrarCuadricula =False
Global $MostrarEscala =False

$Main = GUICreate("Drawer - © Nahuel", 568, 195)
$inpFunc = GUICtrlCreateInput("", 60, 6, 181, 21)
GUICtrlCreateLabel("f(x)=", 18, 6, 40, 24)
GUICtrlSetFont(-1, 12, 800, 2, "Microsoft Sans Serif")
$Button1 = GUICtrlCreateButton("Sin()", 18, 44, 51, 21, 0)
$Button2 = GUICtrlCreateButton("ASin()", 72, 44, 51, 21, 0)
$Button3 = GUICtrlCreateButton("Cos()", 18, 71, 51, 21, 0)
$Button4 = GUICtrlCreateButton("ACos()", 72, 71, 51, 21, 0)
$Button6 = GUICtrlCreateButton("Tan()", 18, 98, 51, 21, 0)
$Button7 = GUICtrlCreateButton("ATan()", 72, 98, 51, 21, 0)
$Button8 = GUICtrlCreateButton("ln()", 146, 44, 51, 21, 0)
$Button9 = GUICtrlCreateButton("V¯", 200, 44, 51, 21, 0)
$Button10 = GUICtrlCreateButton("| X |", 146, 71, 51, 21, 0)
$Button11= GUICtrlCreateButton("X", 200, 71, 51, 21, 0)
$Button12 = GUICtrlCreateButton(")", 146, 98, 51, 21, 0)
$Button13 = GUICtrlCreateButton("^", 200, 98, 51, 21, 0)
$Button14 = GUICtrlCreateButton("+", 18, 134, 51, 21, 0)
$Button15 = GUICtrlCreateButton("*", 72, 134, 51, 21, 0)
$Button16 = GUICtrlCreateButton("-", 18, 160, 51, 21, 0)
$Button17 = GUICtrlCreateButton("/", 72, 160, 51, 21, 0)
$Button18 = GUICtrlCreateButton("&Draw graph", 146, 134, 105, 49, $BS_DEFPUSHBUTTON)

$Slider1 = GUICtrlCreateSlider(262, 42, 161, 19)
GUICtrlSetLimit(-1,100,10)
GUICtrlSetData(-1,25)
$Slider2 = GUICtrlCreateSlider(262, 80, 161, 19)
GUICtrlSetLimit(-1,100,10)
GUICtrlSetData(-1,25)

GUICtrlCreateLabel("X axis scale", 306, 28, 64, 17)
GUICtrlCreateLabel("Y axis scale", 308, 66, 64, 17)
GUICtrlCreateGroup("", 256, 16, 297, 171)

GUICtrlCreateLabel("Bgnd color:", 264, 108,80, 17)
$lab_ColorFondo=GUICtrlCreateLabel("", 352, 108, 24, 17)
GUICtrlSetBkColor(-1,$ColorFondo)
$CambiarColorFondo= GUICtrlCreateButton("Change", 384, 106, 61, 17, 0)
GUICtrlCreateLabel("Graph color:", 264, 127, 63, 17)
$lab_ColorGrafica=GUICtrlCreateLabel("", 352, 126, 24, 17)
GUICtrlSetBkColor(-1,$ColorGrafica)
$CambiarColorGrafica = GUICtrlCreateButton("Change", 384, 125, 61, 17, 0)
GUICtrlCreateLabel("Grid color:", 264, 146, 82, 17)
$lab_ColorCuad=GUICtrlCreateLabel("", 352, 144, 24, 17)
GUICtrlSetBkColor(-1,$ColorCuadricula)
$CambiarColorCuad = GUICtrlCreateButton("Change", 384, 144, 61, 17, 0)

GUICtrlCreateLabel("Axis color", 264, 164, 50, 17)
$lab_ColorEjes=GUICtrlCreateLabel("", 352, 164, 24, 17)
GUICtrlSetBkColor(-1,$ColorEjes)
$CambiarColorEjes = GUICtrlCreateButton("Change", 384, 164, 61, 17, 0)

$CheckboxMostrarCuad = GUICtrlCreateCheckbox("Show grid", 438, 44, 111, 15)
GUICtrlSetState(-1,$GUI_CHECKED)
$CheckboxMostrarEsca = GUICtrlCreateCheckbox("Show scale", 438, 80, 111, 15)
GUICtrlSetState(-1,$GUI_CHECKED)

$GuardarConf = GUICtrlCreateButton("Save", 458, 120, 75, 27, 0)
$ResetConf = GUICtrlCreateButton("Restore", 458, 150, 75, 27, 0)


GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $CambiarColorEjes
$newColor=_ChooseColor(2,$ColorEjes,2,$Main)
If @error Then ContinueLoop
GUICtrlSetBkColor($lab_ColorEjes,$newColor)
$ColorEjes=$newColor
Case $CambiarColorCuad
$newColor=_ChooseColor(2,$ColorCuadricula,2,$Main)
If @error Then ContinueLoop
GUICtrlSetBkColor($lab_ColorCuad,$newColor)
$ColorCuadricula=$newColor
Case $CambiarColorFondo
$newColor=_ChooseColor(2,$ColorFondo,2,$Main)
If @error Then ContinueLoop
GUICtrlSetBkColor($lab_ColorFondo,$newColor)
$ColorFondo=$newColor
Case $CambiarColorGrafica
$newColor=_ChooseColor(2,$ColorGrafica,2,$Main)
If @error Then ContinueLoop
GUICtrlSetBkColor($lab_ColorGrafica,$newColor)
$ColorGrafica=$newColor
Case $GuardarConf
IniWrite(@ScriptDir & "\conf.ini","Colores","Fondo",$ColorFondo)
IniWrite(@ScriptDir & "\conf.ini","Colores","Grafica", $ColorGrafica)
IniWrite(@ScriptDir & "\conf.ini","Colores","Cuadricula", $ColorCuadricula)
IniWrite(@ScriptDir & "\conf.ini","Colores","Ejes", $ColorEjes)
_MsgBox(64,"Saved","Your color preferences have been saved",$Main)
Case $ResetConf
FileDelete(@ScriptDir & "\conf.ini")
$ColorFondo=0xFFFFFF
$ColorGrafica=0xFF0000
$ColorCuadricula=0xE7E7E7
$ColorEjes=0x000000
GUICtrlSetBkColor($lab_ColorGrafica,$ColorGrafica)
GUICtrlSetBkColor($lab_ColorFondo,$ColorFondo)
GUICtrlSetBkColor($lab_ColorCuad,$ColorCuadricula)
GUICtrlSetBkColor($lab_ColorEjes,$ColorEjes)
Case $Button1
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"Sin(")
Case $Button2
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"ASin(")
Case $Button3
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"Cos(")
Case $Button4
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"ACos(")
Case $Button6
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"Tan(")
Case $Button7
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"ATan(")
Case $Button8
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"Log(")
Case $Button9
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"Sqrt(")
Case $Button10
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"Abs(")
Case $Button11
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"X")
Case $Button12
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&")")
Case $Button13
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"^")
Case $Button14
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"+")
Case $Button15
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"*")
Case $Button16
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"-")
Case $Button17
ControlFocus($Main,"",$inpFunc)
GUICtrlSetData($inpFunc,GUICtrlRead($inpFunc)&"/")
Case $Button18
$Func=GUICtrlRead($inpFunc)

$ParentesisA=StringSplit($Func,"(")
$ParentesisC=StringSplit($Func,")")

If Not IsArray($ParentesisA) Then
Dim $ParentesisA[1]=[0]
EndIf
If Not IsArray($ParentesisC) Then
Dim $ParentesisC[1]=[0]
EndIf

If $ParentesisA[0]>$ParentesisC[0] Then
$ParsQueFaltan=$ParentesisA[0]-$ParentesisC[0]
$FuncNueva=$Func
For $i=0 To $ParsQueFaltan-1
$FuncNueva&=")"
Next
Dim $iMsgBoxAnswer
$iMsgBoxAnswer = _MsgBox(52,"Error in expression","Unbalanced bracket expression." & @CRLF & "Accept correction?" & @CRLF & $FuncNueva,$Main)
Select
Case $iMsgBoxAnswer = 6 ;Yes
GUICtrlSetData($inpFunc,$FuncNueva)
_Graficar($FuncNueva)
Case $iMsgBoxAnswer = 7 ;No
ContinueLoop
EndSelect
ElseIf $ParentesisA[0]<$ParentesisC[0] Then
_MsgBox(48,"Error in expression","Unbalanced bracket expression.",$Main)
ElseIf $ParentesisA[0]=$ParentesisC[0] Then
_Graficar($Func)
EndIf
EndSwitch
WEnd

Func _Graficar($strFunc)
$escX=Number(GUICtrlRead($Slider1))
$escY=Number(GUICtrlRead($Slider2))
$MostrarCuadricula=False
$MostrarEscala=False
If GUICtrlRead($CheckboxMostrarCuad)=$GUI_CHECKED Then $MostrarCuadricula=True
If GUICtrlRead($CheckboxMostrarEsca)=$GUI_CHECKED Then $MostrarEscala=True


$child=GUICreate("",$DesktopWidth,$DesktopHeight,-1,-1,-1,-1,$Main)

GUISetBkColor($ColorFondo,$child);Color blanco de fondo
$exit=GUICtrlCreateButton("&Exit",$DesktopWidth-150,$DesktopHeight-50,100);Botَn
GUIctrlSetCursor(-1,2)

_DibuarEjes()

$grafico = GUICtrlCreateGraphic(0,0,$DesktopWidth,$DesktopHei ght)
GUISetCursor(3,1)
GUICtrlSetGraphic(-1,$GUI_GR_COLOR,$ColorGrafica)
$strFunc=String("-(" & $strFunc & ")*"&$escY)
SplashTextOn("",@CRLF&"Drawing...",150,57,-1,-1,1)

;~ GUICtrlSetGraphic(-1,$GUI_GR_COLOR,$ColorGrafica)
;Dibujar grلfica:
Dim $Asintotas[1]

$asC=0

For $X=-$CoordOrigen[0] To $CoordOrigen[0]
GUICtrlSetGraphic($grafico ,$GUI_GR_COLOR,$ColorGrafica)
$exFunc=$strFunc
$exFunc=StringReplace($exFunc,"x",$X/$escX)
$Y=Execute($exFunc)
If StringInStr(String($Y),"INF") Then
$Asintotas[$asC]="Vertical Asymptote at X=" & $X/$escX
$asC+=1
ReDim $Asintotas[$asC+1]
EndIf
GUICtrlSetGraphic($grafico,$GUI_GR_LINE,$CoordOrig en[0]+$X-2,$CoordOrigen[1]+$Y+2)

Next
GUICtrlSetGraphic($grafico,$GUI_GR_MOVE,0,0)
GUICtrlSetGraphic($grafico,$GUI_GR_CLOSE+$GUI_GR_D OT)

SplashOff()
GUISetState()
$strAsintotas=""
If $asC>0 Then
For $i=0 To UBound($Asintotas)-1
$strAsintotas&=@CRLF&$Asintotas[$i]
Next
EndIf

While 1
$nMsg=GUIGetMsg()
if $nMsg=-3 Or $nMsg=$exit Then ExitLoop
$mousepos=MouseGetPos()
$x_tooltip=($mousepos[0]-$CoordOrigen[0])/$escX
$y_tooltip=(-$mousepos[1]+$CoordOrigen[1])/$escY

ToolTip("X: " & $x_tooltip & ", Y: "& $y_tooltip & @CRLF & $strAsintotas,$mousepos[0]+5,$mousepos[1]+5,"Coords")

Sleep(25)
WEnd
ToolTip("")
GUIDelete()
EndFunc

Func _MsgBox($iFlags, $sTitle, $sText, $hWnd = 0)
Local $aRet = DllCall('user32.dll', 'int', 'MessageBox', 'hwnd', $hWnd, 'str', $sText, 'str', $sTitle, 'uint', $iFlags)
Return $aRet[0]
EndFunc ;==>_MsgBox

Func _DibuarEjes()

$gEje_Y=GUICtrlCreateGraphic($DesktopWidth/2,0,1,$DesktopHeight);Eje Y
GUICtrlSetBkColor(-1,$ColorEjes)
$x=0
For $i=$CoordOrigen[1] To $DesktopHeight Step $escY
GUICtrlSetGraphic($gEje_Y,$GUI_GR_DOT,0,$i+2)
If $MostrarEscala Then
GUICtrlCreateLabel(-$x,$CoordOrigen[0],$i+2)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
EndIf
if $MostrarCuadricula Then
GUICtrlCreateGraphic(0,$i+2,$DesktopWidth,1)
GUICtrlSetColor(-1,$ColorCuadricula)
EndIf
$x+=1
Next
$x=0
For $i=$CoordOrigen[1] To 0 Step -$escY
GUICtrlSetGraphic($gEje_Y,$GUI_GR_DOT,0,$i+2)
If $MostrarEscala Then
GUICtrlCreateLabel($x,$CoordOrigen[0],$i+2)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
EndIf
If $MostrarCuadricula Then
GUICtrlCreateGraphic(0,$i+2,$DesktopWidth,1)
GUICtrlSetColor(-1,$ColorCuadricula)
EndIf
$x+=1
Next

$gEje_X=GUICtrlCreateGraphic(0,$DesktopHeight/2,$DesktopWidth,1);Eje X
GUICtrlSetBkColor(-1,$ColorEjes)
$x=-1
For $i=$CoordOrigen[0] To $DesktopWidth Step $escX
$x+=1
GUICtrlSetGraphic($gEje_X,$GUI_GR_DOT,$i-2,0)
If $x=0 Then ContinueLoop
If $MostrarCuadricula then
GUICtrlCreateGraphic($i-2,0,1,$DesktopHeight)
GUICtrlSetColor(-1,$ColorCuadricula)
EndIf
If $MostrarEscala then
GUICtrlCreateLabel($x,$i+2,$CoordOrigen[1]+3)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
EndIf
Next
$x=-1
For $i=$CoordOrigen[0] To 0 Step -$escX
$x+=1
GUICtrlSetGraphic($gEje_X,$GUI_GR_DOT,$i-2,0)
If $x=0 Then ContinueLoop
If $MostrarCuadricula Then
GUICtrlCreateGraphic($i-2,0,1,$DesktopHeight)
GUICtrlSetColor(-1,$ColorCuadricula)
EndIf
If $MostrarEscala Then
GUICtrlCreateLabel(-$x,$i+2,$CoordOrigen[1]+3)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
EndIf
Next
EndFunc

موفق :abc_023:

أبو يوسف
07-09-2013, 01:18 PM
جزاك الله خيرا اخانا ابا بلقيس

جهود مباركة

.

ثامر أبو بلقيس
07-09-2013, 04:24 PM
مشكووووور على المجهود

شكرا جزيلا:abc_022:

abohmam
15-09-2013, 10:31 PM
جزاك الله خيرا أخى ابا بلقيس

بارك الله في جهودك

أبو صخر
16-09-2013, 01:12 PM
شـكــ وبارك الله فيك ـــرا لك ... لك مني أجمل تحية .

الحارث بن فيصل
20-09-2013, 02:08 PM
خالص الشكر والامتنان على ما بذلتموه من جهود مباركة

ثامر أبو بلقيس
25-01-2014, 09:42 PM
مرور عطر اخواني :abc_152:

الهمام
28-01-2014, 04:00 PM
شـكــ وبارك الله فيك ـــرا لك ... لك مني أجمل تحية .