【作品103】不完全な魔王召喚

【作品103】不完全な悪魔召喚
  • URLをコピーしました!
この記事を書いた人
ワタタク
  • クリエイティブコーディングで制作した作品と、上達のためにやったこと・学習過程を発信
  • コンセプトは「クリエイティブコーディング1万時間の歩き方」
  • 2024年にProcessingの構文のアウトプットを終え、2025年から作品制作開始(クリエイティブコーディングで作成した作品集

目次

アニメーション

コード

17行目の5.jpgの部分をあなたの画像に変える必要があります。

// #103@20250605
// minacoding2025 day5
// 参考↓
// https://openprocessing.org/sketch/1345654
// Photo Fragments by dewagdeadi 

PImage img;
ArrayList<Pixel> drips = new ArrayList<>();
float interval;
int counter = 0;
float rippleX, rippleY;
boolean isRippling = false;
float shakeIntensity = 0;

void setup() {
  size(1000, 1000);
  img = loadImage("5.jpg");
  img.resize(1000, 1000);
  interval = img.height / 100.0;
  noStroke();
  for (float y = interval - 10 / 2; y <= img.height; y += interval) {
    for (float x = interval / 2; x <= img.width; x += interval) {
      color c = img.get((int)x, (int)y); 
      int id = (int)(red(c) + green(c) + blue(c)); 
      if (id > 0) {
        drips.add(new Pixel(x, y, c, id)); 
      }
    }
  }
}

void draw() {
  translate(random(-shakeIntensity * 2, shakeIntensity * 2), random(-shakeIntensity * 2, shakeIntensity * 2));
  if (isRippling) {
    counter += 2; 
    shakeIntensity = max(0, shakeIntensity - 0.02);
  }
  background(0); 
  for (Pixel d : drips) {
    float distFromRipple = dist(d.basex, d.basey, rippleX, rippleY);
    if (counter > distFromRipple / 2) {
      d.move(); 
      if (d.y > 0) {
        d.show(); 
      }
    }
  }
}

void mousePressed() {
  rippleX = mouseX;
  rippleY = mouseY;
  counter = 0; 
  shakeIntensity = 30;
  isRippling = true; 
}

class Pixel {
  float x, y, basex, basey, yvel; 
  color c; 
  int id; 

  Pixel(float x, float y, color c, int id) {
    this.x = x; 
    this.y = -300; 
    this.basex = x; 
    this.basey = y; 
    this.yvel = 0; 
    this.c = c; 
    this.id = id; 
  }

  void move() {
    y += yvel; 
    if (y < basey) { 
      yvel += 0.2;
    } else {
      y -= yvel; 
      yvel *= -0.3; 
      float d = dist(x, y, mouseX, mouseY);
      if (d < 100) {
        yvel -= 1000 / (d + 10);
      }
    }
  }

  void show() {
    pushMatrix();
    fill(c); 
    translate(x, y); 
    rotate(radians(y - basey)); 
    rect(0, 0, 1.1 * interval, 1.1 * interval); 
    popMatrix();
  }
}
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次