【发布时间】:2021-05-21 06:50:34
【问题描述】:
我试图查看7.8: Objects and Images - p5.js Tutorial 以重新创建This example
我想从鼠标悬停时随机移动的图像开始。 有人可以指导我如何实现这一目标吗?
我尝试过的东西,但它根本不是同一种互动。示例交互简单,超级好,振荡幅度很平滑。
function preload() {
stone = loadImage("stone.png");
imageMode = center;
}
function setup() {
createCanvas(1200, 800);
}
function draw() {
background(42,44,45);
if((200<mouseX)&&(900>mouseX)&&(250<mouseY)&&(650>mouseY)){
this.x = random(width*0.5, height*0.5);
this.y = random(height*0.5, width*0.5);
this.speed = 0.0001 * (mouseX/ mouseY);
this.x += random(-this.speed, this.speed);
this.y += random(-this.speed, this.speed)
x += random(-3, 3);
y += random(-3, 3);
image(stone,this.x + (mouseX / (height)) ,this.y + (mouseY / width), 400, 300);
}
else{
image(stone,width*0.5,height*0.5, 400, 300); }
}
【问题讨论】:
-
您能否提供您正在使用的编辑器版本,以便更轻松地查看问题所在?
-
Editor Link tickle 示例也有这种拖尾效果,文本会随着鼠标移动。这种交互非常流畅。
标签: javascript processing p5.js