スポンサーリンク

Processing

Processingでの配列

投稿日:

配列を使用せずにグラフを書こうとすると棒を書くための値を格納する10個の変数が必要になる。
下記参照

int x0 = 50;
int x1 = 61;
int x2 = 83;
int x3 = 69;
int x4 = 71;
int x5 = 50;
int x6 = 29;
int x7 = 31;
int x8 = 17;
int x9 = 39;

fill(0);
rect(0,0,x0,8);
rect(0,10,x1,8);
rect(0,20,x2,8);
rect(0,30,x3,8);
rect(0,40,x4,8);
rect(0,50,x5,8);
rect(0,60,x6,8);
rect(0,70,x7,8);
rect(0,80,x8,8);
rect(0,90,x9,8);

これを配列で書くと下記

int[] x = {50,61,83,69,71,50,29,31,17,39};

fill(0);
for(int i=0; i<x.length; i++){
  rect(02,i*10,x[i],8);
}

配列の基本ですね。

Originally posted 2015-11-12 18:57:44.

スポンサーリンク

-Processing
-, ,

Copyright© office606 , 2023 All Rights Reserved Powered by STINGER.