๐ŸŽ‡ Image Circle Modulation (ver.1)

BamgasiJMยท2026๋…„ 3์›” 14์ผ

p5.js Art

๋ชฉ๋ก ๋ณด๊ธฐ
61/65
post-thumbnail

let img;
let gridCols = 80;
let gridRows = 80;
let cellW, cellH;
let levels = [];
let imgReady = false;
let offsetX, offsetY; // ์ด๋ฏธ์ง€ ์œ„์น˜ ๋ณด์ •

function setup() {
  createCanvas(1000, 1000);
  background(0);
  noStroke();

  loadImage("../../assets/sticker_lara_006.png", (loadedImg) => {
    img = loadedImg;

    // ๋น„์œจ ์œ ์ง€: ๊ธด ์ชฝ์„ 1000์œผ๋กœ ๋งž์ถ”๊ธฐ
    if (img.width > img.height) {
      img.resize(1000, 0);
    } else {
      img.resize(0, 1000);
    }

    // ์ค‘์•™ ๋ฐฐ์น˜ ์˜คํ”„์…‹ ๊ณ„์‚ฐ
    offsetX = (width - img.width) / 2;
    offsetY = (height - img.height) / 2;

    cellW = img.width / gridCols;
    cellH = img.height / gridRows;

    img.loadPixels();

    // ๊ฐ ๊ทธ๋ฆฌ๋“œ์˜ ๋ฐ๊ธฐ ๋ ˆ๋ฒจ ๊ณ„์‚ฐ
    for (let y = 0; y < gridRows; y++) {
      levels[y] = [];
      for (let x = 0; x < gridCols; x++) {
        let px = int(x * cellW);
        let py = int(y * cellH);
        let idx = (py * img.width + px) * 4;
        let r = img.pixels[idx];
        let g = img.pixels[idx + 1];
        let b = img.pixels[idx + 2];
        let brightness = (r + g + b) / 3;
        let level = map(brightness, 0, 255, 2, 5);
        levels[y][x] = level;
      }
    }

    imgReady = true;
  });
}

function draw() {
  background(0);

  if (!imgReady) return;

  for (let y = 0; y < gridRows; y++) {
    for (let x = 0; x < gridCols; x++) {
      let cx = offsetX + x * cellW + cellW / 2;
      let cy = offsetY + y * cellH + cellH / 2;
      let baseSize = levels[y][x];

      // ๋งˆ์šฐ์Šค ํ˜ธ๋ฒ„ ๋ฐ˜๊ฒฝ 300px ๊ฐ€์šฐ์‹œ์•ˆ ํšจ๊ณผ
      let d = dist(mouseX, mouseY, cx, cy);
      let size = baseSize;
      if (d < 300) {
        let influence = exp(-pow(d, 1.8) / (2 * pow(30, 2))); // ฯƒ=30
        size = lerp(baseSize, 10, influence);
      }

      fill(80, 200, 180);
      ellipse(cx, cy, size, size);
    }
  }
}

profile
Coding Art with Blender / oF / Processing / p5.js / nannou

0๊ฐœ์˜ ๋Œ“๊ธ€