Created
August 29, 2014 19:43
-
-
Save baldur/9bb2264ac1a8d403749c to your computer and use it in GitHub Desktop.
with_canvas
This file contains hidden or 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
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us"> | |
<head> | |
<title>Canvas stuff</title> | |
<style> | |
html, body { width: 100%; height: 100%; margin: 0px; } | |
</style> | |
</head> | |
<body> | |
<canvas id="gallery"></canvas> | |
</body> | |
<script type="text/javascript"> | |
var canvas = document.getElementById('gallery'); | |
if (canvas.getContext) { | |
var context = canvas.getContext('2d'); | |
context.canvas.width = window.innerWidth; | |
context.canvas.height = 300; | |
var image = new Image(); | |
image.onload = function() { | |
context.save(); | |
context.beginPath(); | |
context.moveTo(0, 0); | |
context.moveTo(0, 80); | |
context.lineTo(window.innerWidth/2, 180); | |
context.lineTo(window.innerWidth, 80); | |
context.lineTo(window.innerWidth, 0); | |
context.lineTo(0, 0); | |
context.closePath(); | |
context.clip(); | |
context.drawImage(image, 0, 0, window.innerWidth, image.height * (window.innerWidth/image.width)); | |
context.restore(); | |
}; | |
image.src = 'https://staging.mapzen.com/images/nyc-sunset.png'; | |
context.beginPath(); | |
context.moveTo(0, 100); | |
context.lineWidth = 2; | |
context.lineTo(window.innerWidth/2, 200); | |
context.lineTo(window.innerWidth, 100); | |
context.stroke(); | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment