Created
February 5, 2012 07:27
-
-
Save tatsuro-ueda/1743798 to your computer and use it in GitHub Desktop.
Processing Examples Basic Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 「coswav」という配列をつくりコサイン値を入れる | |
size(200, 200); | |
float[] coswave = new float[width]; | |
for (int i = 0; i < width; i++) { | |
// 0~widthを0~πに置き換える | |
float amount = map(i, 0, width, 0, PI); | |
// 絶対値(1~0~1)を配列に入れる | |
coswave[i] = abs(cos(amount)); | |
} | |
for (int i = 0; i < width; i++) { | |
stroke(coswave[i]*255); | |
line(i, 0, i, height/3); | |
} | |
for (int i = 0; i < width; i++) { | |
// 4分の1の階調。よく見るとわかる。 | |
stroke(coswave[i]*255 / 4); | |
line(i, height/3, i, height/3*2); | |
} | |
for (int i = 0; i < width; i++) { | |
stroke(255 - coswave[i]*255); | |
// 1番目の反転 | |
line(i, height/3*2, i, height); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 各ドットは画像の中心からの距離で色付けされている | |
float[][] distances; | |
float maxDistance; | |
size(200, 200); | |
background(0); | |
maxDistance = dist(width/2, height/2, width, height); | |
distances = new float[width][height]; | |
// 2次元配列に距離を入れる | |
for(int i=0; i<height; i++) { | |
for(int j=0; j<width; j++) { | |
float dist = dist(width/2, height/2, j, i); | |
distances[j][i] = dist/maxDistance * 255; | |
} | |
} | |
// 2ドット毎に処理をする(塗りつぶさない) | |
for(int i=0; i<height; i+=2) { | |
for(int j=0; j<width; j+=2) { | |
// 2次元配列の値を使って点を描く | |
stroke(distances[j][i]); | |
point(j, i); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// これは何をやっているんでしょう?誰か教えてください(涙 | |
int unit = 40; | |
int count; | |
Module[] mods; | |
void setup() { | |
size(320, 240); | |
background(176); | |
noStroke(); | |
int wideCount = width / unit; | |
int highCount = height / unit; | |
count = wideCount * highCount; | |
mods = new Module[count]; | |
int index = 0; | |
for (int y = 0; y < highCount; y++) { | |
for (int x = 0; x < wideCount; x++) { | |
mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8)); | |
} | |
} | |
} | |
void draw() { | |
for (int i = 0; i < count; i++) { | |
mods[i].update(); | |
mods[i].draw(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment