<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
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |