この記事を書いた人

- クリエイティブコーディングで制作した作品と、上達のためにやったこと・学習過程を発信
- コンセプトは「クリエイティブコーディング1万時間の歩き方」
- 2024年にProcessingの構文のアウトプットを終え、2025年から作品制作開始(クリエイティブコーディングで作成した作品集)
目次
作品の画像とコード

アニメーション。
参考サイト様は円を膨張させています。
僕は台形を膨張させてみました。
// 参考にさせていただいたページとURL
// 第6回: 画像の分析・再合成
// (画像データ、ピクセル、ラスタ画像)
// 2018年5月24日
// 東京藝術大学藝術情報センター(AMC)
// 担当: 田所 淳
// https://drive.google.com/file/d/1RbTZUtU_svu32m8kBjl6AKaK0jfs2-Gq/view
ArrayList<Trapezoid> trapezoids;
PImage img;
int maxSize = 100;
void setup() {
size(600, 600);
frameRate(60);
noStroke();
trapezoids = new ArrayList<Trapezoid>();
img = loadImage("dogs.jpg");
img.resize(width, height);
for (int i = 0; i < 10; i++) {
PVector loc = new PVector(random(width), random(height));
trapezoids.add(new Trapezoid(loc));
}
}
void draw() {
background(0);
for (int i = 0; i < trapezoids.size(); i++) {
trapezoids.get(i).drawTrapezoid();
}
for (int i = 0; i < trapezoids.size(); i++) {
if (trapezoids.get(i).isDead == false) {
boolean expand = trapezoids.get(i).checkPixel();
if (expand == false) {
PVector loc;
while (true) {
loc = new PVector(random(width), random(height));
color c = get(int(loc.x), int(loc.y));
if ((red(c) + blue(c)) == 0) break;
}
trapezoids.add(new Trapezoid(loc));
trapezoids.get(i).isDead = true;
}
}
}
}
void mouseClicked() {
trapezoids.clear();
for (int i = 0; i < 100; i++) {
PVector loc = new PVector(random(width), random(height));
trapezoids.add(new Trapezoid(loc));
}
}
class Trapezoid {
float size;
float expandSpeed;
color trapezoidColor;
PVector location;
boolean expand;
boolean isDead;
Trapezoid(PVector _location) {
location = _location;
size = 0;
expandSpeed = 4.0;
expand = true;
isDead = false;
trapezoidColor = img.get(int(location.x), int(location.y));
}
void drawTrapezoid() {
if (expand == true) {
size += expandSpeed;
}
fill(trapezoidColor);
beginShape();
vertex(location.x - size / 2, location.y - size / 4);
vertex(location.x + size / 2, location.y - size / 4);
vertex(location.x + size / 4, location.y + size / 4);
vertex(location.x - size / 4, location.y + size / 4);
endShape(CLOSE);
}
boolean checkPixel() {
float nextSize = size + expandSpeed;
for (float i = 0; i < TWO_PI; i += 0.01) {
int x = int(cos(i) * nextSize / 2.0 + location.x);
int y = int(sin(i) * nextSize / 2.0 + location.y);
color c = get(x, y);
if ((red(c) + blue(c) + green(c)) > 0 || size > maxSize) {
expand = false;
}
}
return expand;
}
}
// sかSを押すことで、xの位置とyの位置をファイル名につけて保存する
void keyPressed() {
if (key == 's' || key == 'S') {
String filename = "saved_image_x" + mouseX + "_y" + mouseY + ".png";
saveFrame(filename);
}
}
}

それでは今日もレッツワクワクコーディング。