Created
December 6, 2016 08:45
-
-
Save alexanderbazo/fc2bb79d7150c079964492e885a261e3 to your computer and use it in GitHub Desktop.
Zeichnen auf dem HTML5-Canvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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