下面为一跟随鼠标运动的红球:
1 float x = 300; //初始位置 2 float y = 200; 3 float easing = 0.05; //定义缓动因子 4 void setup() { 5 size(900, 600); 6 } 7 void draw() { 8 // background(0); 9 fill(0, 10); //设置矩形的填充颜色和不透明度 10 rect(0, 0, width, height); //绘制一个全屏的矩形 11 float diffX = mouseX-x; //光标位置与当前图形中心的距离 12 float diffY = mouseY-y; 13 x += diffX *easing; 14 y += diffY *easing; 15 fill(240, 50, 50); 16 noStroke(); 17 ellipse(x, y, 40, 40); 18 }