Ciao 访客, welcome back to old school! :p
int N = 20;int W = 400, H = W;int E = 20;int L = 200;int Y = H/2;color Yellow = color(255, 255, 0);int dy = 2;void setup() { size(W,H); smooth(); fill (Yellow);} void DrawLines() { stroke(Yellow); line(E,L,E+200,L);}void draw() { DrawLines(); }
需要一个if 结构来判断线段是否到达场景的边缘,并在做出相应的执行内容的变更。
int N = 20;int W = 400, H = W;int E = 20;int L = 200;int Y = H/2;color Yellow = color(255,255,0);int dy = 2;void setup() { size(W,H); smooth();}void draw() { background (Yellow); N = N + dy; if ((N > Y) || (N < 0)) { dy = dy * -1; } stroke(0); fill(175); line(E,N,L,N);}