global w as integer
global h as integer
w=screen width()
h=screen height()
type sliderbar
xpos as integer
ypos as integer
width as integer
height as integer
maxpos as integer
mouseoffset as integer
state as integer
endtype
global bottomslider as sliderbar
global topslider as sliderbar
setupSliderBars()
global mousestate as integer
mousestate=0 // not pressed
//1= newly pressed
//2= held
//3= newly released
global mousexpos as integer
global mouseypos as integer
mousexpos=0
mouseypos=0
global numiterations as integer
global plotw as integer
global ploth as integer
global plotoffset as integer
global unittop as float
global unitbottom as float
global unitleft as float
global unitright as float
unittop=2.0
unitbottom=-1.0
unitleft=-2.0
unitright=4.0
ploth=h-300
numiterations=100
plotw=((unitright-unitleft)*ploth)/(unittop-unitbottom) //preserve aspect ratio
plotoffset=(w-plotw)/2
dim heightplot(plotw,numiterations) as integer
dim widthplot(w/4) as float
dim outputarray(0) as float
sync on
sync rate 0
fillHeightPlot()
do
cls
drawHeightPlot()
updateMouseCode()
updateSliderBars()
drawSliderBars()
updatewidthplot()
drawwidthplot()
sync
loop
function fillHeightPlot()
for n=0 to plotw
setIterationsArray(500,numiterations,.4,n*(unitright-unitleft)/plotw+unitleft)
for i=0 to numiterations
newh=ploth*(1.0-(outputarray(i)-unitbottom)/(unittop-unitbottom))
if newh<0 then newh=-1
if newh>ploth then newh=-1
heightplot(n,i)=newh
next i
next n
endfunction
function drawHeightPlot()
lock pixels
for n=0 to plotw
for i=0 to numiterations
if n+plotoffset=topslider.xpos+4 or n+plotoffset=topslider.xpos+5 or n+plotoffset=topslider.xpos+6
ink rgb(255,0,0),0
else
ink rgb(255,255,255),0
endif
dot n+plotoffset,heightplot(n,i)
next i
next n
unlock pixels
ink rgb(255,0,0),0
endfunction
function updateMouseCode()
mousexpos=mousex()
mouseypos=mousey()
local newmousestate as integer
if mouseclick()
if mousestate=0 or mousestate=3 //not pressed or newly released
newmousestate=1 //newly pressed
endif
if mousestate=1 or mousestate=2 //newly pressed or held
newmousestate=2 //held
endif
else
if mousestate=0 or mousestate=3 //not pressed or newly released
newmousestate=0 //not pressed
endif
if mousestate=1 or mousestate=2 //newly pressed or held
newmousestate=3 //newly released
endif
endif
mousestate=newmousestate
endfunction
function drawSliderBars()
box bottomslider.xpos,bottomslider.ypos,bottomslider.xpos+bottomslider.width,bottomslider.ypos+bottomslider.height
box topslider.xpos,topslider.ypos,topslider.xpos+topslider.width,topslider.ypos+topslider.height,rgb(255,0,0),rgb(255,0,0),rgb(255,0,0),rgb(255,0,0)
endfunction
function drawwidthplot()
lasth=h-30-widthplot(0)*150
for n=1 to w/4
newh=h-30-widthplot(n)*150
line (n-1)*4,lasth,n*4,newh
lasth=newh
next n
endfunction
function updatewidthplot()
setIterationsarray(bottomslider.xpos/2,w/4,.4,(topslider.xpos+5-plotoffset)*(unitright-unitleft)/plotw+unitleft)
for n=0 to w/4
widthplot(n)=outputarray(n)
next n
endfunction
function updateSliderBars()
//mousestate 1 is newly pressed
if mousestate=1 and mousexpos>bottomslider.xpos
if mousexpos<bottomslider.xpos+bottomslider.width and mouseypos>bottomslider.ypos and mouseypos<bottomslider.ypos+bottomslider.height
bottomslider.state=1 //selected
bottomslider.mouseoffset=mousexpos
endif
endif
if mousestate=0 or mousestate=3
bottomslider.state=0 //unselected
bottomslider.mouseoffset=0
endif
if mousestate=2 and bottomslider.state=1
bottomslider.xpos=bottomslider.xpos+mousexpos-bottomslider.mouseoffset
bottomslider.mouseoffset=mousexpos
endif
if bottomslider.xpos>bottomslider.maxpos then bottomslider.xpos=bottomslider.maxpos
if bottomslider.xpos<0 then bottomslider.xpos=0
//mousestate 1 is newly pressed
if mousestate=1 and mousexpos>topslider.xpos
if mousexpos<topslider.xpos+topslider.width and mouseypos>topslider.ypos and mouseypos<topslider.ypos+topslider.height
topslider.state=1 //selected
topslider.mouseoffset=mousexpos
endif
endif
if mousestate=0 or mousestate=3
topslider.state=0 //unselected
topslider.mouseoffset=0
endif
if mousestate=2 and topslider.state=1
topslider.xpos=topslider.xpos+mousexpos-topslider.mouseoffset
topslider.mouseoffset=mousexpos
endif
if topslider.xpos>topslider.maxpos then topslider.xpos=topslider.maxpos
if topslider.xpos<0 then topslider.xpos=0
endfunction
function setIterationsArray(iterationFrom as integer, retsize as integer, startx as float, r as float)
curx#=startx
for n=0 to iterationFrom
curx#=iterateNumber(curx#,r)
next n
empty array outputarray()
array insert at bottom outputarray()
outputarray(0)=curx#
for n=1 to retsize
array insert at bottom outputarray()
outputarray(n)=iterateNumber(outputarray(n-1),r)
next n
endfunction
function setupSliderBars()
bottomslider.xpos=0
bottomslider.ypos=h-30
bottomslider.height=30
bottomslider.width=50
bottomslider.maxpos=w-bottomslider.width
bottomslider.state=0 //unselected
bottomslider.mouseoffset=0
topslider.xpos=0
topslider.ypos=0
topslider.height=10
topslider.width=10
topslider.maxpos=w-topslider.width
topslider.state=0 //unselected
topslider.mouseoffset=0
endfunction
function iterateNumber(x as float, r as float)
x2#=r*x*(1-x)
//x2#=x+.001-r/6.4*sin(360*x) //circle map attempt
//x2#=2.7^(-4.9*x*x)+r //gauss iterated map
endfunction x2#
The basic idea is that you start out with a number x. Lets say its .4. Then you assign x as x=x*(1-x) a bunch of times. After a hundred iterations or so the system obviously converges. If you generalize this equation to get x=x*r*(1-x), then as you vary r, you can see that sometimes x converges to a specific value, sometimes it switches forever in between two values, and sometimes it's so
chaotic you don't know what's going on.
The bifurcation diagram of an iterative equation like that is the graph of all possible long-term values for varying r.
The magic happens in the "iterate number" function, so switch that one. Try commenting out the other functions that are there.