I was wondering why the following code does not scale correctly when using PB5.73 (works fine with PB6.04)...
Code: Select all
; Define
#X=500
#Y=500
#Xa=-100
#Xb=100
#Ya=-100000
#Yb=100000
#epsilon=0.0000001
#dots=10
Global scalex.d
Global scaley.d
; EndDefine
Procedure.d xo(x.d)
ProcedureReturn x*scalex
EndProcedure
Procedure.d yo(y.d)
ProcedureReturn y*scaley
EndProcedure
Procedure.d x(x.d)
ProcedureReturn (x-#Xa)*scalex
EndProcedure
Procedure.d y(y.d)
ProcedureReturn (y-#Ya)*scaley
EndProcedure
Procedure.d function(x.d)
If x=0
ProcedureReturn 0; Infinitive
Else
ProcedureReturn 653184000/499/x
EndIf
EndProcedure
Procedure.d axis(minx.d,maxx.d,miny.d,maxy.d,stepx.d=1,stepy.d=1,width.d=1)
Protected.s s
Protected.d x,y
MovePathCursor(x(minx),y(0))
While minx<=maxx
x=PathCursorX()
y=PathCursorY()
s=Str(minx)
MovePathCursor(x-VectorTextWidth(s)/2,y)
FlipCoordinatesY(0,#PB_Coordinate_User)
DrawVectorText(s)
FlipCoordinatesY(0,#PB_Coordinate_User)
MovePathCursor(x,y)
minx+stepx
AddPathLine(x(minx),y(0))
AddPathLine(0,5,#PB_Path_Relative)
MovePathCursor(0,-5,#PB_Path_Relative)
Wend
StrokePath(width)
MovePathCursor(x(0),y(miny))
While miny<=maxy
If miny
x=PathCursorX()
y=PathCursorY()
s=Str(miny)
MovePathCursor(x-12-VectorTextWidth(s)/2,y+VectorTextHeight(s)/2)
FlipCoordinatesY(0,#PB_Coordinate_User)
DrawVectorText(s)
FlipCoordinatesY(0,#PB_Coordinate_User)
MovePathCursor(x,y)
EndIf
miny+stepy
AddPathLine(x(0),y(miny))
AddPathLine(5,0,#PB_Path_Relative)
MovePathCursor(-5,0,#PB_Path_Relative)
Wend
StrokePath(width)
EndProcedure
Procedure.d draw(minx.d,maxx.d,steps=100,color=#Red,width=3)
Protected.d stepx
Protected.d dot
stepx=(maxx-minx)/steps
MovePathCursor(x(minx),y(function(minx)))
While minx<=maxx
minx+stepx
AddPathLine(x(minx),y(function(minx)))
x=PathCursorX()
y=PathCursorY()
VectorSourceColor($FF000000|color)
StrokePath(width)
dot=Round(minx/#dots,#PB_Round_Down)*#dots
If minx>dot-#epsilon And minx<dot+#epsilon
AddPathCircle(x,y,5)
VectorSourceColor($FF000000)
FillPath()
AddPathCircle(x,y,2)
VectorSourceColor($FFFFFFFF)
FillPath()
EndIf
MovePathCursor(x,y)
Wend
EndProcedure
Procedure main()
LoadFont(0,"Segoe UI",10)
OpenWindow(0,0,0,#X,#Y,"Function Plotter",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CanvasGadget(0,0,0,#X,#Y)
StartVectorDrawing(CanvasVectorOutput(0))
scalex=#X/(#Xb-#Xa)
scaley=#Y/(#Yb-#Ya)
; ScaleCoordinates(scalex,scaley)
; TranslateCoordinates(-#Xa,-#Ya)
; FlipCoordinatesY(y(0))
FlipCoordinatesY(#Y/2)
VectorFont(FontID(0),15)
axis(#Xa,#Xb,#Ya,#Yb,#dots,10000)
draw(#Xa,#Xb,1000)
StopVectorDrawing()
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndProcedure
main()