Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div id="canvas-container">
    <canvas id="game" width="300" height="500"></canvas>
  </div>
</body>
</html>
 
var canvas = document.getElementById('game');
var ctx = canvas.getContext('2d');
var x = canvas.width;
var y = canvas.height;
var scoreVal = 0;
var itemXRand = Math.floor(Math.random() * x) + 1;
ctx.stroke();
function cloud() {
    ctx.beginPath();
    ctx.moveTo(170, 30);
    ctx.bezierCurveTo(130, 100, 130, 150, 230, 150);
    ctx.bezierCurveTo(250, 180, 320, 180, 340, 150);
    ctx.bezierCurveTo(420, 150, 420, 120, 390, 100);
    ctx.bezierCurveTo(430, 40, 370, 30, 340, 50);
    ctx.bezierCurveTo(320, 5, 250, 20, 250, 50);
    ctx.bezierCurveTo(200, 5, 150, 20, 170, 80);
    ctx.closePath();
    ctx.lineWidth = 5;
    ctx.fillStyle = '#8ED6FF';
    ctx.fill();
    ctx.strokeStyle = '#0000ff';
    ctx.stroke();
}
function workArea() {
    ctx.beginPath();
    ctx.rect(0, 0, x, y);
    ctx.fillStyle = '#2ab9ff';
    ctx.fill();
    ctx.stroke = 1;
}
function topRect() {
    ctx.beginPath();
    ctx.rect(0, 0, x, 30);
    ctx.fillStyle = '#D3D3D3';
    ctx.fill();
    ctx.stroke = 1;
}
function scoreKeep() {
    ctx.font = '15px Arial';
    ctx.fillStyle = '#000000';
    ctx.fillText('Score ' + scoreVal, 5, 25);
}
function bttmRect() {
    ctx.beginPath();
    ctx.rect(0, y - 30, x, 30);
    ctx.fillStyle = '#5bc928';
    ctx.fill();
    ctx.stroke = 1;
}
function monstRect() {
    ctx.beginPath();
    ctx.rect(0, y - 80, x, 30);
    ctx.fillStyle = 'red';
    ctx.fill();
    ctx.stroke = 1;
}
function itemCirc() {
    var centerX = itemXRand;
    var radius = 15;
    var positionY = 45;
    ctx.beginPath();
    ctx.arc(centerX, positionY, radius, 0, 2 * Math.PI, false);
    ctx.fillStyle = randomColor();
    ctx.fill();
    ctx.lineWidth = 1;
    ctx.strokeStyle = '#003300';
    ctx.stroke();
}
function startUp() {
    workArea();
    topRect();
    bttmRect();
    scoreKeep();
    itemCirc();
    monstRect();
    cloud();
}
function randomColor() {
    return ('#' + Math.floor(Math.random() * 16777215).toString(16));
}
startUp();
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers