level 2
cjfeng1021
楼主
小弟在编写一个简易的diagram,但我是初次接触processing,有望大神们帮助帮助,万分感谢。如果可能,有望大神能提供编写好的最终效果代码供小弟参考参考,感激不尽。

大致如上图,关键现在不懂如何添加动态。(上图是我自己画的,当大神在编写代码时不必按照上图这几个图形排列,可随性摆放)
动态要求如下:
1. 圆点可以用鼠标单击移动,但只限于水平横向移动,不可以被纵向移动。
2. 每当圆点被移动的同时,上面4个矩形同时产生横向移动且移动方向与圆点的移动方向相反。
3. 但是矩形移动具有一定的规律,规律是:距离圆点最近的那个矩形横向移动距离较大较明显(不要太大了,别超出画框),以此类推第二近的移动距离小一点,第三近的再小一点,最远那个矩形移动的幅度最小最不明显。
4. 矩形移动的同时产生残影,残影效果如下图。(最后附上残影效果代码作参考)



(代码如下:这个我真不懂。来源:https://processing.org/examples/storinginput.html)
int num = 60;
float mx[] = new float[num];
float my[] = new float[num];
void setup() {
size(640, 360);
noStroke();
fill(255, 153);
}
void draw() {
background(51);
// Cycle through the array, using a different entry on each frame.
// Using modulo (%) like this is faster than moving all the values over.
int which = frameCount % num;
mx[which] = mouseX;
my[which] = mouseY;
for (int i = 0; i < num; i++) {
// which+1 is the smallest (the oldest in the array)
int index = (which+1 + i) % num;
ellipse(mx[index], my[index], i, i);
}
}
2015年02月26日 02点02分
1

大致如上图,关键现在不懂如何添加动态。(上图是我自己画的,当大神在编写代码时不必按照上图这几个图形排列,可随性摆放)动态要求如下:
1. 圆点可以用鼠标单击移动,但只限于水平横向移动,不可以被纵向移动。
2. 每当圆点被移动的同时,上面4个矩形同时产生横向移动且移动方向与圆点的移动方向相反。
3. 但是矩形移动具有一定的规律,规律是:距离圆点最近的那个矩形横向移动距离较大较明显(不要太大了,别超出画框),以此类推第二近的移动距离小一点,第三近的再小一点,最远那个矩形移动的幅度最小最不明显。
4. 矩形移动的同时产生残影,残影效果如下图。(最后附上残影效果代码作参考)



(代码如下:这个我真不懂。来源:https://processing.org/examples/storinginput.html)int num = 60;
float mx[] = new float[num];
float my[] = new float[num];
void setup() {
size(640, 360);
noStroke();
fill(255, 153);
}
void draw() {
background(51);
// Cycle through the array, using a different entry on each frame.
// Using modulo (%) like this is faster than moving all the values over.
int which = frameCount % num;
mx[which] = mouseX;
my[which] = mouseY;
for (int i = 0; i < num; i++) {
// which+1 is the smallest (the oldest in the array)
int index = (which+1 + i) % num;
ellipse(mx[index], my[index], i, i);
}
}