Created
October 31, 2017 15:35
-
-
Save chrisfrancis27/763e076f016d68602d510420fb2a0e6d to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://cdn.rawgit.com/konvajs/konva/1.7.4/konva.min.js"></script> | |
<meta charset="utf-8"> | |
<title>Konva Clipping Function Demo</title> | |
<style> | |
body { | |
margin: 0; | |
padding: 0; | |
overflow: hidden; | |
background-color: #F0F0F0; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="container"></div> | |
<script> | |
var width = window.innerWidth; | |
var height = window.innerHeight; | |
var stage = new Konva.Stage({ | |
container: 'container', | |
width: width, | |
height: height | |
}); | |
var layer = new Konva.Layer(); | |
var group = new Konva.Group({ | |
clipFunc: function(ctx) { | |
ctx.arc(250, 120, 50, 0, Math.PI * 2, false); | |
ctx.arc(150, 120, 60, 0, Math.PI * 2, false); | |
}, | |
draggable: true | |
}); | |
var blueBlob = new Konva.Line({ | |
points: [73, 140, 340, 23, 500, 109, 300, 170], | |
stroke: 'blue', | |
strokeWidth: 10, | |
fill: '#aaf', | |
tension: 0.8, | |
closed : true | |
}); | |
var redBlob = new Konva.Line({ | |
points: [73, 140, 340, 23, 500, 109], | |
stroke: 'red', | |
strokeWidth: 10, | |
fill: '#faa', | |
tension: 1.2, | |
scale: {x : 0.5, y : 0.5}, | |
x: 100, | |
y: 50, | |
closed : true | |
}); | |
group.add(blueBlob); | |
group.add(redBlob); | |
layer.add(group); | |
// add the layer to the stage | |
stage.add(layer); | |
setTimeout(function() { | |
group.clipFunc(function(ctx) { | |
ctx.rect(100, 100, 300, 200); | |
}); | |
}, 1000); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment