![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
今回の記事の目的はProcessingの「round()
関数」を理解し、自分なりに使ってみること。
この記事を書いた人
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-user-profile-illustrationi-light-blue.png)
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-user-profile-illustrationi-light-blue.png)
- クリエイティブコーディングで制作した作品と、上達のためにやったこと・学習過程を発信
- コンセプトは「クリエイティブコーディング1万時間の歩き方」
- 2024年にProcessingの構文のアウトプットを終え、2025年から作品制作開始(クリエイティブコーディングで作成した作品集)
目次
【Processing】round()関数について
round()関数について
- round()」は英語で「丸める」という意味
- 「
round()
」関数は、浮動小数点の数値を四捨五入して整数に変える関数- 3.6を使うと、4に変わります
- round()」関数は、計算結果をわかりやすくしたり、見た目をきれいに整えるために役立ちます
round()
関数は負の数も丸めます。例えば、-2.3は-2になる- round()」関数を使うとき、結果は整数型(int)になります。結果の変数も整数型でないといけないということです
【Processing】round()関数の書き方【構文】
round()関数の書き方【構文】
round(n)
- round(小数点)
- round(5.8)は6になる
【Processing】round()関数の使い方【画像とコード】
小数点を整数に変える例
![Processing round()で小数点を整数に変える例](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/10/round1.png)
![Processing round()で小数点を整数に変える例](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/10/round1.png)
float number = 3.6;
int rounded = round(number);
println(rounded); // 出力は4
round()関数を使って、図形を描く
![round()関数を使って、図形を描く](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/10/round2.png)
![round()関数を使って、図形を描く](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/10/round2.png)
![round()関数 小数点を整数に変えている](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/10/round3.png)
![round()関数 小数点を整数に変えている](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/10/round3.png)
float number = 100.7; // 任意の小数点数値をここに指定
int roundedValue = round(number);
void setup() {
size(200, 200);
background(255);
println("小数点の数値: " + number);
println("四捨五入後の整数: " + roundedValue);
ellipse(width/2, height/2, roundedValue, roundedValue);
}
【Processing】round()関数はどんな表現で使えそうか
図形を使った表現で、小数点ばっかりになってややかしいときに、round()
を使って整数に変えたいと思います。
【Processing】round()関数を使ってみた感想
小数点を整数に変えること。やったのは小学生以来ですね。
Processingは算数や数学の知識を思い出したり、知識がついていくので文系の僕には刺激がたくさんあります。
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
それでは今日もレッツワクワクコーディング。