mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
91 lines
34 KiB
HTML
91 lines
34 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<title>Example</title>
|
||
|
<link rel="stylesheet" href="../css/style.css">
|
||
|
<script type="text/javascript">var root = '../../'</script>
|
||
|
<script type="text/javascript" src="../../src/load.js"></script>
|
||
|
<script type="text/paperscript" canvas="canvas">
|
||
|
// Example inspired by: 'Phyllotactic Spirals' by Ken Frederick
|
||
|
// http://scriptographer.org/scripts/general-scripts/phyllotactic-spirals/
|
||
|
|
||
|
// Further reading:
|
||
|
// http://en.wikipedia.org/wiki/Phyllotaxis
|
||
|
|
||
|
var values = {
|
||
|
// The amount of paths to produce:
|
||
|
amount: 400
|
||
|
}
|
||
|
|
||
|
var raster = new Raster('lenna');
|
||
|
// Make the raster very transparent, to almost hide it:
|
||
|
raster.opacity = 0.1;
|
||
|
|
||
|
// Position the raster in the center of the view
|
||
|
raster.position = view.center;
|
||
|
|
||
|
// Scale the raster by 150%
|
||
|
raster.scale(1.5)
|
||
|
|
||
|
// Create the group of circle shaped paths, and move the group
|
||
|
// to the center of the view and scale it up a bit:
|
||
|
var group = createPhyllotaxis(values.amount);
|
||
|
group.position = view.center;
|
||
|
group.scale(1.5);
|
||
|
|
||
|
var bgCircle = new Path.Circle(group.position, group.bounds.width / 2);
|
||
|
bgCircle.fillColor = 'black';
|
||
|
bgCircle.scale(1.1);
|
||
|
bgCircle.position = view.center;
|
||
|
bgCircle.moveBelow(group);
|
||
|
|
||
|
|
||
|
// Colorize the paths within the group:
|
||
|
colorizePaths();
|
||
|
|
||
|
function createPhyllotaxis(amount) {
|
||
|
var group = new Group();
|
||
|
// The Golden Angle (http://en.wikipedia.org/wiki/Golden_angle)
|
||
|
var rotation = 137.51;
|
||
|
var spacing = 5;
|
||
|
for (var i = 1; i <= amount; i++) {
|
||
|
var point = new Point({
|
||
|
length: spacing * Math.sqrt(i),
|
||
|
angle: i * rotation
|
||
|
});
|
||
|
var radius = 4 - (i / amount * 3);
|
||
|
group.appendTop(new Path.Circle(point, radius));
|
||
|
}
|
||
|
return group;
|
||
|
}
|
||
|
|
||
|
function colorizePaths() {
|
||
|
for (var i = 0, l = group.children.length; i < l; i++) {
|
||
|
var path = group.children[i];
|
||
|
// Set the path's fill color to the average color of the
|
||
|
// raster pixels that fall within it:
|
||
|
path.fillColor = raster.getAverageColor(path);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function onMouseMove(event) {
|
||
|
// Move the group to the current position of the mouse:
|
||
|
group.position = event.point;
|
||
|
bgCircle.position = event.point;
|
||
|
// Colorize the paths:
|
||
|
colorizePaths();
|
||
|
}
|
||
|
|
||
|
// Whenever the view is resized, recenter the raster and recolorize
|
||
|
// the paths:
|
||
|
function onResize() {
|
||
|
raster.position = view.center;
|
||
|
colorizePaths();
|
||
|
}
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
<img width="512" height="512" id="lenna" style="display: none;" src="data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAAXAAD/4QMraHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjAtYzA2MCA2MS4xMzQ3NzcsIDIwMTAvMDIvMTItMTc6MzI6MDAgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnh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