mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Switch examples to using event.count in onFrame().
This commit is contained in:
parent
36c9286ca9
commit
cd7544c7c7
7 changed files with 16 additions and 30 deletions
|
@ -33,12 +33,10 @@
|
|||
layer.appendBottom(placedSymbol);
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
function onFrame() {
|
||||
count++;
|
||||
function onFrame(event) {
|
||||
for (var i = 0, l = layer.children.length; i < l; i++) {
|
||||
var item = layer.children[i];
|
||||
var angle = (values.count - i) * Math.sin(count / 128) / 10;
|
||||
var angle = (values.count - i) * Math.sin(event.count / 128) / 10;
|
||||
item.rotate(angle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,10 +46,9 @@
|
|||
|
||||
var length1 = path1.length;
|
||||
var length2 = path2.length;
|
||||
var count = 0;
|
||||
function onFrame() {
|
||||
function onFrame(event) {
|
||||
var vector = new Point({
|
||||
angle: -count % 360,
|
||||
angle: -event.count % 360,
|
||||
length: 100
|
||||
});
|
||||
path1.rotate(-0.5);
|
||||
|
@ -60,12 +59,11 @@
|
|||
|
||||
for (var i = 0; i < lineCount; i++) {
|
||||
var path = lineGroup.children[i];
|
||||
var l1 = (length1 / lineCount * (i + count / 10)) % length1;
|
||||
var l2 = (length2 / lineCount * (i + count / 10)) % length2;
|
||||
var l1 = (length1 / lineCount * (i + event.count / 10)) % length1;
|
||||
var l2 = (length2 / lineCount * (i + event.count / 10)) % length2;
|
||||
path.segments[0].point = path1.getPointAt(l1),
|
||||
path.segments[1].point = path2.getPointAt(l2);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
|
|
@ -258,7 +258,6 @@
|
|||
heartPath.strokeColor = null;
|
||||
heartPath.scale(1.5);
|
||||
|
||||
var count = 0;
|
||||
var groupTogether = false;
|
||||
var pathLength = heartPath.length;
|
||||
var mouseDown = false;
|
||||
|
@ -270,11 +269,10 @@
|
|||
boids.push(new Boid(position, 10, 0.05));
|
||||
}
|
||||
|
||||
function onFrame() {
|
||||
count++;
|
||||
function onFrame(event) {
|
||||
for (var i = 0, l = boids.length; i < l; i++) {
|
||||
if (groupTogether) {
|
||||
var point = heartPath.getPointAt(((i + count / 30) % l) / l * pathLength);
|
||||
var point = heartPath.getPointAt(((i + event.count / 30) % l) / l * pathLength);
|
||||
boids[i].arrive(point);
|
||||
}
|
||||
boids[i].run(boids);
|
||||
|
|
|
@ -9,11 +9,9 @@
|
|||
<script type="text/paperscript" canvas="canvas">
|
||||
// http://en.wikipedia.org/wiki/Lenna
|
||||
var raster = new Raster('lenna');
|
||||
var count = 0;
|
||||
var lastScale = 1;
|
||||
var center = document.bounds.center;
|
||||
function onFrame(event) {
|
||||
count++;
|
||||
var scale = (Math.sin(event.time * 2) + 1) / 2;
|
||||
raster.scale(scale / lastScale);
|
||||
lastScale = scale;
|
||||
|
|
|
@ -30,13 +30,11 @@
|
|||
}
|
||||
|
||||
var children = document.activeLayer.children;
|
||||
var count = 0;
|
||||
function onFrame() {
|
||||
count++;
|
||||
function onFrame(event) {
|
||||
for (var i = 0, l = children.length; i < l; i++) {
|
||||
var item = children[i];
|
||||
var delta = (mousePoint - item.position) / (i + 5);
|
||||
item.rotate(Math.sin((count + i) / 10) * 7);
|
||||
item.rotate(Math.sin((event.count + i) / 10) * 7);
|
||||
if (delta.length > 0.1)
|
||||
item.translate(delta);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
<script type="text/paperscript" canvas="canvas">
|
||||
var width, height, center;
|
||||
var points = 10;
|
||||
var count = 0;
|
||||
var smooth = true;
|
||||
var path = new Path();
|
||||
var mousePos = document.bounds.center / 2;
|
||||
|
@ -31,11 +30,10 @@
|
|||
path.selected = true;
|
||||
}
|
||||
|
||||
function onFrame() {
|
||||
count++;
|
||||
function onFrame(event) {
|
||||
pathHeight += (center.y - mousePos.y - pathHeight) / 10;
|
||||
for (var i = 1; i < points; i++) {
|
||||
var sinSeed = count + (i + i % 10) * 100;
|
||||
var sinSeed = event.count + (i + i % 10) * 100;
|
||||
var sinHeight = Math.sin(sinSeed / 200) * pathHeight;
|
||||
var yPos = Math.sin(sinSeed / 100) * sinHeight + height;
|
||||
path.segments[i].point.y = yPos;
|
||||
|
|
|
@ -7,18 +7,16 @@
|
|||
<script type="text/javascript">var root = '../../'</script>
|
||||
<script type="text/javascript" src="../../src/load.js"></script>
|
||||
<script type="text/paperscript" canvas="canvas">
|
||||
var path,
|
||||
count = 0,
|
||||
rect = new Rectangle([150, 150], [300, 300]);
|
||||
var path;
|
||||
var rect = new Rectangle([150, 150], [300, 300]);
|
||||
document.currentStyle.fillColor = 'black';
|
||||
|
||||
function onFrame() {
|
||||
function onFrame(event) {
|
||||
if (path)
|
||||
path.remove();
|
||||
var size = Math.abs(Math.sin(count / 40)) * 150 + 10;
|
||||
var size = Math.abs(Math.sin(event.count / 40)) * 150 + 10;
|
||||
path = new Path.RoundRectangle(rect, size);
|
||||
path.position = document.bounds.center;
|
||||
count++;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
|
Loading…
Reference in a new issue