Anonymous user
Plot coordinate pairs: Difference between revisions
→{{header|PureBasic}}: Corrected Y Scale, refined code
(→{{header|PureBasic}}: Corrected Y Scale, refined code) |
|||
Line 445:
EndStructure
Global i, x, y.f, max_x, max_y, min_x = #MAXLONG, min_y = Infinity()
Global Dim MyData.PlotData(count)
Restore serie_x
For i = 0 To count
Read.i x
MyData(i)\x = x
If x > max_x: max_x = x: EndIf
If x < min_x: min_x = x: EndIf
Next
Restore serie_y
For i = 0 To count
Read.f y
MyData(i)\y = y
If y > max_y: max_y = y: EndIf
If y < min_y: min_y = y: EndIf
Next
Procedure UpdatePlot(Win, w, h)
Static gblm = 20, gtrm = 5 ;graph's bottom-left and top-right margin
SetWindowTitle(win,"PureBasic Plot "+Str(w)+"x"+Str(h))▼
If w > gblm And h > gblm And count > 0
Protected x1,x2,y1,y2▼
Protected gw = w - gblm, gh = h - gblm ;graph's width and height
yf=(h-20)/max_y*0.99▼
xf=(w-20)/max_x*0.99▼
CreateImage(0,w,h)▼
Define OutputID=ImageOutput(0)▼
▲ CreateImage(0, w, h)
StartDrawing(OutputID)
DrawingMode(#PB_2DDrawing_Transparent)
LineXY(20,h-20,w,h-20,$FFFFFF)▼
LineXY(20,h-20,20,0,$FFFFFF)▼
For i=0 To amounts▼
;- Draw grid
y2=y1▼
; Y-scale▼
▲ LineXY(x1,y1,x2,y2,$467E3E)
▲ ; Y-scale
x = gblm + max_x * i / count * xf
▲ DrawText(1,y1-5,RSet(StrD(i/10*max_y,1),5))
▲ If i: DrawText(x1-5,y1+2,Str(i)): EndIf
;- Draw curve
Protected ox = gblm, oy = gh, x, y
x=20+MyData(i)\x*xf▼
▲ Next
ox = x: oy = y
Next
StopDrawing()
ImageGadget(0, 0, 0, w, h, ImageID(0))
EndIf
EndProcedure
Define
If Win
SmartWindowRefresh(Win, 1)
UpdatePlot(Win, WindowWidth(Win), WindowHeight(
Repeat
Define
Select
Case #PB_Event_SizeWindow
UpdatePlot(Win, WindowWidth(Win), WindowHeight(
EndSelect
Until
; Save the plot if the user wants to
▲ Define file$=SaveFileRequester("Save as","PB.png","PNG (*.png)|*.png",0)
UsePNGImageEncoder()
SaveImage(0,
EndIf
EndIf
|