xxxxxxxxxx
90
let ball; //動かす物体
//マウスが入ったら、出たら、押したら、離したら
let twEnter, twExit, twPress, twRelease;
let cnv; //キャンバス
function setup() {
cnv = createCanvas(windowWidth, windowHeight);
cnv.mouseOver(mouseEnterd);
cnv.mouseOut(mouseExited);
//初期値を設定
ball = {
diameter: height / 8,
col: color(255, 63, 31),
};
//マウスが画面に入ったとき
twEnter = gsap.to(ball, {
diameter: height / 6,
col: color(255, 255, 63),
duration: 1,
ease: "sine.inOut",
repeat: 100, //くりかえし
yoyo: true, //行って戻って
paused: true,
});
//マウスが画面から出たとき
twExit = gsap.to(ball, {
diameter: height / 8,
col: color(255, 63, 31),
duration: 0.5,
ease: "sine.inOut",
paused: true,
});
//マウスボタンを押したとき
twPress = gsap.to(ball, {
diameter: height / 2,
col: color(31, 127, 255),
duration: 0.25,
ease: "sine.Out",
paused: true,
});
//マウスボタンを離したとき
twRelease = gsap.to(ball, {
diameter: height / 1.5,
col: color(31, 127, 255, 0),
duration: 1.0,
ease: "sine.Out",
paused: true,
});
}
function draw() {
background(0);
noStroke();
fill(ball.col); //設定した色で
//動き
circle(width / 2, height / 2, ball.diameter);
}
//全てのTweenをリセット
function resetTw() {
twEnter.pause();
twExit.pause();
twPress.pause();
twRelease.pause();
}
//マウスが画面に入ったら
function mouseEnterd() {
resetTw();
twEnter.restart();
}
//マウスが画面に入ったら
function mouseExited() {
resetTw();
twExit.restart();
}
//マウスを押したら
function mousePressed() {
resetTw();
twPress.restart();
}
//マウスを離したら
function mouseReleased() {
resetTw();
twRelease.restart();
}