processing--运动感海报
本例主要运用运动拖尾美化动感图形,通过创建类优化程序结构,提高创意编程效率。
主程序代码:
1 Motion[] motions; 2 Motion2[] motions2; 3 float col; 4 void setup() { 5 size(900, 600); 6 background(0); 7 colorMode(HSB, 360, 100, 100); 8 noStroke(); 9 col = random(260, 330); 10 motions =new Motion[6]; 11 for (int i=0; i<6; i++) { 12 motions[i] = new Motion(); 13 } 14 motions2 =new Motion2[8]; 15 for (int i=0; i<8; i++) { 16 motions2[i] = new Motion2(); 17 } 18 } 19 void draw() { 20 fill(0, 20); 21 rect(0, 0, width, height); 22 translate(260, -100); 23 rotate(PI/6); 24 for (int i=0; i<6; i++) { 25 motions[i].display(); 26 } 27 for (int i=0; i<8; i++) { 28 motions2[i].display(); 29 } 30 resetMatrix(); 31 fill(240); 32 textAlign(CENTER); 33 textSize(46); 34 text("sports", 450, 180); 35 textSize(160); 36 text("LET'S", 450, 340); 37 text("RUN", 450, 500); 38 }
Motion类代码
1 class Motion { 2 float x; 3 float y; 4 float radius; 5 float sp; 6 Motion() { 7 x=random(200, 600); 8 y=random(120, height); 9 radius=random(10, 40); 10 sp=random(2, 5); 11 } 12 void display() { 13 y -=sp; 14 if (y<-200) { 15 y=height+200; 16 } 17 fill(col, 100, 100); 18 rect(x, y, radius, radius*4); 19 } 20 }
Motion2类代码
1 class Motion2 { 2 float x; 3 float y; 4 float radius; 5 float sp; 6 Motion2() { 7 x=random(200, 500); 8 y=random(120, height); 9 radius=random(10, 40); 10 sp=random(1, 6); 11 } 12 void display() { 13 y -=sp; 14 if (y<-200) { 15 y=height+200; 16 } 17 fill(col-90, 100, 100); 18 rect(x, y, radius, radius*4); 19 } 20 }
显示效果:


浙公网安备 33010602011771号