Some code cleanup in examples.

This commit is contained in:
Jürg Lehni 2014-03-01 22:52:20 +01:00
parent a8578326ea
commit 3219b36c3d
4 changed files with 8 additions and 14 deletions

View file

@ -14,7 +14,7 @@
}
lineGroup.strokeColor = 'red';
var path1 = project.importJSON('["Path",{"pathData":"M63.39307,265.71387c10.8667,6.96631 26.4707,12.26025 43.18896,12.26025c24.79932,0 39.28857,-13.09619 39.28857,-32.04346c0,-17.27588 -10.03125,-27.58545 -35.38721,-37.05908c-30.65088,-11.146 -49.59814,-27.30713 -49.59814,-53.49902c0,-29.25732 24.2417,-50.9917 60.74365,-50.9917c18.94727,0 33.1582,4.4585 41.23877,9.19531L156.18018,133.35986c-5.85156,-3.62256 -18.39014,-8.9165 -35.38721,-8.9165c-25.63525,0 -35.3877,15.3252 -35.3877,28.14258c0,17.5542 11.42432,26.19238 37.33789,36.22314c31.76514,12.26025 47.64795,27.58545 47.64795,55.1709c0,28.979 -21.17676,54.33496 -65.48096,54.33496c-18.11133,0 -37.89502,-5.57275 -47.92578,-12.26025z"}]');
var path1 = new Path('M63.39307,265.71387c10.8667,6.96631 26.4707,12.26025 43.18896,12.26025c24.79932,0 39.28857,-13.09619 39.28857,-32.04346c0,-17.27588 -10.03125,-27.58545 -35.38721,-37.05908c-30.65088,-11.146 -49.59814,-27.30713 -49.59814,-53.49902c0,-29.25732 24.2417,-50.9917 60.74365,-50.9917c18.94727,0 33.1582,4.4585 41.23877,9.19531L156.18018,133.35986c-5.85156,-3.62256 -18.39014,-8.9165 -35.38721,-8.9165c-25.63525,0 -35.3877,15.3252 -35.3877,28.14258c0,17.5542 11.42432,26.19238 37.33789,36.22314c31.76514,12.26025 47.64795,27.58545 47.64795,55.1709c0,28.979 -21.17676,54.33496 -65.48096,54.33496c-18.11133,0 -37.89502,-5.57275 -47.92578,-12.26025z');
path1.position = view.center;
var path2 = path1.clone();

View file

@ -11,8 +11,8 @@
var yesGroup = words.children.yes;
var noGroup = words.children.no;
// Importet SVG Groups have their transformContent flag turned off by
// default. This is required for SVG importing to work correctly. Turn
// Imported SVG Groups have their transformContent flag turned off by
// default. This is required for SVG importing to work correctly. Turn
// it on now, so we don't have to deal with nested coordinate spaces.
yesGroup.transformContent = true;
noGroup.transformContent = true;

View file

@ -240,7 +240,6 @@
});
var heartPath = new Path('M514.69629,624.70313c-7.10205,-27.02441 -17.2373,-52.39453 -30.40576,-76.10059c-13.17383,-23.70703 -38.65137,-60.52246 -76.44434,-110.45801c-27.71631,-36.64355 -44.78174,-59.89355 -51.19189,-69.74414c-10.5376,-16.02979 -18.15527,-30.74951 -22.84717,-44.14893c-4.69727,-13.39893 -7.04297,-26.97021 -7.04297,-40.71289c0,-25.42432 8.47119,-46.72559 25.42383,-63.90381c16.94775,-17.17871 37.90527,-25.76758 62.87354,-25.76758c25.19287,0 47.06885,8.93262 65.62158,26.79834c13.96826,13.28662 25.30615,33.10059 34.01318,59.4375c7.55859,-25.88037 18.20898,-45.57666 31.95215,-59.09424c19.00879,-18.32178 40.99707,-27.48535 65.96484,-27.48535c24.7373,0 45.69531,8.53564 62.87305,25.5957c17.17871,17.06592 25.76855,37.39551 25.76855,60.98389c0,20.61377 -5.04102,42.08691 -15.11719,64.41895c-10.08203,22.33203 -29.54687,51.59521 -58.40723,87.78271c-37.56738,47.41211 -64.93457,86.35352 -82.11328,116.8125c-13.51758,24.0498 -23.82422,49.24902 -30.9209,75.58594z');
var pathLength = heartPath.length;
var boids = [];
var groupTogether = false;
@ -255,7 +254,7 @@
function onFrame(event) {
for (var i = 0, l = boids.length; i < l; i++) {
if (groupTogether) {
var length = ((i + event.count / 30) % l) / l * pathLength;
var length = ((i + event.count / 30) % l) / l * heartPath.length;
var point = heartPath.getPointAt(length);
if (point)
boids[i].arrive(point);
@ -268,7 +267,6 @@
function onResize(event) {
heartPath.fitBounds(view.bounds);
heartPath.scale(0.8);
pathLength = heartPath.length;
}
function onMouseDown(event) {

View file

@ -48,7 +48,6 @@
}
var segment, path;
var movePath = false;
function onMouseDown(event) {
segment = path = null;
var hitResult = project.hitTest(event.point, hitOptions);
@ -69,10 +68,8 @@
segment = path.insert(location.index + 1, event.point);
path.smooth();
}
hitResult.item.bringToFront();
}
movePath = hitResult.type == 'fill';
if (movePath)
project.activeLayer.addChild(hitResult.item);
}
function onMouseMove(event) {
@ -84,12 +81,11 @@
function onMouseDrag(event) {
if (segment) {
segment.point = event.point;
segment.point += event.delta;
path.smooth();
}
if (movePath)
} else if (path) {
path.position += event.delta;
}
}
</script>
</head>