人間観察バラエティー Human observation GAME

これは、沢山の人間がランダムに動くプログラムです。マウスをクリックしなければ、ランダムに動く人間を観察できます。

マウスの方向に人間が集まってきますので、マウスをクリックして集合させてみてください。

プログラムの数値を変えれば、人数を調整できます。

洋服の色がランダムに変わるようにプログラムしてあります。

ぜひ遊んでみてください。

This is a program where many people move randomly. If you do not click the mouse, you can observe a person who moves randomly.

Since humans gather in the direction of the mouse, please try clicking the mouse and gathering people.

You can adjust the number of people by changing the numerical value of the program.

I programed the color of clothes to change randomly.

Please try playing.

Download zip file here ↓

人間観察バラエティーのzipダウンロードは、こちら

動画⇩ on YouTube

ソースコード👇↓Source code is here

PImage i[] = new PImage[8];
PImage fi[] = new PImage[8];
PImage shadow0;
PImage shadow1;

color rgb(float y, float cr, float cb) {
  float[] o = {0, 0, 0};
  o[0] = y+(cr*1.402);
  o[1] = y-(cr*0.714)-(cb*0.344);
  o[2] = y+(cb*1.772);
  /*
  R  = Y+1.402Cr
   G  = Y-0.714Cr-0.344Cb
   B  = Y+1.772Cb
   */
  return color(o[0], o[1], o[2]);
}

void setup() {
  i[0] = loadImage("fplayer/0.png");
  i[1] = loadImage("fplayer/1.png");
  i[2] = loadImage("fplayer/2.png");
  i[3] = loadImage("fplayer/3.png");
  i[4] = loadImage("fplayer/4.png");
  i[5] = loadImage("fplayer/5.png");
  i[6] = loadImage("fplayer/6.png");
  i[7] = loadImage("fplayer/7.png");
  fi[0] = loadImage("playerf/0.png");
  fi[1] = loadImage("playerf/1.png");
  fi[2] = loadImage("playerf/2.png");
  fi[3] = loadImage("playerf/3.png");
  fi[4] = loadImage("playerf/4.png");
  fi[5] = loadImage("playerf/5.png");
  fi[6] = loadImage("playerf/6.png");
  fi[7] = loadImage("playerf/7.png");
  shadow0 = loadImage("player/shadow_0.png");
  shadow1 = loadImage("player/shadow_1.png");
  //size(1024, 1024);
  fullScreen(P2D);
  frameRate(60);
  noSmooth();
  noStroke();
  background(255);

  for (int f = 0; f < stock; f++) {
    xx[f] = width/2+((f-(stock/2))*24);  
    yy[f] = height/2;
    ns[f] = random(-1000, 1000);
    st[f] = 2;
    col[f] = rgb(200, random(-210, 210), random(-210, 210));
  }
}

int rand(int min, int max) {
  return int(random(min-1, max)+0.5);
}

int stock = 20;
int shadowf = 1;
int[] h = new int[stock];
float[] xx = new float[stock];
float[] yy = new float[stock];
float[] x = new float[stock];
float[] y = new float[stock];
int[] st = new int[stock];
color[] col = new color[stock];
float[] s = new float[stock];
float[] ns = new float[stock];

int tickspeed = 4;
int tick;

int stoptickspeed = 8;
int stoptick;

int limits = 1600/2;

int fineness = 1;

void draw() {
  background(240); 
  fill(255);
  ellipse(width/2, height/2, limits*2, limits*2);

  for (int ii = 0; ii < height; ii++) {
    for (int f = 0; f < stock; f++) {
      if (int(yy[f]) == ii) {
        if (shadowf > 0)image(shadow1, int((xx[f]-24)/1)*1, int((yy[f]-6)/1)*1, 48, 12);
        if (shadowf < 0)image(shadow0, int((xx[f]-24)/1)*1, int((yy[f]-6)/1)*1, 48, 12);
        tint(255);
        if (h[f] <= 7)image(i[h[f]], xx[f]-12, yy[f]-(48*1));
        tint(col[f]);
        if (h[f] <= 7)image(fi[h[f]], xx[f]-12, yy[f]-(48*1));
        tint(255);
      }
    }
  }
  for (int f = 0; f < stock; f++) {
    xx[f] += x[f]/fineness/2;
    yy[f] += y[f]/fineness/2;
    if (x[f] > 0 && y[f] > 0) {
      h[f] = 1;
    }
    if (x[f] < 0 && y[f] > 0) {
      h[f] = 7;
    }
    if (x[f] < 0 && y[f] < 0) {
      h[f] = 5;
    }
    if (x[f] > 0 && y[f] < 0) {
      h[f] = 3;
    }
    if (x[f] > 0 && y[f] == 0) {
      h[f] = 2;
    }
    if (x[f] < 0 && y[f] == 0) {
      h[f] = 6;
    }
    if (x[f] == 0 && y[f] < 0) {
      h[f] = 4;
    }
    if (x[f] == 0 && y[f] > 0) {
      h[f] = 0;
    }
  }
  if (tick >= tickspeed) {
    ai();
    tick = 0;
  }
  tick++;
  shadowf = -shadowf;
}

void ai() {
  for (int f = 0; f < stock; f++) {
    x[f] = int(round(sin(s[f]+PI)*st[f]*fineness));
    y[f] = int(round(cos(s[f]+PI)*st[f]*fineness));
    if (dist(width/2, height/2, xx[f], yy[f]) > limits) {
      s[f] = (atan2(xx[f]-(width/2), yy[f]-(height/2)));
      //h[f] = 10;
    } else {
      //s[f] += random(-PI/2, PI/2)/2;
    }
    s[f] += map(noise(ns[f]), 0, 1, -PI/4, PI/4);
    ns[f] += 0.02;
    if (stoptick >= stoptickspeed) {
      st[f] = int(round(random(0, 4)));
      if (st[f] < 0)st[f] = 0;
      if (st[f] > 2)st[f] = 2;
      stoptick = 0;
    }
    if (mousePressed) {
      if (dist(mouseX, mouseY, xx[f], yy[f]) > 48*2) {
        s[f] = (atan2(xx[f]-(mouseX), yy[f]-(mouseY)))+((map(noise(ns[f]), 0, 1, -PI/3, PI/3)));
        st[f] = 4;
      }else{
        //s[f] = (atan2(xx[f]-(mouseX), yy[f]-(mouseY))+PI);
        st[f] = 2;  
      }
    }
    stoptick++;
  }
}

void keyPressed(){
  if(keyCode == ESC)exit(); 
}

使用画像⇩Used image↓

 

 

 

↑ You can not see it on a white background, but there are 8 images of white clothes. I put colors randomly on this white clothes.

白い背景では見えませんが、白い服の画像8つです。この白い服にランダムに色を載せています。

Follow me!

コメントを残す