1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Processing]ゾートロープ的なもの

Last updated at Posted at 2020-03-14

的なもの

Zoetrope.gif
あまりよく見えないので、隙間からではなく上から見下ろしてます(ゾートロープじゃない気が…)

プログラム

Zoetrope.java
//Y軸回転
float rotateY = 0;

//画角
float fov = 3;

//回転速度
float speed = 0.01f;

//X軸回転
float rotateX = 0;

//円柱半径
float radius = 0;

//円柱高さ
float leng = 0;

//アニメーション番号
int aniNum = 0;

//貼り付ける画像
PImage tex;

void setup() {
  size(1600, 800, P3D);
  frameRate(30);

  tex = loadImage("Zoetrope.png");
}

void draw() {
  background(0);
  lights();
  perspective(PI/fov, (float)width/height, 10, 1000);

  //操作説明
  textSize(25);
  text(" A :accel\n D :decelerate\n W :Just speed\n S :Stop\n Click :Zoom", 
    0, height-250);

  translate(width/2, height/2+100, 100);

  noStroke();
  fill(255);

  rotateX(rotateX);
  rotateY(rotateY);

  Cylinder(leng, radius);

  rotateY += speed;

  //アニメーションスウィッチ
  switch(aniNum) {

  case 0:
    radius++;
    aniNum++;
    break;

  case 1:
    leng++;
    if (leng >= 250) aniNum++;
    break;

  case 2:
    radius ++;
    if (radius >= 150) aniNum++;
    break;

  case 3:
    rotateX -= PI/180;
    if (rotateX <= -PI/4) aniNum++;
    break;
  }
}

//円柱メソッド
//   Cylinder( 長さ , 半径 )
void Cylinder(float leng, float radius) {

  float x, y, z;

  pushMatrix();

  //底面
  beginShape(TRIANGLE_FAN);
  y = leng / 2;
  vertex(0, y, 0);
  for (int deg = 0; deg <= 360; deg += 2) {
    x = cos(radians(deg)) * radius;
    z = sin(radians(deg)) * radius;
    vertex(x, y, z);
  }
  endShape(); 

  //側面
  beginShape(QUAD_STRIP);
  texture(tex);
  textureMode(NORMAL);

  for (int deg = 0; deg <= 360; deg += 1) {
    x = cos(radians(deg)) * radius;
    y = -leng / 2;
    z = sin(radians(deg)) * radius;
    normal(x, 0, z);
    vertex(x, y, z, deg/360f, 0);

    x = cos(radians(deg)) * radius;
    y = leng / 2;
    z = sin(radians(deg)) * radius;
    normal(x, 0, z);
    vertex(x, y, z, deg/360f, 1);
  }
  endShape();

  popMatrix();
}

void keyPressed() {
  //a で加速 d で減速  w でいい感じの速度 d で停止
  if (key == 'a') speed += 0.01f;
  else if (key == 'd') speed -= 0.02f;
  else if (key == 'w') speed = 0.63f;
  else if (key == 's') speed = 0;
}

void mousePressed() {
  //画角切り替え
  if (mouseButton == LEFT) {
    fov = (fov+6)%12; //fovの値を3と9交互にする式
  }
}

使用画像

「Zoetrope.png」
Zoetrope.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?