크리스마스이기 때문에 processing에서 밤의 숲을 써

19437 단어 processing
메리클 루시마마스

전 자료



참고로 했습니다!

processing으로 나무 그리기

우크리스마스...




int step = 12;
int count = 0;
int lightNum = 200;

float tr_scale;
float tr_angle;
float tr_length;
float tr_startd;
float tr_startx;
float tr_starty;
float offset = -90;
float triangle = 30;


Light[] lights = {};

PGraphics backPg;
PGraphics frontPg;


void setup(){
  size (1366, 768);
  colorMode(RGB, 256);
  background(255);

  frontPg = createGraphics(width, height);
  backPg  = createGraphics(width, height);

  createLayer(backPg, 40, false);
  createLayer(frontPg, 20, true);

  for (int i = 0; i < lightNum; i++) {
    lights = (Light[])append(lights, new Light());
  }
}

void draw() {
  image(backPg, 0, 0);

  for (int i = 0; i < lightNum; i++) {
    lights[i].draw();
  }

  image(frontPg, 0, 0);
}


void createLayer(PGraphics context, int num, boolean hasBg) {
  tr_scale  = 0.99;
  tr_angle  = 24.0;
  tr_length = 180.0;
  tr_startd = 0.0;
  tr_startx = width / 2;
  tr_starty = height;

  context.beginDraw();

  if (hasBg == true) {
    backDraw(context);
  }


  createTree (context, tr_startx, tr_starty, tr_length, tr_startd, step);

  for (int i = 0; i < num; i++) {
    if (hasBg == true) {
      backDraw(context);
    }

    if (count == step) {
      count = 0;
      createTree(context, random (0, width), tr_starty, random(tr_length), tr_startd, step);
    }
  }

  context.endDraw();
}

void createTree (PGraphics context, float x01, float y01, float len, float deg, int n){
  context.stroke(color(#00695C, float(5 / (n + 1))));

  context.strokeWeight(int ((n + 1) / 4));

  float x02 = x01 + len * cos(radians(deg + offset));
  float y02 = y01 + len * sin(radians(deg + offset));

  context.line(x01, y01, x02, y02);

  if (n > 0) {
    float deg01 = random(-tr_angle, triangle);
    float scl01 = random(random(10, 20), len * tr_scale);
    createTree(context, x02, y02, scl01, deg + deg01, n - 1);

    float deg02 = random(-tr_angle, triangle);
    float scl02 = random(random(10, 20), len * tr_scale);
    createTree(context, x02, y02, scl02, deg + deg02, n - 1);
  }

  count = n;
}

void backDraw(PGraphics context) {
  context.noStroke();
  context.fill(#2a2f47, 9.5);

  context.rectMode(CORNER);

  context.rect(0, 0, width, height);
}

class Light {
  float x, y, brightness;
  float cnt;
  float v;

  Light() {
    x = random(width);
    y = random(height);
    cnt = 0;
    v = 0.6;
  }

  void draw() {
    noStroke();

    fill(color(#FFFF00, round(cnt -0.5)));
    ellipse(x + random(-1, 1), y + random(-1, 1), 8 + round(cnt / 10), 8 + round(cnt / 10));

    fill(color(#FFFF00, round(cnt)));
    ellipse(x, y, 5, 5);

    cnt += (v + random(-0.1, 0.5));

    if (cnt > 20.0) {
      v = -0.4;
    }

    if (cnt < 1.0) {
      v = 0.4;
    }
  }
}


디스플레이에 따라 나오는 색이 다르기 때문에 저에게 고민합니다 ...
JavaScript 버전의 processing에 이식하면 무너지는 ...

움직이면 반딧불처럼 빛이 흔들리고 조금 깨끗합니다.
크리스마스 옆에서 난수와 마주하는 것이 즐거움 (ry

좋은 웹페이지 즐겨찾기