aUCBLogo Demos and Tests / xygraphtest
be xygraphtest
xy
end
be XYGraph frm width height
local [g x y w h x0 y0 w0 h0 zx zy zx0 zy0 p0 p pz
mouseleft mouseright inmotion]
g=(Graph frm
wxDefault_Frame_Style+wxFull_Repaint_on_Resize ;+wxStay_on_Top
[0 0] List width height [Graph])
hideTurtle
x=0
y=0
x0=0
y0=0
w=0
h=0
w0=0
h0=0
zx=1
zy=1
zx0=1
zy0=1
p0=[0 0 0]
p=[0 0 0]
pz=[0 0 0]
mouseleft=false
mouseright=false
inmotion=false
be init
WindowOnLeftDown g
[
if not mouseleft
[ GraphSetCurrent g
p0=MousePos+p
x0=p0.1+x
y0=p0.2+y
mouseleft=true
]
]
WindowOnLeftUp g
[
mouseleft=false
GraphSetCurrent g
p0=p0-MousePos+p
x=p.1
y=p.2
]
WindowOnRightDown g
[
if not mouseright
[ GraphSetCurrent g
p0=MousePos+pz
w0=p0.1+w
h0=p0.2+h
mouseright=true
]
]
WindowOnRightUp g
[
mouseright=false
GraphSetCurrent g
p0=p0-MousePos+pz
w=p.1
h=p.2
zx0=zx0*(1+w/800)
zy0=zy0*(1+h/600)
]
WindowOnMotion g
[
if mouseleft and2 not inmotion
[ GraphSetCurrent g
p=p0-MousePos
x=p.1
y=p.2
setScreenRange -400+x -300+y 400+x 300+y
redraw
updateGraph
]
if mouseright and2 not inmotion
[ GraphSetCurrent g
pz=p0-MousePos
w=pz.1
h=pz.2
zx=zx0*(1+w/800)
zy=zy0*(1+h/600)
setScrunch zx zy 1
redraw
updateGraph
]
]
end
be plot xa ya xmin xmax ymin ymax tickstepx tickstepy
local [x y y2 i]
GraphSetCurrent g
clearScreen
WindowMode
setPenSize [.5 .5]
PenDown
maxx=330
maxy=250
setX -maxx
setX maxx
setX 0
setY maxy
setY -maxy
setX -maxx
setY maxy
setX maxx
setY -maxy
setX -maxx
tick=10
txtx=25
setH 90
setLabelSize [25 25]
setLabelAlign 0 0
for [y [round ymin] [round ymax] tickstepy]
[ setY maxy*y/ymax
PenDown
setX -maxx+tick
setX -maxx
PenUp
setX maxx-tick
PenDown
setX maxx
PenUp
setX -maxx-txtx
label y
setX -maxx
]
setY -maxy
for [x [round xmin] [round xmax] tickstepx]
[ setX maxx*x/xmax
PenDown
setY -maxy+tick
setY -maxy
PenUp
setY maxy-tick
PenDown
setY maxy
PenUp
setY -maxy-txtx
label x
setY -maxy
]
PenUp
setPenSize [0 0]
y=ya.1
setXY -maxx y
imax=count xa
PenDown
setXY xa/xmax*maxx ya/ymax*maxy
end
be paint
GraphSetCurrent g
clearScreen
PenUp setXY -400 0 PenDown
end
end
be xy
if not Name? "frm
[ frm=Frame [][MyFrame]
wxResize_Border+wxCaption+wxSystem_Menu+wxClose_Box
+wxFull_Repaint_on_Resize
;wxDefault_Frame_Style+wxStay_on_Top)
[0 100][400 300]
g=XYGraph frm 400 300
g'init
g2=XYGraph frm 400 300
g2'init
bs=BoxSizer wxVertical
BoxSizerAdd bs g'g 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bs g2'g 100 wxExpand+wxALIGN_CENTER 0
FrameSetSizer frm bs
]
imax=1000
filterpara=imax/5
tau=0.1
t0=0.6
f=20
t=rSeqFA -1 1 imax
x=t*400
U=(sin t*360*f)*(exp (sqr (t-t0)/tau)* -1)*100
+(FloatArray (random iSeqIA 400 400 imax)-200)
Uq=lowPassFilter U*(sin t*360*f) filterpara
; g'paint setPixelXY x U 0
(g'plot x U -400 400 -300 300 100 100)
g2'paint setPixelXY x Uq HSB 1 1 1
FrameSetClientSize frm 400 600
; pr [;Activate MyFrame and press a key to exit]
FrameOnClose frm
[ pr [;OK]
erase [[][frm g g2]]
GC
]
GC
end