mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 07:19:57 -05:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
366122cd33
3 changed files with 38 additions and 22 deletions
|
@ -7,24 +7,35 @@
|
||||||
<script type="text/javascript">var root = '../../'</script>
|
<script type="text/javascript">var root = '../../'</script>
|
||||||
<script type="text/javascript" src="../../src/load.js"></script>
|
<script type="text/javascript" src="../../src/load.js"></script>
|
||||||
<script type="text/paperscript" canvas="canvas">
|
<script type="text/paperscript" canvas="canvas">
|
||||||
document.currentStyle.fillColor = 'black';
|
var raster = new Raster('lenna'),
|
||||||
var raster = new Raster('lenna');
|
size = new Size(50, 50),
|
||||||
|
colSize = raster.size / size * 1.5,
|
||||||
|
fullSize = size * colSize;
|
||||||
|
|
||||||
raster.hidden = true;
|
raster.hidden = true;
|
||||||
var size = new Size(50, 50);
|
|
||||||
var colSize = raster.size / size * 1.5;
|
|
||||||
raster.size = size;
|
raster.size = size;
|
||||||
for (var x = 0; x < size.width; x++) {
|
for (var x = 0; x < size.width; x++) {
|
||||||
for (var y = 0; y < size.height; y++) {
|
for (var y = 0; y < size.height; y++) {
|
||||||
var gray = raster.getPixel(x, y).gray * 0.9;
|
var color = raster.getPixel(x, y),
|
||||||
|
gray = color.gray * 0.9;
|
||||||
if (gray > 0.1) {
|
if (gray > 0.1) {
|
||||||
var pos = new Point(x, y) * colSize + colSize / 2;
|
var pos = new Point(x, y) * colSize + colSize / 2,
|
||||||
var rectSize = gray * colSize.width;
|
rectSize = gray * colSize.width,
|
||||||
var path = new Path.Rectangle([0, 0], [rectSize, rectSize]);
|
path = new Path.Rectangle([0, 0], [rectSize, rectSize]);
|
||||||
|
path.fillColor = color;
|
||||||
path.position = pos;
|
path.position = pos;
|
||||||
path.rotate(gray * 180);
|
path.rotate(gray * 180);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
document.activeLayer.position = document.bounds.center;
|
||||||
|
|
||||||
|
// Reposition the paths whenever the window is resized:
|
||||||
|
DomEvent.add(window, {
|
||||||
|
resize: function(event) {
|
||||||
|
document.activeLayer.position = document.bounds.center;
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -458,14 +458,16 @@ var Item = this.Item = Base.extend({
|
||||||
y1 = x1,
|
y1 = x1,
|
||||||
y2 = x2;
|
y2 = x2;
|
||||||
for (var i = 0, l = children.length; i < l; i++) {
|
for (var i = 0, l = children.length; i < l; i++) {
|
||||||
var child = children[i],
|
var child = children[i];
|
||||||
rect = includeStroke
|
if (child.visible) {
|
||||||
? child.getStrokeBounds()
|
var rect = includeStroke
|
||||||
: child.getBounds();
|
? child.getStrokeBounds()
|
||||||
x1 = Math.min(rect.x, x1);
|
: child.getBounds();
|
||||||
y1 = Math.min(rect.y, y1);
|
x1 = Math.min(rect.x, x1);
|
||||||
x2 = Math.max(rect.x + rect.width, x2);
|
y1 = Math.min(rect.y, y1);
|
||||||
y2 = Math.max(rect.y + rect.height, y2);
|
x2 = Math.max(rect.x + rect.width, x2);
|
||||||
|
y2 = Math.max(rect.y + rect.height, y2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return includeStroke
|
return includeStroke
|
||||||
? Rectangle.create(x1, y1, x2 - x1, y2 - y1)
|
? Rectangle.create(x1, y1, x2 - x1, y2 - y1)
|
||||||
|
|
|
@ -154,15 +154,18 @@ var PaperScript = this.PaperScript = new function() {
|
||||||
DomEvent.requestAnimationFrame(frame, doc && doc.canvas);
|
DomEvent.requestAnimationFrame(frame, doc && doc.canvas);
|
||||||
onFrame();
|
onFrame();
|
||||||
// Automatically redraw document each frame.
|
// Automatically redraw document each frame.
|
||||||
doc && doc.redraw();
|
if (doc)
|
||||||
}
|
doc.redraw();
|
||||||
DomEvent.requestAnimationFrame(frame, doc && doc.canvas);
|
};
|
||||||
|
// Call the onFrame handler and redraw the document:
|
||||||
|
frame();
|
||||||
|
} else {
|
||||||
|
// Automatically redraw document at the end.
|
||||||
|
if (doc)
|
||||||
|
doc.redraw();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
// Automatically redraw document at the end.
|
|
||||||
if (doc)
|
|
||||||
doc.redraw();
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue