Skip to content

Instantly share code, notes, and snippets.

@alexanderbazo
Created December 6, 2016 08:45
Show Gist options
  • Save alexanderbazo/fc2bb79d7150c079964492e885a261e3 to your computer and use it in GitHub Desktop.
Save alexanderbazo/fc2bb79d7150c079964492e885a261e3 to your computer and use it in GitHub Desktop.
Zeichnen auf dem HTML5-Canvas
var canvas = document.querySelector("#canvas"),
context = canvas.getContext("2d");
// Zeichne eine Linie von x1,y1 nach x2,y2
function drawLine(x1, y1, x2, y2, color, weight) {
context.beginPath();
context.moveTo(x1, y1);
context.lineTo(x2, y2);
context.strokeStyle = color;
context.lineWidth = weight;
context.stroke();
context.closePath();
}
// Zeichne einen Kreis an der Position x,y
function drawCircle(x, y, radius, color) {
context.beginPath();
context.fillStyle = color;
context.arc(x, y, radius, 0, 2 * Math.PI, false);
context.fill();
context.closePath();
}
// Zeichne ein Rechteck an der Position x,y
function drawRect(x, y, width, color) {
context.beginPath();
context.fillStyle = color;
context.rect(x - width/2, y - width/2, width, width);
context.fill();
context.closePath();
}
// Lösche einen rechteckigen Bereich des Canvas
function erase(x, y, width) {
context.clearRect(x - width/2, y - width/2, width, width);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment