Help us understand the problem. What is going on with this article?

最近話題の片目3DをProcessingで試してみた

More than 1 year has passed since last update.

概要

最近話題の「片目3D」「GIFに2本線で浮き出て見える」と言った技術を自分でジェネレートするとどう見えるのかシミュレーションしてみました。

参考リンク

なにこれすごい「アニメGIFに縦線2本を入れるだけで裸眼で3D化」
試してみて!!裸眼で3D?! GIF画像に縦線2本を入れるだけで3D化できることが判明!!
ルパン三世のOPに隠された技術!片目で見るとなんと立体映像に!

実行方法

OpenProcessingで実行
または お手元のProcessing環境で

  • 1. Processingの作業ディレクトリを作成
  • 2.下記ソースコードをディレクトリ名と同じファイル名.pdeとして保存
  • 3.Processing上で実行

ソースコード

line3d.pde
float d = 0;
int SPEED=4;
int BAR_WIDTH = 25;
int MARGIN = 200;

void setup() {
  size(600, 600);
  rectMode(CENTER); 
  smooth();
}

//  影用
float saveX, saveY;

void draw() {
  background(128); 
  drawBackgroundBorder();

  //  オブジェクト描画
  float z = (d % 180) / int(90 /SPEED);

  if (z < 1) {
    drawDia();
    drawLeftBar();
    drawFrame();
    drawRightBar();
  } else if (z < 3) {
    drawLeftBar();
    drawFrame();
    drawDia();
    drawRightBar();
  } else if (z < 5) {
    drawLeftBar();
    drawFrame();
    drawRightBar();
    drawDia();
  } else if (z < 7) {
    drawLeftBar();
    drawFrame();
    drawDia();
    drawRightBar();
  } else if (z < 9) {
    drawDia();
    drawLeftBar();
    drawFrame();
    drawRightBar();
  }
  d += 0.5;
}

void drawDia() {
  float x = width / 2 + sin(radians(d)) * 30;
  float y = height / 2 + cos(radians(d * 2)) * 50;
  float s = abs(sin(radians(d))) * 500;

  //  着地した際の座標を記録
  if (d % 180 < 1) {
    saveX = x;
    saveY = y;
  }

  float rotation = radians(d * SPEED);

  //  影の描画
  fill(0, 128);
  noStroke();
  pushMatrix();
  translate(saveX, saveY);
  rotate(rotation); 
  rect(0, 0, s * 0.6, s / 10);
  popMatrix();

  //  オブジェクトの描画
  fill(255);
  stroke(0);
  strokeWeight(1);
  pushMatrix();
  translate(x, y);
  rotate(rotation); 
  rect(0, 0, s * 1.2, s / 5);
  ellipse(0, 0, s / 10, s / 10);

  //  焦点のずれ
  stroke(128);
  float w = abs(sin(radians(d)));

  noFill();
  strokeWeight(w * w * w * 5);
  stroke(0, 64);
  rect(0, 0, s * 1.2, s / 5);
  ellipse(0, 0, s / 10, s / 10);

  noFill();
  strokeWeight(w * w * w * 10);
  stroke(0, 32);
  rect(0, 0, s * 1.2, s / 5);
  ellipse(0, 0, s /10, s / 10);
  popMatrix();
}

void drawBackgroundBorder() {
  //  背景(地面)
  int slopeWeight = 5;
  strokeWeight(slopeWeight);
  stroke(192);
  float offset = d * SPEED % 10;
  int slopelength  = height / slopeWeight/2;
  for (int i = 0; i <slopelength; i++) {
    line(0, i*2*slopeWeight + offset, width, i*2*slopeWeight + offset);
  }
}

void drawFrame() {
  noFill();
  strokeWeight(50);
  rect(width / 2, height / 2, width, height);
}

void drawLeftBar() {
  drawBar(MARGIN);
}
void drawRightBar() {
  drawBar(width - MARGIN);
}
void drawBar(int position) {
  fill(0);
  stroke(0);
  strokeWeight(1);
  rect(position, height / 2, BAR_WIDTH, height);
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした