aUCBLogo Demos and Tests / xygraphtest2
be xygraphtest2
xy
end
be XYGraph frm width height ~
xmin xmax ymin ymax ticksx ticksy mode
local [g mx my mw mh x0 y0 w0 h0 zx zy zx0 zy0 p0 p pz
mouseleft mouseright inmotion c
xa ya xxa yya
xmin0 xmax0 ymin0 ymax0
maxx maxy]
g=(Graph frm
wxDefault_Frame_Style+wxFull_Repaint_on_Resize ;+wxStay_on_Top
[0 0] List width height [Graph])
;g=[]
setUpdateGraph false
hideTurtle
mx=0
my=0
x0=0
y0=0
mw=0
mh=0
w0=0
h0=0
zx=1
zy=1
zx0=1
zy0=1
c=0
p0=[0 0 0]
p=[0 0 0]
pz=[0 0 0]
mouseleft=false
mouseright=false
inmotion=false
yminh=ymax
ymax=ymin
ymin=yminh
xminh=xmax
xmax=xmin
xmin=xminh
xmin0=xmin
xmax0=xmax
ymin0=ymin
ymax0=ymax
maxx=330
maxy=250
be init
WindowOnLeftDown g
[
if not mouseleft
[ GraphSetCurrent g
p0=MousePos+p
x0=p0.1+mx
y0=p0.2+my
mouseleft=true
]
]
WindowOnLeftUp g
[
mouseleft=false
GraphSetCurrent g
p0=p0-MousePos+p
mx=p.1
my=p.2
]
WindowOnRightDown g
[
if not mouseright
[ GraphSetCurrent g
p0=MousePos+pz
w0=p0.1+mw
h0=p0.2+mh
mouseright=true
]
]
WindowOnRightUp g
[
mouseright=false
GraphSetCurrent g
p0=p0-MousePos+pz
mw=p.1
mh=p.2
zx0=zx0*(1+mw/800)
zy0=zy0*(1+mh/600)
]
;comment [
WindowOnMotion g
[
if mouseleft and2 not inmotion
[ GraphSetCurrent g
p=p0-MousePos
mx=p.1
my=p.2
xmin=(xmin0+xmax0)/2-(xmax0-xmin0)/2*zx-mx/maxx*(xmax0-xmin0)
xmax=(xmin0+xmax0)/2+(xmax0-xmin0)/2*zx-mx/maxx*(xmax0-xmin0)
ymin=(ymin0+ymax0)/2-(ymax0-ymin0)/2*zy-my/maxy*(ymax0-ymin0)
ymax=(ymin0+ymax0)/2+(ymax0-ymin0)/2*zy-my/maxy*(ymax0-ymin0)
clearScreen
drawplot
updateGraph
]
if mouseright and2 not inmotion
[ GraphSetCurrent g
pz=p0-MousePos
mw=pz.1
mh=pz.2
zx=zx0*(1+mw/800)
zy=zy0*(1+mh/600)
xmin=(xmin0+xmax0)/2-(xmax0-xmin0)/2*zx-mx/maxx*(xmax0-xmin0)
xmax=(xmin0+xmax0)/2+(xmax0-xmin0)/2*zx-mx/maxx*(xmax0-xmin0)
ymin=(ymin0+ymax0)/2-(ymax0-ymin0)/2*zy-my/maxy*(ymax0-ymin0)
ymax=(ymin0+ymax0)/2+(ymax0-ymin0)/2*zy-my/maxy*(ymax0-ymin0)
clearScreen
drawplot
updateGraph
]
]
;]
end
be plot xa_ ya_ c_
xa=xa_
ya=ya_
c=c_
drawplot
end
be drawplot
local [x y y2 i h w hq wq hx hy rx ry]
WindowMode
setPenSize [.5 .5]
setPC 0
PenUp
setXY -maxx -maxy
PenDown
setY maxy
setX maxx
setY -maxy
setX -maxx
tick=10
txtx=25
setH 90
setLabelSize [25 25]
setLabelAlign 0 0
setPrintPrecision 4
setLabelFont "Times
h=ymax-ymin
hq=(ymax0-ymin0)*2^(round -0.5+(ln abs h/(abs ymax0-ymin0))/ln 2)
w=xmax-xmin
wq=(xmax0-xmin0)*2^(int -0.5+(ln abs w/(abs xmax0-xmin0))/ln 2)
for [y -ticksy ticksy]
[
hy=-hq*(y/ticksy-0.5)
hy=hy+(remainder -(ymax+ymin)/2 hq/ticksy)
ry=hy+(ymax+ymin)/2
hy=-hy*maxy*2/h
if hy > maxy or2 hy < -maxy [continueLoop]
;(pr maxy h hy)
;if this == xy::g3 [pr hy]
setY hy
PenDown
setX -maxx+tick
setX -maxx
PenUp
setX maxx-tick
PenDown
setX maxx
PenUp
setX -maxx-txtx
Label ry
;pr ry
setX -maxx
]
setY -maxy
for [x -ticksx 2*ticksx]
[ hx=-wq*(x/ticksx-0.5)
hx=hx+(remainder -(xmax+xmin)/2 wq/ticksx)
rx=hx+(xmax+xmin)/2
hx=-hx*maxx*2/w
if hx > maxx or2 hx < -maxx [continueLoop]
setX hx
PenDown
setY -maxy+tick
setY -maxy
PenUp
setY maxy-tick
PenDown
setY maxy
PenUp
setY -maxy-txtx
label rx
setY -maxy
]
setPenSize [0 0]
x=(xmax+xmin)/2
y=(ymax+ymin)/2
fx=2/(xmax-xmin)*maxx
fy=2/(ymax-ymin)*maxy
xxa=saturateBelow -maxx saturateAbove maxx (-xa+x)*fx
yya=saturateBelow -maxy saturateAbove maxy (-ya+y)*fy
ifelse mode == "pixels
[ setPixelXY xxa yya c
][
setPC c
PenUp
; x=maxx
; repeat count xxa
; [ j=repcount
; if xxa.j < x [x=xxa.j y=yya.j]
; ]
; setXY x y
setXY xxa.1 yya.1
PenDown
setXY xxa yya
PenUp
]
updateGraph
;pause
end
be clean
GraphSetCurrent g
clearScreen
end
end
be xy
;g3=XYGraph frm 400 300 -400 400 0 10 8 4 "lines
;g3'init
;comment [
if not Name? "frm
[
frm=Frame [][MyFrame]
wxResize_Border+wxCaption+wxSystem_Menu+wxClose_Box
+wxFull_Repaint_on_Resize
;wxDefault_Frame_Style+wxStay_on_Top)
[100 100][400 300]
; g=XYGraph frm 400 300 -400 400 -300 300 8 6 "lines
; norefresh
; g'init
g2=XYGraph frm 400 300 -400 400 -12 12 8 4 "lines
norefresh
g2'init
g3=XYGraph frm 400 300 -400 400 0 12 8 4 "lines
norefresh
g3'init
g4=XYGraph frm 400 300 0 100 0 8000 5 5 "lines
norefresh
g4'init
txtRe1=StaticText frm [ContrastRe]
txtRe2=StaticText frm [dCRe]
txtRe3=StaticText frm [SNRe]
txtAbs1=StaticText frm [ContrastAbs]
txtAbs2=StaticText frm [dCAbs]
txtAbs3=StaticText frm [SNAbs]
bs=BoxSizer wxVertical
bsh=BoxSizer wxHORIZONTAL
BoxSizerAdd bs bsh 400 wxExpand+wxALIGN_CENTER 0
bsv=BoxSizer wxVertical
BoxSizerAdd bsh bsv 100 wxExpand+wxALIGN_CENTER 0
; BoxSizerAdd bs g'g 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsv g2'g 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsh g4'g 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsv g3'g 100 wxExpand+wxALIGN_CENTER 0
bst=BoxSizer wxHORIZONTAL
BoxSizerAdd bs bst 20 wxExpand+wxALIGN_CENTER 0
bsRe =BoxSizer wxVertical
bsAbs=BoxSizer wxVertical
BoxSizerAdd bst bsRe 20 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bst bsAbs 20 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsRe txtRe1 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsRe txtRe2 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsRe txtRe3 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsAbs txtAbs1 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsAbs txtAbs2 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsAbs txtAbs3 100 wxExpand+wxALIGN_CENTER 0
FrameSetSizer frm bs
FrameSetClientSize frm 800 800
running=true
stopping=false
FrameOnClose frm
[ running=false
]
FrameOnChar frm
[ running=false
]
]
;]
imax=10000
filterpara=imax/10
tau=0.1
t0=0
f=imax*0.182
amplitude=10
t=rSeqFA -1 1 imax
x=t*400
tcmax=100
contrastRe=FloatArray tcmax
dCRe=0
SNRe=0
contrastAbs=FloatArray tcmax
dCAbs=0
SNAbs=0
avg=10
tc=1
tca=rseqFA 0 tcmax tcmax
setPrintPrecision 3
while [running]
[
U=(sin t*360*f)*(exp (sqr (t-t0)/tau)*-1)*amplitude
+(FloatArray (random iSeqIA 400 400 imax)-200)
U.1=0
Uqre=lowPassFilter2 U*(sin t*360*f) filterpara
Uqim=lowPassFilter2 U*(cos t*360*f) filterpara
if not Name? "Uqmre [Uqmre=Uqre Uqmim=Uqim]
Uqmre=(Uqmre*avg+Uqre)/(avg+1)
Uqmim=(Uqmim*avg+Uqim)/(avg+1)
Ur=(FloatArray (random iSeqIA 400 400 imax)-200)
Ur.1=0
Urqre=lowPassFilter2 Ur*(sin t*360*f) filterpara
Urqim=lowPassFilter2 Ur*(cos t*360*f) filterpara
if not Name? "Urqmre [Urqmre=Urqre Urqmim=Urqim]
Urqmre=(Urqmre*avg+Urqre)/(avg+1)
Urqmim=(Urqmim*avg+Urqim)/(avg+1)
Uq =sqrt (sqr Uqre )+(sqr Uqim )
Uqm =sqrt (sqr Uqmre )+(sqr Uqmim )
Urq =sqrt (sqr Urqre )+(sqr Urqim)
Urqm=sqrt (sqr Urqmre)+(sqr Urqmim)
; g'clean
; (g'plot x U HSBA 0 1 0 0.02)
; (g'plot x Ur HSBA 0 1 0 0.02)
GraphSetCurrent g2'g
(g2'plot x Uqre HSBA 0 1 1 0.1)
(g2'plot x Uqmre HSB 60 1 1)
(g2'plot x Urqre HSBA 240 1 1 0.1)
(g2'plot x Urqmre HSB 200 1 1)
GraphSetCurrent g3'g
(g3'plot x Uq HSBA 120 1 1 0.1)
(g3'plot x Uqm HSB 60 1 1)
(g3'plot x Urq HSBA 170 1 1 0.1)
(g3'plot x Urqm HSB 200 1 1)
lastCRe=contrastRe.tc
lastCAbs=contrastAbs.tc
tc=tc+1
if tc > tcmax [tc=1]
tca.tc=tc
contrastRe.tc=0+(Uqmre-Urqmre)
StaticTextSetLabel txtRe1 se [ContrastRe] contrastRe.tc
dCRe=(dCRe*10+(abs contrastRe.tc-lastCRe))/11
StaticTextSetLabel txtRe2 se [dCRe] dCRe
SNRe=(SNRe*100+contrastRe.tc/dCRe)/101
StaticTextSetLabel txtRe3 se [SNRe] SNRe
contrastAbs.tc=0
+((sqrt (sqr Uqmre )+(sqr Uqmim ))-
(Sqrt (sqr Urqmre)+(sqr Urqmim)))
StaticTextSetLabel txtAbs1 se [ContrastAbs] contrastAbs.tc
dCAbs=(dCAbs*10+(abs contrastAbs.tc-lastCAbs))/11
StaticTextSetLabel txtAbs2 se [dCAbs] dCAbs
SNAbs=(SNAbs*100+contrastAbs.tc/dCAbs)/101
StaticTextSetLabel txtAbs3 se [SNAbs] SNAbs
GraphSetCurrent g4'g
clean
(g4'plot tca contrastRe/10 HSB 0 1 1)
(g4'plot tca contrastAbs/10 HSB 120 1 1)
dispatchMessages
GC
]
stopping=true
pr [;OK]
erase [[][frm g g2]]
GC
end