Code: Select all
#Image = 0
#Gadget_TrackBarLeft = 0
#Gadget_TrackBarRight = 1
#Gadget_TrackBarBottom = 2
#Gadget_Image = 3
#exp = 2.71828183
Procedure UpdateGraph(imageno.l, type.l, y1.d, y2.d, b.d)
width.l = ImageWidth(imageno)
height.l = ImageHeight(imageno)
StartDrawing(ImageOutput(imageno))
Box(0, 0, width, height)
col.l = RGB(0, 255, 0)
If b = 0
type = 0
EndIf
y.d = y1
prevy.d = y
Select type
Case 0
stepy.d = (y2 - y1) / width
For x = 1 To width - 1
y + stepy
LineXY(x - 1, prevy, x, y, col)
prevy = y
Next
Case 1
stepy.d = (y2 - y1) / width
a.d = (y2 - y1) / (Pow(#exp, b * width) - 1)
d.d = y1 - a
mult.d = Pow(#exp, b)
For x = 1 To width - 1
y = (prevy - d) * mult + d
LineXY(x - 1, prevy, x, y, col)
prevy = y
Next
EndSelect
StopDrawing()
EndProcedure
Procedure UpdateImage()
height = ImageHeight(#Image)
UpdateGraph(#Image, 1, height - GetGadgetState(#Gadget_TrackBarLeft), height - GetGadgetState(#Gadget_TrackBarRight), (GetGadgetState(#Gadget_TrackBarBottom) - 50) / 1000)
SetGadgetState(#Gadget_Image, ImageID(#Image))
EndProcedure
imwidth.l = 400
imheight.l = 240
CreateImage(#Image, imwidth, imheight)
OpenWindow(0, 0, 0, imwidth + 56, imheight + 44, "Graph test", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
TrackBarGadget(#Gadget_TrackBarLeft, 4, 4, 20, imheight + 16, 0, imheight, #PB_TrackBar_Vertical)
TrackBarGadget(#Gadget_TrackBarRight, imwidth + 32, 4, 20, imheight + 16, 0, imheight, #PB_TrackBar_Vertical)
TrackBarGadget(#Gadget_TrackBarBottom, 4, imheight + 16, imwidth + 48, 20, 0, 100)
SetGadgetState(#Gadget_TrackBarLeft, 0)
SetGadgetState(#Gadget_TrackBarRight, imheight)
SetGadgetState(#Gadget_TrackBarBottom, 50)
ImageGadget(#Gadget_Image, 28, 12, imwidth, imheight, ImageID(#Image))
UpdateImage()
Repeat
event = WaitWindowEvent()
eventgadget = EventGadget()
Select event
Case #PB_Event_Gadget
If eventgadget = #Gadget_TrackBarLeft Or eventgadget = #Gadget_TrackBarRight Or eventgadget = #Gadget_TrackBarBottom
UpdateImage()
EndIf
EndSelect
Until event = #PB_Event_CloseWindow