xxxxxxxxxx
55
var flip
var heads=0
var tails=0
var total=0
var Hperc
var Tperc
var timer=0
var runTime=1
function setup() {
createCanvas(400, 400);
}
function preload () {
coin = loadImage('coin.png')
}
function draw() {
timer =timer +1
background(255,230,0);
image (coin,270,270,100,100)
flip=round(random(0,1))
if (flip==1) {
heads=heads+1
total=total+1
}
if (flip==0) {
tails=tails+1
total=total+1
}
textSize(20)
text(heads,100,100)
text(tails,300,100)
text (total,200,100)
text('HEADS',85,70)
text('TOTAL',185,70)
text('TAILS',285,70)
if (timer >=runTime*3600) {
text('% ROLLS:',150,150)
Hperc = (heads/total) *100
Tperc = (tails/total) *100
textSize(20)
text ('Heads:',10,200)
text (Hperc,10,250)
text ('Tails:',10,300)
text(Tperc,10,350)
noLoop()
}
}