Skip to content

Instantly share code, notes, and snippets.

@Bijesse
Created November 29, 2018 21:40
Show Gist options
  • Save Bijesse/9dccdf4584b2ccf03ca0af510f39fe60 to your computer and use it in GitHub Desktop.
Save Bijesse/9dccdf4584b2ccf03ca0af510f39fe60 to your computer and use it in GitHub Desktop.
// source https://jsbin.com
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.2/p5.js"></script>
<script id="jsbin-javascript">
let radius = 100;
let score = 0;
let x, y;
let r, g, b;
function setup() {
createCanvas(windowWidth, windowHeight);
x = random(windowWidth);
y = random(windowHeight);
r = random(255);
g = random(255);
b = random(255);
}
function draw() {
background(220);
fill (r, g, b);
noStroke();
ellipse(x, y, radius*2, radius*2);
text("Score: " + score, 10, 20);
textSize(20);
}
function mousePressed() {
let d = dist(mouseX, mouseY, x, y);
if (d < radius){
newCircle();
score++;
if (score === 3){
radius /= 2;
setInterval(newCircle, 500);
}
}
}
function newCircle() {
x = random(255);
y = random(255);
r = random(255);
g = random(255);
b = random(255);
}
setInterval(newCircle, 1000);
</script>
<script id="jsbin-source-javascript" type="text/javascript">let radius = 100;
let score = 0;
let x, y;
let r, g, b;
function setup() {
createCanvas(windowWidth, windowHeight);
x = random(windowWidth);
y = random(windowHeight);
r = random(255);
g = random(255);
b = random(255);
}
function draw() {
background(220);
fill (r, g, b);
noStroke();
ellipse(x, y, radius*2, radius*2);
text("Score: " + score, 10, 20);
textSize(20);
}
function mousePressed() {
let d = dist(mouseX, mouseY, x, y);
if (d < radius){
newCircle();
score++;
if (score === 3){
radius /= 2;
setInterval(newCircle, 500);
}
}
}
function newCircle() {
x = random(255);
y = random(255);
r = random(255);
g = random(255);
b = random(255);
}
setInterval(newCircle, 1000);
</script></body>
</html>
let radius = 100;
let score = 0;
let x, y;
let r, g, b;
function setup() {
createCanvas(windowWidth, windowHeight);
x = random(windowWidth);
y = random(windowHeight);
r = random(255);
g = random(255);
b = random(255);
}
function draw() {
background(220);
fill (r, g, b);
noStroke();
ellipse(x, y, radius*2, radius*2);
text("Score: " + score, 10, 20);
textSize(20);
}
function mousePressed() {
let d = dist(mouseX, mouseY, x, y);
if (d < radius){
newCircle();
score++;
if (score === 3){
radius /= 2;
setInterval(newCircle, 500);
}
}
}
function newCircle() {
x = random(255);
y = random(255);
r = random(255);
g = random(255);
b = random(255);
}
setInterval(newCircle, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment