Processing=007 01=simplepractice

Page 1

Processing

07 01

ArrayList Simple Practice 陣列小練習


ArrayList Practice 陣列小練習


If you got this… 如果你懂這個 的話…

{}

ArrayList


Think of How? 想想看怎麼做這個 ?


First, you might think in this way (Directly)

你可能會先這樣做

Probably I (Gary) am stupid

又或許只有我這麼笨


import peasy.test.*; import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*; PeasyCam cam; void setup(){ size(1000,1000,P3D); cam = new PeasyCam(this,0,0,0,1000); } void draw(){ background(0); for(int i =0; i<500; i+=50){ for(int j=0; j<500; j+=50){ fill(map(i,0,500,0,255),map(j,0,500,0,255),random(100,255)); pushMatrix(); translate(i,j,0); box(30,30,random(500)); popMatrix(); } } }


If you like it this way, it’s also fine

NOTHING 如果你喜歡這樣也可以 HAPPENS ???!!!


Problem 01: Keep updating, not static. 一直抖一直抖

Problem 02:

The height extend in both sides 高度往兩邊長


Now we need ArrayList 所以我們需要 ArrayList


import peasy.test.*; import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*; PeasyCam cam;

ArrayList randomH;

Create an ArrayList

void setup(){ size(1000,1000,P3D); cam = new PeasyCam(this,0,0,0,1000); randomH = new ArrayList(); Declare

the ArrayList

for(int i =0; i<500; i+=50){ for(int j=0; j<500; j=j+50){ PVector h = new PVector(i,j,random(0,300)); randomH.add(h); } } } void draw(){ background(0); for(int i =0; i<randomH.size();i++){ Call PVector nH = (PVector)randomH.get(i);

them out

創造一個 ArrayList

宣告一個 ArrayList

Put stuffs inside

在 ArrayList 裡面放入東西

把他們取出來呈現

pushMatrix(); fill(map(nH.x,0,500,0,255),map(nH.y,0,500,0,255),map(nH.z,0,500,0,255)); Draw boxes translate(nH.x,nH.y,nH.z/2); Fix the double sides problem box(30,30,nH.z); 解決往兩邊延長的問題 popMatrix(); } }

畫方盒


完成

DONE


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.