畫100個矩形, 其大小、顏色、和位置都是random
使用for迴圈來run 100次
填滿顏色用 fill (R, G, B, Alpha ) --> p.154 random( high )、random( low, high )、random( 255 )
矩形 rect (x, y, width, height ) --> random(x, y, random( w ), random( h ) )
http://140.136.150.78/IM2010/HW02/a/applet/
2-2. 將第一個作業改成每秒產生1000個矩形 p. 203
每秒產生,需用到 setup()、draw()、frameRate()
在空白區塊可作宣告變數
setup() 只執行一次
draw() 重複執行,其重複頻率由frameRate()控制,frameRate(n)表每秒跑n次
2-3. 改寫 p.92的圖形
會用到nest loop,改變 x, y來產生多個圖形變化
line( x1, y1, x2, y2 ),欲改變 line的顏色,需要使用stroke(R,G,B)
smooth()
strokeWeight() 線條粗細
2-4. 畫一張size(800, 600),共4*3=12個 大小200*200 圓
使用nest for loop來畫出12個圓
這次一口氣做了四個小作業
一開始就要畫random隨機產生不同顏色和大小,沒想到processing的作法這麼直觀
直接在畫矩形和顏色的function直接使用random就好
後面使用的setup()和draw()的概念也很清晰,並可控制頻率
這次學到了很多東西
p.200
Each time the draw() function finishes, it draws a new frame to the display window and then starts running the block again from the first line.
By default, frames are drawn to the screen at 60 frames per second (fps),each second.
float y = 0.0;
void draw()
{ frameRate(30);
line(0, y, 100, y);y = y + 0.5;
}
The background of the display window does not refresh automatically, so lines will simply accumulate.
drawing function, Utilize noLoop() to make a program run its draw() only one time.
void setup()
{
size(100, 100);noStroke();
smooth();
noLoop();
}
void draw()
{
eye(65, 44);eye(20, 50);
}
void eye(int x, int y)
{
fill(255);ellipse(x, y, 60, 60);
fill(0);
ellipse(x+10, y, 30, 30);
fill(255);
ellipse(x+16, y-5, 6, 6);
}
沒有留言:
張貼留言