Spel36: Binär Grafisk Kalkylator

 

flipping_cards.png1244420137

Vi programmerar addition av heltal med hjälp av en binär grafisk kalkylator som bygger på den binära grafiska representationen/beräkningen i föregående post.

Lämplig från 2 års ålder i enbart grafisk form, med komplettering till binär representation vid 4 år, och till 10-tal från 7 år när siffrorna 1-9 pluggats in i grundskolan genom en massiv insats.

Titta på ett exempel här. Och ett annat exempel med subtraktion här (Positivt tal i grönt and negativt i rött). Jämför med Counting på App Store.

Jämför med Minecraft Graphing Calculator.

Template:

function setup()

supportedOrientations(LANDSCAPE_ANY)
print(“Binär grafisk kalkylator”)
bitimage = {}
bitimage[1] =readImage(“Dropbox:1bit”)
bitimage[2] =readImage(“Dropbox:2bit”)
bitimage[3] =readImage(“Dropbox:4bit”)
bitimage[4] =readImage(“Dropbox:8bit”)
bitimage[5] =readImage(“Dropbox:16bit”)
bitimage[6] =readImage(“Dropbox:32bit”)

I=6
N=20
J=10
number={}
for n=1,N do
number[n]={}
end
objectnumber={}
objectposition={}
for n=1,N do
for i=1,I do
number[n][i]=math.random(0,1)
end
number[n][I]=0
end
objectnumber={}

for n=1,N do
objectnumber[n]=0
objectposition[n]={}
for i=1,I do
objectnumber[n]=2^(i-1)*number[n][i]+objectnumber[n]
end
for j=1,objectnumber[n] do
objectposition[n][j]=vec2(math.random(700,900),math.random(200*n-150,200*n))
end

end

bitpos={}
sum = {}
for i=1,I do
bitpos[i] ={}
for j=1,J do
bitpos[i][j]=vec2(0,-100)
end
end

nextbutton=vec2(200,700)
plusbutton=vec2(600,700)
plus=0
n1=1
end

function touched(touch)
plusd=(plusbutton-finger):len()
nextd=(nextbutton-finger):len()

if (CurrentTouch.state==ENDED) then

if nextd<50 then
if n1<4 then
n1=n1+1
end
sound(“Game Sounds One:Dropzone”)
sound(“Game Sounds One:Female Cheer 2”)
end

if plusd<30 then
plus=1
sound(“Game Sounds One:Assembly 5”)
for n=1,n1 do
for j=1,J do
end
end
end

end
end

function draw()

background(40, 40, 50)

finger=vec2(CurrentTouch.x,CurrentTouch.y)

if plus==0 then

for n=1,n1 do

for i=1,I do
if number[n][i]>0 then
sprite(bitimage[i],700-100*i,200+100*n,50)
end
end

for j=1,objectnumber[n] do
sprite(“Planet Cute:Character Princess Girl”,objectposition[n][j].x,objectposition[n][j].y,30)
end

fontSize(50)
font(“AmericanTypewriter-Bold”)
fill(0, 32, 255, 255)
count=math.floor(objectnumber[n])
text(count,750,150+100*n)

end

for i=1,I do
sum[i]=0
for n=1,n1 do
sum[i]=sum[i]+number[n][i]
end
end

for n=1,n1 do
for i=1,I do
fontSize(50)
font(“AmericanTypewriter-Bold”)
fill(255, 3, 0, 255)
text(number[n][i],700-100*i,150+100*n)
end
end

end

if plus>0 then

for i=1,I do
if sum[i]>0 then
for j=1,sum[i] do
bitpos[i][j]=vec2(700-100*i,100+50*j)
end
end
end

for i=1,I-1 do
if sum[i]>1 then
d=(bitpos[i][sum[i]]-finger):len()
if d<50 then
sum[i+1]=sum[i+1]+1
sum[i]=sum[i]-2
end
end
end

for n=1,n1 do
for j=1,objectnumber[n] do
sprite(“Planet Cute:Character Pink Girl”,objectposition[n][j].x,objectposition[n][j].y,30)
end
end

for i=1,I do
for j=1,sum[i] do
sprite(bitimage[i],bitpos[i][j].x,bitpos[i][j].y,50)
end
end

for i=1,I do
fill(255, 3, 0, 255)
if sum[i]>0 then
text(“1”,700-100*i,50)
else
text(“0”,700-100*i,50)
end
end

count=0
for i=1,I do
count=2^(i-1)*sum[i]+count
end

count=math.floor(count)
fill(0, 32, 255, 255)
count=math.floor(count)
text(count,750,50)

end

sprite(“Cargo Bot:Next Button”,200,700,100)
fill(0, 255, 1, 255)
text(“Ett Tal Till”,200,650)
sprite(“Space Art:UFO”,630,700,100)
fill(0, 255, 0, 255)
text(“Addera Talen”,600,650)

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