Spel55: Dark Energy

Vi programmerar en modell av ett universum som innehåller både positiv massa och negative massa under gravitation, där massor av lika tecken repellerar varandra och massor av olika tecken repellerar varandra enligt Newton’s gravitationslag. Modellen visar accelererande expansion av positiv massa från ett begynnelsetillstånd av negative massa omgiven av positiv massa motsvarande en perturbation av gravitationspotentialen. Titta på Dark Energy på App Store med nedanstående kod:

–Main
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(“scene00”,Scene00)
Scene.Change(“scene00”)
— icon = readImage(“Dropbox:IconDarkEnergy”)
— saveImage(“Project:Icon”,icon)
end

function touched(touch)

Scene.Touched(touch)

end

function draw()

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

end

Scene00 = class()

local homeButton
local moveForwardButton
local Button1,Button2,Button3

function Scene00:init()

music(“A Hero’s Quest:Hero’s Triumph”)

moveForwardButton=Button(“Cargo Bot:Next Button”,vec2(700,150))
homeButton=Button(“Cargo Bot:Menu Game Button”,vec2(700,50))
Button1=Button(“Cargo Bot:Condition Yellow”,vec2(100,500))
Button2=Button(“Cargo Bot:Condition Blue”,vec2(100,400))
Button3=Button(“Dropbox:hawking1”,vec2(100,300))

end

function Scene00:draw()

sprite(“Dropbox:Universe3”,350,500,2000)

if speak==1 then
speech.rate=0.3
speech.pitch=0.1
speech.say(“What is Dark Energy?”)
speech.say(“I don’t know!”)
speech.say(“More precisely, Nobody knows!!”)
speech.pitch=1
speech.rate=0.4
speech.say(“Do you want to explore a possible answer?”)
speech.say(“Then click watch, and then start exploring yourself!!”)
speak=0
end

fill(0, 32, 253, 255)
font(“AmericanTypewriter-Bold”)
fontSize(50)
text(“What is”,370,900)
fill(243, 242, 243, 255)
fontSize(80)
fill(0, 0, 0, 255)
text(“Dark Energy?”,370,750)
fill(0, 11, 255, 255)
fontSize(50)
text(“Watch”,270,500)
text(“Explore Yourself”,400,400)
text(“Listen to me!”,360,300)

Button1:draw()
Button2:draw()
Button3:draw()

end

function Scene00:touched(touch)

Button1:touched(touch)
if(Button1.selected==true) then
Scene.Change(“scene0”)
end
Button2:touched(touch)
if(Button2.selected==true) then
Scene.Change(“scene1”)
end
Button3:touched(touch)
if(Button3.selected==true) then
speak=1
end
end

Scene01 = class()

local homeButton

function Scene01:init()

moveForwardButton=Button(“Cargo Bot:Next Button”,vec2(700,50))
end

function Scene01:draw()
sprite(“Dropbox:Universe2”,350,500,1800)
fontSize(30)
font(“AmericanTypewriter-Bold”)
fill(255, 255, 255, 255)
text(“Start from Newton’s Law of Gravitation:”,350,900)
fontSize(60)
fill(244, 243, 244, 255)
text(“Δφ=ρ”,350,800)
fontSize(30)
fill(255, 255, 255, 255)
text(“Δ is the Laplacian differential operator”,350,700)
text(“φ(x,t) is gravitational potential”,350,650)
text(“ρ(x,t) is mass density”,350,600)
text(“as functions of space x and time t.”,300,550)
fill(255, 255, 255, 255)
fontSize(25)
text(“View φ as primordial perturbation of initial 0 state”,350,450)
text(“resulting in mass distribution ρ=Δφ of variable sign, with “,370,400)
fill(255, 255, 255, 255)
fontSize(40)
text(” ρ = ρ-plus + ρ-minus”,330,300)
fill(0, 255, 12, 255)
text(“ρ-plus>=0”,350,250)
fill(255, 9, 0, 255)
text(“ρ-minus<=0”,350,200)
fill(239, 237, 237, 255)
fontSize(25)
text(“with separation of positive and negative mass.”,310,100)

moveForwardButton:draw()

end

function Scene01:touched(touch)

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

Scene1 = class()

local moveForwardButton
local fastButton
local slowButton
local traceButton
local startButton
local initialButton

displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT_ANY)

local planets={}
local planet
local vels={}
local masses={}
local signs ={}
local vel
local force
local pos
local dt
local trace
local sign
local N
local M
local start
local initial

function Scene1:init()

homeButton=Button(“Cargo Bot:Menu Game Button”,vec2(700,100))
fastButton=Button(“Cargo Bot:Command Right”,vec2(500,100))
slowButton=Button(“Cargo Bot:Command Left”,vec2(450,100))
traceButton=Button(“Cargo Bot:Condition Any”,vec2(350,100))
massButton=Button(“Cargo Bot:Condition Blue”,vec2(250,100))
startButton=Button(“Cargo Bot:Play Button”,vec2(600,100))
initialButton=Button(“Cargo Bot:Condition Yellow”,vec2(150,100))

dt=0.002
trace=1
sign=1
N=5
M=20
start=0
initial=0

music(“Game Music One:Zero”)

end

function Scene1:draw()

if trace==1 then
background(0, 0, 0, 255)
end

homeButton:draw()
fastButton:draw()
slowButton:draw()
traceButton:draw()
massButton:draw()
startButton:draw()
initialButton:draw()

font(“AmericanTypewriter-Bold”)
fontSize(48)
fill(255, 16, 0, 255)
text(“Explore Your Own 2D Universe”,380, 900)
fontSize(30)
font(“AmericanTypewriter-Condensed”)
fill(3, 0, 255, 255)
text(“1. Choose Positive (1) and Negative Mass (-1) by Blue Button.”,390, 800)
fontSize(30)
text(“2. Distribute mass points by touch. “,240, 750)
text(“3. Choose preset distribution by Yellow Button.”,305, 700)
text(“4. Click start!”,300,650)
text(“Orbit”,350,150)
text(“Time step”,470,150)
text(sign,250,150)
text(“Preset”,150,150)
text(“Start”,600,150)
fontSize(40)
stroke(15, 28, 249, 108)
strokeWidth(3)

if initial==1 then

for i=1,N do
for j=1,M do
table.insert(planets,makePlanet(i*10*math.cos(2*math.pi*j/M)+350,i*10*math.sin(2*math.pi*j/M)+400))
table.insert(vels,makePlanetvel(0,0))
table.insert(masses,1)
table.insert(signs,-1)
end
end

for i=N,2*N do
for j=1,M do
table.insert(planets,makePlanet(i*10*math.cos(2*math.pi*j/M)+350,i*10*math.sin(2*math.pi*j/M)+400))
table.insert(vels,makePlanetvel(0,0))
table.insert(masses,1)
table.insert(signs,1)
end
end

initial=0

end

if start==1 then

for i,planet in pairs(planets) do
force=vec2(0,0)
for j,planet in pairs(planets) do
r= (planets[i]-planets[j]):len()
force=force-(1000000/(r+10)^3)*(planets[i]-planets[j])*signs[i]*signs[j]
end
vels[i]=vels[i]+force*dt/masses[i]
planets[i]=planets[i]+vels[i]*dt
end

end
fill(42, 0, 255, 255)
for i,planet in pairs(planets) do
if signs[i]==1 then
fill(18, 255, 0, 255)
ellipse(planets[i].x,planets[i].y,masses[i]*20)
end
if signs[i]==-1 then
fill(255, 0, 1, 255)
ellipse(planets[i].x,planets[i].y,masses[i]*20)
end
end
sprite(“Dropbox:IconNewtonMathGames”,740,990,50)
end

function Scene1:touched(touch)
homeButton:touched(touch)
if(homeButton.selected==true) then
speak=0
Scene.Change(“scene00”)
end

fastButton:touched(touch)
if(fastButton.selected==true) then
dt=dt+0.001
end

slowButton:touched(touch)
if(slowButton.selected==true) then
dt=dt-0.001
end

traceButton:touched(touch)
if(traceButton.selected==true) then
trace=-trace
end

massButton:touched(touch)
if(massButton.selected==true) then
sign=-sign
end

startButton:touched(touch)
if(startButton.selected==true) then
start=1
end

initialButton:touched(touch)
if(initialButton.selected==true) then
initial=1
end

if touch.state == BEGAN then
pos=vec2(CurrentTouch.x,CurrentTouch.y)
elseif touch.state == ENDED then
if pos.y>100 then
table.insert(planets,makePlanet(pos.x,pos.y))
table.insert(vels,makePlanetvel(CurrentTouch.x -pos.x,CurrentTouch.y -pos.y))
table.insert(masses,math.random(1,1))
table.insert(signs,sign)
end
end

end

function makePlanet(x,y)
local planet=vec2()
planet.x=x
planet.y=y
return planet
end

function makePlanetvel(vx,vy)
local vel=vec2()
vel.x=vx
vel.y=vy
return vel
end

 

Scene4 = class()

local moveForwardButton
local x
local v
local I
local N
local h
local t
local dt
function Scene4:init()

x={}
v={}

I=40
N=50
h=1
t=0
dt=0.05
for i=1,I do
x[i]=i*h
v[i]=0
end

moveForwardButton=Button(“Cargo Bot:Next Button”,vec2(700,50))

end

function Scene4:draw()

background(10, 9, 9, 255)

fill(0, 32, 253, 255)
font(“AmericanTypewriter-Bold”)
fontSize(50)
text(“Selfgravitating”,370,900)
fill(243, 242, 243, 255)
fontSize(40)
text(“negative (or positive) mass”,370,850)
fill(0, 11, 255, 255)
text(“Contraction”,370,800)
fontSize(30)
text(“reflection at center”,350,200)
text(“no black hole with mass extinction”,400,150)

for i=1,I do
for j=1,I do
if x[j]<x[i] then
v[i]= v[i]-dt/i^3
end
x[i]=x[i]+v[i]*dt
if x[i]<0.1 then
v[i]=-v[i]
end
end
end

for i=1,I do
— fill(255-20*x[i],0,20*x[i],255)
fill(255-20*x[i],0,0,255)
for n=1,N do
ellipse(x[i]*20*math.cos(2*math.pi*n/N)+350,x[i]*20*math.sin(2*math.pi*n/N)+500,10)
end
end

moveForwardButton:draw()

end

function Scene4:touched(touch)

moveForwardButton:touched(touch)
if(moveForwardButton.selected==true) then
Scene.Change(“scene5”)
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