Skip to Content
自造手冊:新工業革命實務指南
book

自造手冊:新工業革命實務指南

by Paolo Aliverti, Andrea Maietta
March 2017
Intermediate to advanced
232 pages
4h 44m
Chinese
GoTop Information, Inc.
Content preview from 自造手冊:新工業革命實務指南
第 19 章 Processing
206
水滴不斷滴在頭頂…
如果想要很多水滴怎麼辦?例如,每次
點擊滑鼠都要產生一滴新的水滴。您需
要在主草稿碼追蹤所有的水滴,但又不
知道總共有多少滴水,所以無法使用陣
列。在此需要另一個稱為 ArrayList 的資
料結構:它與陣列很相似,但是裡頭的
元素內容可以變動。
要建立水滴清單時,請將 DropTest 草稿
碼最上端的 Drop drop; 這一行改為以下:
ArrayList<Drop> drops =
newAList<Drop>();
因此當您在定義 drops 變數時,不只說明
了它的型態為 AList,您還指定了這個清
單中存放了 Drop 型態的物件。ArrayList
也是種類別,當然會有您可以呼叫的方
法。
您 會 感 興 趣 的 第 一 個 方 法 就 是 add 方
法, 可 讓 您 將 水 滴 加 入 清 單 中:drops.
add(drop)。
搭配 size 方法,您可以指定總共有多少
滴水,並透過常用的 for 迴圈來繪製所有
的雨滴。請
根據以下來修改 DropTest 的
draw 方法:
void draw(){
background(bg_color);
for (int i = 0; i < drops.size(); i++)
{
Drop drop = drops.get(i);
drop.update();
drop.draw();
}
}
您可使用 get 方法來取得第 n 個位置的物
件,將其在清單中位置當作參數;與陣
列一樣,清單的第 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

優雅的SciPy|Python科學研究的美學

優雅的SciPy|Python科學研究的美學

Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
Presto实战

Presto实战

Matt Fuller, Manfred Moser, Martin Traverso

Publisher Resources

ISBN: 9789864763238