mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Flock example: resize the document whenever the browser window is resized.
This commit is contained in:
parent
c14ea8f7b5
commit
1781b53b55
1 changed files with 16 additions and 6 deletions
|
@ -14,9 +14,6 @@
|
||||||
strokeWidth: 2,
|
strokeWidth: 2,
|
||||||
strokeCap: 'round'
|
strokeCap: 'round'
|
||||||
};
|
};
|
||||||
var bounds = document.bounds,
|
|
||||||
width = bounds.width,
|
|
||||||
height = bounds.height;
|
|
||||||
|
|
||||||
var head = new Path.Oval([0, 0], [13, 8]);
|
var head = new Path.Oval([0, 0], [13, 8]);
|
||||||
head.fillColor = 'white';
|
head.fillColor = 'white';
|
||||||
|
@ -131,7 +128,9 @@
|
||||||
borders: function() {
|
borders: function() {
|
||||||
var loc = this.loc,
|
var loc = this.loc,
|
||||||
r = this.r,
|
r = this.r,
|
||||||
oldLoc = this.loc.clone();
|
oldLoc = this.loc.clone(),
|
||||||
|
width = document.size.width,
|
||||||
|
height = document.size.height;
|
||||||
if (loc.x < -r) loc.x = width + r;
|
if (loc.x < -r) loc.x = width + r;
|
||||||
if (loc.y < -r) loc.y = height + r;
|
if (loc.y < -r) loc.y = height + r;
|
||||||
if (loc.x > width + r) loc.x = -r;
|
if (loc.x > width + r) loc.x = -r;
|
||||||
|
@ -273,8 +272,19 @@
|
||||||
function onMouseDown(event) {
|
function onMouseDown(event) {
|
||||||
groupTogether = !groupTogether;
|
groupTogether = !groupTogether;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resize the document, whenever the window is resized,
|
||||||
|
window.onresize = function(event) {
|
||||||
|
document.size = [window.innerWidth, window.innerHeight];
|
||||||
|
heartPath.position = document.bounds.center;
|
||||||
|
document.redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call straight away to resize the document to the current
|
||||||
|
// window size:
|
||||||
|
window.onresize();
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body style='background-color: black'>
|
<body style='background-color: black; margin: 0; overflow: hidden'>
|
||||||
<canvas id='canvas' width=1024 height=768></canvas>
|
<canvas id='canvas'></canvas>
|
||||||
</body>
|
</body>
|
Loading…
Reference in a new issue