Processing 程式碼
生成好多個黑點點 讓圖片四顆球的顏色看起來一樣PImage img = loadImage("ball.png"); size(640, 569); //剛好是圖檔的大小 background(img); fill(0); for (float y=21; y<569; y+=13.748) { for (float x=2; x<640; x+=30) { ellipse(x, y, 12, 12); } } for (float y=21; y<569; y+=13.748) { for (float x=2+15; x<640; x+=30) { ellipse(x, y, 12, 12); } }自己畫上面的圖size(600, 600); noStroke(); fill(236, 152, 52); //色彩1 rect(0, 0, 300, 300); fill(122, 202, 249); // 色彩2 rect(300, 0, 300, 300); fill(129, 241, 128); // 色彩3 rect(0, 300, 300, 300); fill(230, 95, 115); // 色彩4 rect(300, 300, 300, 300); fill(122, 202, 249); // 色彩2 for (float y = 0; y<300; y+=15) { for (float x = 0; x<300; x+=30) { ellipse(x, y, 11, 11); ellipse(x+15, y+7, 11, 11); } } fill(236, 152, 52); // 色彩1 for (float y = 0; y<300; y+=15) { for (float x = 0; x<300; x+=30) { ellipse(300+x, y, 11, 11); ellipse(300+x+15, y+7, 11, 11); } }把圖完整的畫出來size(600, 600); noStroke(); fill(236, 152, 52); //色彩1 rect(0, 0, 300, 300); fill(122, 202, 249); // 色彩2 rect(300, 0, 300, 300); fill(129, 241, 128); // 色彩3 rect(0, 300, 300, 300); fill(230, 95, 115); // 色彩4 rect(300, 300, 300, 300); fill(191, 156, 205); ellipse(150, 150, 150, 150); ellipse(450, 150, 150, 150); ellipse(150, 450, 150, 150); ellipse(450, 450, 150, 150); for (float y = 0; y<600; y += 15) { for (float x = 0; x<600; x += 30) { if (6+x<300 && 6+y<300) fill(122, 202, 249); //色彩2 if (6+x>300 && 6+y<300) fill(236, 152, 52); //色彩1 if (6+x<300 && 6+y>300) fill(230, 95, 115); //色彩4 if (6+x>300 && 6+y>300) fill(129, 241, 128); //色彩3 ellipse(6+x, y, 11, 11); ellipse(6+x+15, y+7, 11, 11); } }跟以前不一樣的迴圈ArrayList<Integer> a = new ArrayList<Integer>(); a.add(3); a.add(5); a.add(7); for (Integer i : a) { //進階的for迴圈 println(i); } for (int i=0; i<a.size(); i++) { //比較傳統的for迴圈 println(a.get(i)); //你要用 .get(i) 取出你要的那格 }高級的物件for迴圈 畫出一張卡class Card{ //物件裡, 有方法畫圖 int x, y; void draw(){ rect(x, y, 100, 150); } } Card card1 = new Card(); void setup(){ size(500, 400); card1.x = 100; card1.y = 100; } void draw(){ card1.draw(); //程式碼會變比較有條理 }class Card 然後在 Card 裡再畫 Cardclass Card { //發明一種類別 class 叫大寫的卡片 int x, y; Card(int _x, int _y) { // 建構函式 x = _x; y = _y; } void draw() { rect(x, y, 100, 150); } } // 下面: 照著卡片類別, 發明一個物件 card1 Card card1 = new Card(100, 100); // 座標在 100,100 void setup() { size(500, 400); } void draw() { card1.draw(); }
沒有留言:
張貼留言