Re: CalculateIt - Mathematische Terme ausrechnen
Verfasst: 01.08.2010 23:37
Und noch ein ziemlich einfach gehaltenes Testprogramm:


Code: Alles auswählen
IncludeFile "CalculateIt.pb"
Procedure GenerateGraph(Term.s)
Protected Index.i
Protected Result.d, LastResult.d
Protected PosX.d
CreateImage(0, 400, 400)
If StartDrawing(ImageOutput(0))
FrontColor($404040)
For Index = -20 To 20
Line(200 + Index * 10, 0, 1, 400)
Line(0, 200 + Index * 10, 400, 1)
Next
Line(0, 200, 400, 1, $FFFFFF)
Line(200, 0, 1, 400, $FFFFFF)
FrontColor($FF)
For Index = 0 To 400
PosX = (Index - 200) / 10
Result = Calculate(ReplaceString(UCase(Term), "X", "(" + StrD(PosX, 16) + ")"))
LineXY(Index - 1, 200 - LastResult * 10, Index, 200 - Result * 10)
LastResult = Result
Next
StopDrawing()
SetGadgetState(1, ImageID(0))
EndIf
EndProcedure
OpenWindow(0, 0, 0, 420, 450, "CalculateIt - Graphical test", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
StringGadget(0, 10, 10, 400, 20, "")
ImageGadget(1, 10, 40, 400, 400, 0)
Repeat
Define EventID.i = WaitWindowEvent()
If EventID = #PB_Event_Gadget
If EventGadget() = 0 And EventType() = #PB_EventType_Change
GenerateGraph(GetGadgetText(0))
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow