LoginSignup
8
7

More than 5 years have passed since last update.

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

Last updated at Posted at 2015-12-01

概要

最近話題の「片目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);
}
8
7
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
8
7