#プログラム
言ってしまえば全然きれいなコードではないので、そのうちきれいにして追加しておきます
The_Processing.java
//全体回転
float rY = 0;
//文字の奥行
int length = 50;
//アニメーション管理
int mode = 0;
//タイマー用
int count;
//それぞれのクラスを宣言
P p ;
Three three;
Back back;
Line[] lines = new Line[21];
void setup() {
size(1500, 900, P3D);
//fullScreen(P3D);
frameRate(30);
strokeWeight(1);
//セットアップ
SetUpMark();
SetUpLines();
}
void SetUpP3() {
p = new P(100, 50, length, 180);
three = new Three(100, 50, length, 200);
}
void SetUpMark() {
SetUpP3();
back = new Back(400, 50, length, 360);
}
void SetUpLines() {
lines[0] = new Line(320, -150, 85, -225);
lines[1] = new Line(85, -225, -75, -300);
lines[2] = new Line(-75, -300, 100, -340);
lines[3] = new Line(-75, -300, -120, -340);
lines[4] = new Line(-75, -300, -200, -75);
lines[5] = new Line(-200, -75, -340, -150);
lines[6] = new Line(-200, -75, -350, -10);
lines[7] = new Line(-200, -75, -250, 0);
lines[8] = new Line(-200, -75, -150, 275);
lines[9] = new Line(-200, -75, -120, 10);
lines[10] = new Line(-250, 0, -330, -100);
lines[11] = new Line(-250, 0, -350, 10);
lines[12] = new Line(-250, 0, -300, 200);
lines[13] = new Line(-250, 0, -150, 275);
lines[14] = new Line(-250, 0, -120, 10);
lines[15] = new Line(-120, 10, -150, 275);
lines[16] = new Line(-150, 275, 50, 275);
lines[17] = new Line(50, 275, 225, 30);
lines[18] = new Line(225, 30, 320, -150);
lines[19] = new Line(225, 30, 85, -225);
lines[20] = new Line(50, 275, -120, 10);
}
void draw() {
lights();
perspective();
background(0);
translate(width/2, height/2, -500); //中心に移動
rotateY(rY); // 全体回転
if (mode != 3) {
DrawLines();
noStroke();
fill(255);
if (lines[19].x == lines[19].x2) {
p.Draw();
pushMatrix();
translate(0, -150);
if (p.r == p.radian)three.Draw();
popMatrix();
}
}
if (three.H == 75 || mode == 3) {
back.Draw();
}
//アニメーションモードごとに管理
switch(mode) {
case 0:
//8PI回ったら次のモード
Rotater(8);
break;
case 1:
//約3秒待ったら次のモード(ここシャッターチャンス)
WaitCounter(3);
break;
case 2:
rY -= 0.01f;
if (rY < -PI/2) {
mode++;
SetUpP3();
SetUpLines();
}
case 3:
rY -= 0.01f;
if (back.r == 0) {
rY = 0;
mode = 0;
SetUpMark();
}
break;
}
}//********** void draw()*************//
class P {
float topH = 0; //上の高さ
float midH = 0; //真ん中の高さ
float botH = 0; //下の高さ
int r = 0; //半円の角度
float radius;
int wid, length, radian;
P(float radius, int wid, int length, int radian) {
topH = 0;
midH = 0;
botH = 0;
r = 0;
this.radius = radius;
this.wid = wid;
this.length = length;
this.radian = radian;
}
void Draw() {
pushMatrix();
translate(-50, 200 + (50-botH/2));
box(150, botH, length);
if (botH != 50) botH++;
popMatrix();
pushMatrix();
translate(-50, -50 + (250-midH/2));
if (botH == 50) {
box(50, midH, length);
if (midH != 250) midH++;
}
popMatrix();
pushMatrix();
translate(-75, -100 + (50-topH/2));
if (botH == 50 && midH == 250) {
box(100, topH, length);
if (topH != 50) topH++;
}
popMatrix();
if (botH == 50 && midH == 250 && topH == 50) {
Curve(radius, wid, length, r);
if (r < radian) r++;
}
}
void Reset() {
topH = midH = botH = 0;
}
}
class Three {
int H = 0;
int r = 0; //半円の角度
float radius;
int wid, length, radian;
Three(float radius, int wid, int length, int radian) {
H = 0;
r = 0;
this.radius = radius;
this.wid = wid;
this.length = length;
this.radian = radian;
}
void Draw() {
pushMatrix();
translate(12.5f, 0);
Curve(radius, wid, length, r);
if (r < 200) r++;
popMatrix();
pushMatrix();
translate(-12.5f, -22.5f - (75-H/2));
if (r == 200) {
box(25, H, length);
if (H < 75) H++;
}
popMatrix();
}
}
class Back {
int r = 0; //半円の角度
float radius;
int wid, length, radian;
Back(float radius, int wid, int length, int radian) {
r = 0;
this.radius = radius;
this.wid = wid;
this.length = length;
this.radian = radian;
}
void Draw() {
Curve(radius, wid, length, r);
if (mode < 2) {
if (r < radian) r++;
} else {
if (r > 0) r--;
}
}
}
class Line {
float x, y, x1, y1, x2, y2;
float xa, ya;
Line(float x1, float y1, float x2, float y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
x = x1;
y = y1;
ya = (y2 - y1)/(x2 - x1); // xが1進んだ時のyの変化量
xa = Sign(x2-x1); // 進む向き
}
void Draw() {
line(x1, y1, x, y);
if (x != x2) {
x += xa;
y += ya * xa;
}
}
}
//全体回転メソッド
void Rotater(float r) {
rY += 0.01f;
if (rY >= PI * r) {
rY = 0;
mode++;
count = frameCount;
}
}
//タイマーメソッド
void WaitCounter(int timer) {
if (frameCount >= count + frameRate * timer) {
mode++;
}
}
//マイナスだったら-1を返すメソッド
float Sign(float a) {
if (a < 0)return -1;
else return 1;
}
//バウムクーヘン型を作るメソッド
// Curve(半径 , 文字幅 , 奥行幅 , 描く角度の最大)
void Curve(float radius, int wid, int length, int radian) {
float x, y;
int z = length/2;
//外側カーブ
beginShape(QUAD_STRIP);
for (int deg = 0; deg <= radian; deg += 1) {
x = sin(radians(deg)) * radius;
y = cos(radians(deg)) * radius;
vertex(x, y, z);
vertex(x, y, -z);
}
endShape();
//内側カーブ
beginShape(QUAD_STRIP);
for (int deg = 0; deg <= radian; deg += 1) {
x = sin(radians(deg)) * (radius - wid);
y = cos(radians(deg)) * (radius - wid);
vertex(x, y, z);
vertex(x, y, -z);
}
endShape();
//バウムクーヘンの層が見える部分(手前)(奥)
for (int i = -1; i<=1; i++) {
if (i == 0)continue;
beginShape(TRIANGLE_STRIP);
for (int deg = 0; deg <= radian; deg += 1) {
x = sin(radians(deg));
y = cos(radians(deg));
vertex(x* radius, y* radius, z * i);
vertex(x*(radius - wid), y*(radius - wid), z * i);
}
endShape();
}
//蓋
pushMatrix();
rotateY(PI/2);
pushMatrix();
rotateX(radians(radian));
quad(z, radius-wid, -z, radius-wid, -z, radius, z, radius);
popMatrix();
quad(z, radius-wid, -z, radius-wid, -z, radius, z, radius);
popMatrix();
}
//線を順番に描いていくメソッド
void DrawLines() {
stroke(255);
strokeWeight(2);
lines[0].Draw();
if (lines[0].x != lines[0].x2) return;
lines[1].Draw();
if (lines[1].x != lines[1].x2) return;
lines[2].Draw();
lines[3].Draw();
lines[4].Draw();
if (lines[4].x != lines[4].x2) return;
lines[5].Draw();
lines[6].Draw();
lines[7].Draw();
lines[9].Draw();
if (lines[7].x != lines[7].x2) return;
lines[10].Draw();
lines[11].Draw();
lines[12].Draw();
lines[13].Draw();
lines[14].Draw();
if (lines[13].x < lines[8].x1)return;
lines[8].Draw();
if (lines[8].x < -180) return;
lines[15].Draw();
if (lines[15].x != lines[15].x2) return;
stroke(30, 100, 150);
lines[16].Draw();
if (lines[16].x != lines[16].x2)return;
stroke(30, 150, 200);
lines[20].Draw();
stroke(60, 200, 300);
lines[17].Draw();
if (lines[17].x != lines[17].x2)return;
lines[18].Draw();
lines[19].Draw();
}//void DrawLines()