Skip to content

Commit

Permalink
bouncing effect on scene
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdesl committed May 24, 2018
1 parent 203c0ac commit 3f4c247
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/createArtwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ function createArtwork (canvas, params = {}) {
canvas,
sceneBounds: new THREE.Box2(),
unitScale: new THREE.Vector2(1, 1),
colorPalette: colorPalettes.light
colorPalette: colorPalettes.dark
// will contain some other properties for scenes to use, like width/height
};

const tickFPS = 30;

let raf;
Expand Down Expand Up @@ -110,6 +110,10 @@ function createArtwork (canvas, params = {}) {
clear,
reset,
stop,
bounce,
spawn () {

},
randomize () {
traverse('onTrigger', 'randomize');
},
Expand Down Expand Up @@ -172,6 +176,30 @@ function createArtwork (canvas, params = {}) {
draw();
}

function bounce () {
const scale = { value: scene.scale.x };
anime({
targets: scale,
easing: 'easeInQuad',
value: 0.9,
duration: 250,
update: () => {
scene.scale.setScalar(scale.value);
},
complete: () => {
anime({
duration: 250,
targets: scale,
easing: 'easeOutQuad',
value: 1,
update: () => {
scene.scale.setScalar(scale.value);
}
});
}
});
}

function clear () {
// stop all animations, clear shapes
stoppedAnimations.length = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ artwork.load().then(() => {
artwork.clear();
} else if (key === 't') {
artwork.swapPalettes();
} else if (key === 'b') {
artwork.bounce();
}
});
});

0 comments on commit 3f4c247

Please sign in to comment.