META-INF.resources.scripts.canvas-battement.js Maven / Gradle / Ivy
The newest version!
export default function(params) {
var canvas = params.canvas;
var ctx = canvas.getContext("2d");
var px = 0, opx = 0, speed = 2;
var arr = [1,2,3,2];
var go = [];
var blimp = 0;
var larg, haut;
var go_height, go_width;
resize();
var state_machine = null;
loop();
function y(x) {
if (go.length == 0) {
return 0;
} else {
var ret = 0;
for (var i = 0; i < go.length; i++) {
if (go[i].px<=x && x canvas.width) {
zero();
}
requestAnimationFrame(loop);
}
function zero(event) {
px = opx = 0;
go = [];
blimp = 0;
};
function bump(event) {
go.push({px:px,amplitude:1});
};
function bump_now(amplitude) {
go.push({px:px,amplitude:amplitude});
};
function controller(action) {
if (action==='start') {
state_machine = 'running';
} else if (action==='stop') {
state_machine = null;
zero();
} else if (action==='pause') {
if (state_machine == 'paused') {
state_machine = 'running';
} else if (state_machine == 'running') {
state_machine = 'paused';
} else {
// noop
}
}
};
return {
bump: bump,
bump_now: bump_now,
controller: controller,
};
}