1. 程式人生 > >Getting Started with Processing 第五章的easing問題(2)

Getting Started with Processing 第五章的easing問題(2)

上一個 第五章 RoCE mouse process 一次 成了 參數 二維

程序代碼清單如下:

float x;
float y;
float px;
float py;
float easing = 0.05;

void setup(){
size(480,120);
stroke(0,102);
}

void draw(){
float targetX = mouseX;
x+=(targetX-x)*`easing`;
float targetY = mouseY;
y+=(targetY-y)*`easing`
line(x,y,px,py);
py=y;
px=x;
}

首先,在這裏,作者首先將上一個例子中的一維變成了二維

float targetX = mouseX;
x+=(targetX-x)*easing;
float targetY = mouseY;
y+=(targetY-y)*easing;

然後,作者通過利用一個參數 weight,從 dist() 函數返回一個值,然後將之作為 line 的weight.

同時,當程序進行的時候,line(x,y,px,py);是從目前這一點到上一點畫線。

關於px =x;py=y;

但是,程序進行到這裏, 這個時候 px 和 py 沒有被賦值,所以將目前還未進行下一次循環的 x 和 y 值賦值給 px 和 py.
程序進行到下一次循環的時候,x 和 y 的值通過鼠標的移動,於是 x 和 y 的值再次改變。進行下面的程序。





Getting Started with Processing 第五章的easing問題(2)