๐ŸŽ‡ Blooming Flower

BamgasiJMยท2025๋…„ 11์›” 30์ผ

p5.js Art

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

https://openprocessing.org/sketch/2797563

๐Ÿ“ p5.js

let shapes = [];
const shapesNum = 5000;
let maxRadius;

function setup() {
  // createCanvas(windowWidth, windowHeight);
  createCanvas(800, 800);

  maxRadius = min(width, height) * 0.3;

  for (let i = 0; i < shapesNum; i++) {
    shapes.push(new Shape(i));
  }

  background("#232323");
}

function draw() {
  // ์ž”์ƒ์„ ์œ„ํ•ด ๋งค ํ”„๋ ˆ์ž„๋งˆ๋‹ค ๋ฐฐ๊ฒฝ ๊ทธ๋ฆผ
  background("#2323231A");  // ๋’ค์—์„œ ๋‘ ์ž๋ฆฌ๋Š” ์•ŒํŒŒ๊ฐ’

  noStroke();
  fill(0);

  for (let i = 0; i < shapes.length; i++) {
    shapes[i].move();
    shapes[i].display();
  }
}

class Shape {
  constructor(i) {
    // ๊ฐ ๋„ํ˜•์˜ ๊ณ ์œ ํ•œ ์‹œ๊ฐ„/์œ„์ƒ ๊ฐ’์œผ๋กœ ์‚ฌ์šฉ๋จ
    this.i = i * 0.01;

    // ๋ฐ˜์ง€๋ฆ„ ๋ฐฐ์œจ
    this.radiusMultiplier = 0;

    // ๊ฐ๋„
    this.angle = 0;

    // currentRadius
    this.currentRadius = i % maxRadius;
  }

  move() {
    // ํ˜„์žฌ ๋ฐ˜์ง€๋ฆ„์„ ์ ์  ํ‚ค์›€
    this.currentRadius += 1;
    // ์ตœ๋Œ€ ๋ฐ˜์ง€๋ฆ„์— ๋„๋‹ฌํ•˜๋ฉด ๋‹ค์‹œ 0์œผ๋กœ ๋ฆฌ์…‹
    if (this.currentRadius > maxRadius) {
      this.currentRadius = 0;
    }
  }

  display() {
    // ๊ณ ์œ ํ•œ i ๊ฐ’์„ ์ด์šฉํ•ด ๋ณต์žกํ•œ ๋ฐ˜์ง€๋ฆ„ ๋ฐฐ์œจ ๊ณ„์‚ฐ
    this.radiusMultiplier = (cos(this.i * 3) - cos(this.i * 6) + 9) * 0.45;

    // ๊ณ ์œ ํ•œ i ๊ฐ’์„ ์ด์šฉํ•ด ๊ฐ๋„ ๊ณ„์‚ฐ
    this.angle = this.i / 2 + (sin(this.i * 3) - sin(this.i * 6)) / 3;

    // ๊ฐ๋„์™€ ์‹œ๊ฐ„(frameCount)์— ๋”ฐ๋ผ ์ƒ‰์ƒ์ด ๋ณ€ํ•˜๊ฒŒ ํ•จ
    fill(200 * sin(this.angle * 10 + frameCount * 0.1), 120, 100);

    // ๊ทน์ขŒํ‘œ๊ณ„๋ฅผ ์ด์šฉํ•ด ์›์˜ ์œ„์น˜ ๊ณ„์‚ฐ ๋ฐ ๊ทธ๋ฆฌ๊ธฐ
    circle(
      this.currentRadius * this.radiusMultiplier * cos(this.angle) + width / 2,
      this.currentRadius * this.radiusMultiplier * sin(this.angle) + height / 2,
      // ์›์˜ ํฌ๊ธฐ๋„ ํ˜„์žฌ ๋ฐ˜์ง€๋ฆ„๊ณผ ๊ณ ์œ  ๊ฐ’์— ๋”ฐ๋ผ ๋ณ€ํ•˜๊ฒŒ ํ•จ
      this.currentRadius * 0.2 * sin(this.i * 11)
    );
  }
}

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

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