xxxxxxxxxx
101
let n = 200;
let nSpeed = 1;
function setup() {
createCanvas(700, 700);
//noStroke();
textAlign(CENTER, CENTER);
textSize(36);
}
function draw() {
//drawA();
//drawB();
drawC();
if (headsCount <= 100 && tailsCount <= 100)
{
if (random() < 0.07)
{
mousePressed();
}
}
else
{
if (headsCount > tailsCount)
{
print("Winner: Heads!")
}
else
{
print("Winner: Tails!")
}
}
}
//Movement Speed
function drawA() {
background(20);
if (n > width/2)
{
fill = "red";
}
ellipse()
if (n > width)
{
nSpeed = nSpeed * -1;
}
n = n + nSpeed;
}
//Flicker
function drawB() {
if (random() < 0.02)
{
background(random(255),random(255),random(255));
fill(random(255),random(255),random(255));
ellipse(random(width), random(height), random(50, width));
}
}
//Coin Toss
let word = "";
let headsCount = 0;
let tailsCount = 0;
function drawC()
{
background(220);
if (headsCount == 0 && tailsCount == 0)
{
text("Click to flip coin!", width/2, 50);
}
ellipse(width/2, height/2, 100);
text(word, width/2, height/2 + 100);
text("Heads: " + headsCount, 100, 650);
text("Tails: " + tailsCount, 600, 650);
}
function mousePressed() {
if (random() > 0.5)
{
word = "Heads!";
headsCount++;
}
else
{
word = "Tails!";
tailsCount++;
}
}