Spel54: Crash Model

Vi modellerar (se Scene1 nedan för modell) olika system som kan uppvisa snabb exponentiell tillväxt efter en lång fas med liten tillväxt, som beskriver tex när finans- eller bostadsbubblor plötsligt kollapsar efter lång stadig liten tillväxt.

Jämför med Crash Model på App Store med nedanstående kod:

–Main

parameter.number(“R”,0,10,1)
parameter.number(“d0”,0,10,1)
parameter.number(“v0”,0,10.0,3)
parameter.number(“dt0”,0,10,5)
–icon = readImage(“Dropbox:crashmodel”)
–saveImage(“Project:Icon”,icon)

restart=1
reset=1

— Use this function to perform your initial setup
function setup()
supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)
noFill()
noSmooth()
noStroke()
pushStyle()
Scene(“scene0”,Scene0)
Scene(“scene01”,Scene01)
Scene(“scene1”,Scene1)
Scene(“scene2”,Scene2)
Scene(“scene3”,Scene3)
Scene(“scene4”,Scene4)
Scene(“scene5”,Scene5)
Scene(“scene6”,Scene6)
Scene(“scene7”,Scene7)
Scene(“scene8”,Scene8)
Scene(“scene9”,Scene9)
Scene.Change(“scene0”)

end

function touched(touch)

Scene.Touched(touch)

end

function draw()

— background(40, 40, 50)
Scene.Draw()

end

Scene0= class()

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

local homeButton

function Scene0:init()
moveForwardButton=Button(“Cargo Bot:Play Button”,vec2(590,260))
speech.rate=0.4
speech.pitch=0.1
speech.say(“The Wall Street Crash of 1929, also known as Black Tuesday began on October 24, 1929 and was the most devastating stock market crash in the history of the United States. The crash signaled the beginning of the 10-year Great Depression that affected all Western industrialized countries.”)
speech.say(“Press play button to learn more,”)
end

function Scene0:draw()

background(2, 2, 2, 255)

font(“AmericanTypewriter-Bold”)
fontSize(120)
fill(255, 0, 17, 255)

sprite(“Dropbox:crash1”,515,420,1000)
sprite(“Dropbox:crash2”,270,320,250)
sprite(“Dropbox:crash3”,600,320,400)
— text(“CRASH MODEL”,500,670)
moveForwardButton:draw()

end

function Scene0:touched(touch)
moveForwardButton:touched(touch)
if(moveForwardButton.selected==true) then
Scene.Change(“scene01”)
end

end

Scene01= class()

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

local homeButton

function Scene01:init()

modelButton=Button(“Cargo Bot:Command Right”,vec2(200,500))
simulationButton=Button(“Cargo Bot:Command Right”,vec2(600,500))
exampleButton=Button(“Cargo Bot:Command Right”,vec2(200,300))
analysisButton=Button(“Cargo Bot:Command Right”,vec2(600,300))
simulation=0
model=0
end

function Scene01:draw()

background(2, 2, 2, 255)

if simulation==1 then
Scene.Change(“scene2”)
end

if simulation ==0 then

font(“AmericanTypewriter-Bold”)
fontSize(100)
fill(255, 0, 17, 255)

text(“CRASH MODEL”,500,670)
fontSize(50)
fill(0, 9, 255, 255)
text(“Model”,320,500)
text(“Simulation”,770,500)
fill(0, 255, 22, 255)
text(“Examples”,350,300)
text(“Analysis”,750,300)
end

modelButton:draw()
simulationButton:draw()
exampleButton:draw()
analysisButton:draw()

end

function Scene01:touched(touch)
modelButton:touched(touch)
if(modelButton.selected==true) then
Scene.Change(“scene1”)
end
simulationButton:touched(touch)

if(simulationButton.selected==true) then
Scene.Change(“scene3”)
end
exampleButton:touched(touch)
if(exampleButton.selected==true) then
Scene.Change(“scene4”)
end
analysisButton:touched(touch)
if(analysisButton.selected==true) then
Scene.Change(“scene9”)
end

end

Scene1 = class()

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function Scene1:init()

menuButton=Button(“Cargo Bot:Menu Game Button”,vec2(950,50))
end

function Scene1:draw()

background(2, 2, 2, 255)

fill(14, 0, 255, 255)
font(“AmericanTypewriter-Bold”)
fontSize(30)
text(“Stock Market Crash”,300,700)
text(“Marriage Crisis”,600,700)
text(“Spread of Infection”,300,650)
text(“Real Estate Bubble”,600,650)
text(“Lemming Year”,260,600)
text(“Political Revolution”,600,600)
text(“Collapse of Construction”,340,550)
text(“You Name It”,640,550)

fill(0, 255, 24, 255)

text(“all can be modeled by the system:”,400,490)
fill(255, 0, 7, 255)
text(“U = U – d*U*dt + R*v*U*dt for t > 0”,440,430)
text(“v = v – 2*d*v*dt + d*U*v*dt for t > 0 “,450,380)
text(“with U(0) = 1 and v(0) given”,390,330)
fill(0, 255, 9, 255)
text(“where”,190,270)
fill(255, 0, 0, 255)
text(“U main factor, v small disturbance factor”,450,210)
text(“d > 0 small damping coeff, R > 0 interaction coeff”,510,160)

menuButton:draw()

end

function Scene1:touched(touch)

menuButton:touched(touch)
if(menuButton.selected==true) then
Scene.Change(“scene01”)
end

end

Scene2 = class()
supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

local menuButton,resetButton

function Scene2:init()

menuButton=Button(“Cargo Bot:Menu Game Button”,vec2(730,50))
resetButton=Button(“Cargo Bot:Condition Green”,vec2(400,100))
controlButton=Button(“Dropbox:IconControl”,vec2(20,750))

U=1
v=v0*0.01
d=d0*0.01
dt=dt0*0.01
n=0
t=0

end

function Scene2:draw()

fontSize(20)
fill(255, 255, 255, 255)

text(“reset data”,390,50)

n=n+1

U=U-d*U*dt + R*v*U*dt
v=v-2*d*v*dt+d*v*U*dt
t=t+dt

fill(255, 0, 8, 255)
ellipse(0.1*n+50,U*10+200,5)
fill(36, 255, 0, 255)
ellipse(0.1*n+50,v*1000+200,5)

menuButton:draw()
resetButton:draw()
controlButton:draw()

end

function Scene2:touched(touch)

menuButton:touched(touch)
if(menuButton.selected==true) then
Scene.Change(“scene01”)
end
resetButton:touched(touch)
if(resetButton.selected==true) then
reset=1
Scene.Change(“scene3”)
end
end

Scene3 = class()
supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function Scene3:init()

moveForwardButton=Button(“Cargo Bot:Command Right”,vec2(600,100))
controlButton=Button(“Dropbox:IconControl”,vec2(20,750))

end

function Scene3:draw()

background(0, 0, 0, 255)

fill(255, 255, 255, 255)

text(v0*0.01,250,700)
text(dt0*0.01,250,650)
text(d0*0.01,250,600)
text(“v(0) = 0.01*v0 =”,100,700)
text(“dt = 0.01*dt0 =”,100,650)
text(“d = 0.01*d0 = “,100,600)
text(“U (red )and 100*v (green)”,150,425)

fill(255, 0, 47, 255)
ellipse(50,10+200,10)
fill(0, 255, 40, 255)
ellipse(50,10*v0+200,10)
stroke(255, 255, 255, 255)
strokeWidth(3)
line(50,200,50,400)
line(50,200,600,200)

moveForwardButton:draw()
controlButton:draw()

fill(255, 255, 255, 255)

fontSize(20)

text(“start/restart!”,600,50)
text(“test with v(0) = 0.02, 0.03,..”,550,700)
end

function Scene3:touched(touch)
moveForwardButton:touched(touch)
if(moveForwardButton.selected==true) then
Scene.Change(“scene2”)
end

end
Scene4 = class()

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function Scene4:init()

moveForwardButton=Button(“Cargo Bot:Command Right”,vec2(950,50))
moveBackwardButton=Button(“Cargo Bot:Command Left”,vec2(900,50))
end

function Scene4:draw()

background(25, 21, 240, 255)

moveForwardButton:draw()
moveBackwardButton:draw()

sprite(“Dropbox:bubble1”,350,350,300)
sprite(“Dropbox:usrealestate”,500,620,600)
font(“AmericanTypewriter-Bold”)
fontSize(25)
fill(0, 0, 0, 255)
text(“Why did US real estate collapse after precisely 50 years of steady rise?”,500,200)
text(“Because of steady slowly growing instability!”,350,100)

end

function Scene4:touched(touch)
moveForwardButton:touched(touch)
if(moveForwardButton.selected==true) then
Scene.Change(“scene5”)
end
moveBackwardButton:touched(touch)
if(moveBackwardButton.selected==true) then
Scene.Change(“scene01”)
end
end

Scene5 = class()

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function Scene5:init()

moveForwardButton=Button(“Cargo Bot:Command Right”,vec2(950,50))
moveBackwardButton=Button(“Cargo Bot:Command Left”,vec2(900,50))
end

function Scene5:draw()

background(25, 21, 240, 255)

moveForwardButton:draw()
moveBackwardButton:draw()
sprite(“Dropbox:wallstreet1929”,350,350,300)
sprite(“Dropbox:stockslongtime”,500,600,600)
font(“AmericanTypewriter-Bold”)
fontSize(30)
fill(0, 0, 0, 255)
text(“Why did the stock market collapse in 1929”,430,200)
text(“after precisely 10 years of steady rise?”,400,150)
text(“Because of steady slowly growing instability!”,450,100)

end

function Scene5:touched(touch)
moveForwardButton:touched(touch)
if(moveForwardButton.selected==true) then
Scene.Change(“scene6”)
end
moveBackwardButton:touched(touch)
if(moveBackwardButton.selected==true) then
Scene.Change(“scene4”)
end
end

Scene6 = class()

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function Scene6:init()

moveForwardButton=Button(“Cargo Bot:Command Right”,vec2(950,50))
moveBackwardButton=Button(“Cargo Bot:Command Left”,vec2(900,50))
end

function Scene6:draw()

background(25, 21, 240, 255)

moveForwardButton:draw()
moveBackwardButton:draw()

sprite(“Dropbox:divorce1”,350,500,800)
font(“AmericanTypewriter-Bold”)
fontSize(27)
fill(0, 0, 0, 255)
text(“Why did Tom and Mary divorce after precisely”,510,200)
text(“40 years of steady marriage?”,390,150)
text(“Because of steady slowly growing instability!”,500,100)

end

function Scene6:touched(touch)
moveForwardButton:touched(touch)
if(moveForwardButton.selected==true) then
Scene.Change(“scene7”)
end
moveBackwardButton:touched(touch)
if(moveBackwardButton.selected==true) then
Scene.Change(“scene5”)
end
end

Scene7 = class()

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function Scene7:init()

moveForwardButton=Button(“Cargo Bot:Command Right”,vec2(950,50))
moveBackwardButton=Button(“Cargo Bot:Command Left”,vec2(900,50))
end

function Scene7:draw()

background(25, 21, 240, 255)

moveForwardButton:draw()
moveBackwardButton:draw()

sprite(“Dropbox:smoke1”,250,500,500)
font(“AmericanTypewriter-Bold”)
fontSize(20)
fill(0, 0, 0, 255)
text(“Why does the rising smoke go turbulent”,730,700)
text(“after precisely 20 centimeters of laminar flow?”,760,650)
text(“Because of steady slowly growing instability!”,770,550)

end

function Scene7:touched(touch)
moveForwardButton:touched(touch)
if(moveForwardButton.selected==true) then
Scene.Change(“scene8”)
end
moveBackwardButton:touched(touch)
if(moveBackwardButton.selected==true) then
Scene.Change(“scene6”)
end
end

Scene8 = class()

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function Scene8:init()

moveForwardButton=Button(“Cargo Bot:Command Right”,vec2(950,50))
moveBackwardButton=Button(“Cargo Bot:Command Left”,vec2(900,50))
end

function Scene8:draw()

background(255, 0, 3, 255)

moveForwardButton:draw()
moveBackwardButton:draw()
sprite(“Dropbox:soviet89”,500,500,700)
font(“AmericanTypewriter-Bold”)
fontSize(25)
fill(0, 0, 0, 255)
text(“Why did the Soviet Union collapse after precisely 70 years of steady rule?”,500,200)
text(“Because of steady slowly growing instability!”,400,100)

end

function Scene8:touched(touch)
moveForwardButton:touched(touch)
if(moveForwardButton.selected==true) then
Scene.Change(“scene01”)
end
moveBackwardButton:touched(touch)
if(moveBackwardButton.selected==true) then
Scene.Change(“scene7”)
end
end

Scene9 = class()

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function Scene9:init()

menuButton=Button(“Cargo Bot:Menu Game Button”,vec2(950,50))
end

function Scene9:draw()

background(0, 0, 0, 255)
font(“AmericanTypewriter-Bold”)
fontSize(30)
fill(255, 255, 255, 255)

text(“Model:”,200,720)
fontSize(20)
text(“U = U – d*U*dt + R*v*U*dt “,290,650)
text(“v = v – 2*d*v*dt + d*U*v*dt “,300,600)
text(“d > 0 small damping coeff, R > 0 interaction coeff”,380,450)
fontSize(30)
text(“Properties:”,220,520)
fontSize(20)
fill(0, 255, 9, 255)
text(“-d*U*dt means slow decay of main factor U”,350,400)
text(“-2*d*v*dt means slow decay of disturbance v”,350,350)
fill(255, 253, 0, 255)
text(“R*v*U*dt means slow growth of main factor U below threshold”,450,300)
text(“d*U*v*dt means slow growth of disturbance v below threshold”,450,250)
fill(255, 0, 46, 255)
text(“combination of R*v*U*dt and d*U*v*dt means explosive growth above threshold”,550,200)

menuButton:draw()

end

function Scene9:touched(touch)

menuButton:touched(touch)
if(menuButton.selected==true) then
Scene.Change(“scene01”)
end

end

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s