質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Processing

Processingは、オープンソースプロジェクトによるCGのためのプログラミング言語です。Javaをベースにしており、グラフィック機能に特化しています。イメージの生成やアニメーションなど、視覚的なフィードバックを簡単に得ることが可能です。

Q&A

0回答

869閲覧

Processing 3D 図形を重ねた時に色が混ざる

_._._ami

総合スコア26

Processing

Processingは、オープンソースプロジェクトによるCGのためのプログラミング言語です。Javaをベースにしており、グラフィック機能に特化しています。イメージの生成やアニメーションなど、視覚的なフィードバックを簡単に得ることが可能です。

0グッド

0クリップ

投稿2021/12/07 01:39

processingで3Dの図形を色を混ぜずに重ねたいです.

実行直後の向き(正面から)だと1枚目の画像のようになるのですが,マウスを動かして角度を変えると2枚目の画像のように黄色と黒が混ざってしまいます.

常に黒が上に来るようにしたいのですが,どうすればよいでしょうか?

イメージ説明
イメージ説明

/* @pjs font="TEMPSITC.TTF"; */ boolean isGrid = true, isAxis = true; void setup(){ size(500, 300, P3D); noStroke(); textFont(createFont("Tempus Sans ITC", 24)); frameRate(10); } void axis(char s, color c){ int len = 200; fill(c); stroke(c); if(isAxis){ box(len, 1, 1); pushMatrix(); translate(len / 2, 0, 0); sphere(3); text(s, 5, -5, 0); popMatrix(); } if(isGrid){ pushMatrix(); translate(0, -len / 2, -len / 2); int ngrids = 20, xs = len / ngrids, ys = len / ngrids; strokeWeight(1); for(int i = 1; i < ngrids; i++){ line(0, 0, ys * i, 0, len, ys * i); line(0, xs * i, 0, 0, xs * i, len); } popMatrix(); } } void drawAxis(char s, color c){ switch(s){ case 'X': axis(s, c); break; case 'Y': pushMatrix(); rotateZ(PI / 2); axis(s, c); popMatrix(); break; case 'Z': pushMatrix(); rotateY(-PI / 2); axis(s, c); popMatrix(); break; } } void coloredCube(){ pushMatrix(); scale(.5, .5, .5); noStroke(); beginShape(QUADS); fill(245, 223, 77); vertex(1, -1, -1); vertex(1, -1, 1); vertex(1, 1, 1); vertex(1, 1, -1); vertex(1, 1, 1); vertex(-1, 1, 1); vertex(-1, 1, -1); vertex(1, 1, -1); vertex(-1, 1, 1); vertex(1, 1, 1); vertex(1, -1, 1); vertex(-1, -1, 1); vertex(-1, -1, -1); vertex(-1, -1, 1); vertex( 1, -1, 1); vertex( 1, -1, -1); vertex(-1, 1, -1); vertex(-1, 1, 1); vertex(-1, -1, 1); vertex(-1, -1, -1); vertex(1, 1, -1); vertex(-1, 1, -1); vertex(-1, -1, -1); vertex(1, -1, -1); endShape(); popMatrix(); } void pillar(float length, float radius1 , float radius2, int r, int g, int b){ float x,y,z; pushMatrix(); noStroke(); fill(r,g,b); //top beginShape(TRIANGLE_FAN); y = -length / 2; vertex(0, y, 0); for(int deg = 0; deg <= 360; deg = deg + 10){ x = cos(radians(deg)) * radius1; z = sin(radians(deg)) * radius1; vertex(x, y, z); } endShape(); //bottom beginShape(TRIANGLE_FAN); y = length / 2; vertex(0, y, 0); for(int deg = 0; deg <= 360; deg = deg + 10){ x = cos(radians(deg)) * radius2; z = sin(radians(deg)) * radius2; fill(r,g,b); vertex(x, y, z); } endShape(); //side beginShape(TRIANGLE_STRIP); for(int deg =0; deg <= 360; deg = deg + 5){ x = cos(radians(deg)) * radius1; y = -length / 2; z = sin(radians(deg)) * radius1; vertex(x, y, z); x = cos(radians(deg)) * radius2; y = length / 2; z = sin(radians(deg)) * radius2; vertex(x, y, z); } endShape(); popMatrix(); } void drawShape(){ pushMatrix(); translate(0, 20, 0); scale(100, 40, 60); coloredCube(); popMatrix(); pushMatrix(); translate(40, 0, 0); rotateX(HALF_PI); fill(0); pillar(60,20,20,0,0,0); popMatrix(); pushMatrix(); translate(-40, 0, 0); rotateX(HALF_PI); pillar(60,20,20,0,0,0); popMatrix(); } void draw(){ background(255); translate(250, 150, -50); rotateX(map(mouseY, 0, height, PI, -PI)); rotateY(map(mouseX, 0, width, -PI, PI)); pushMatrix(); drawAxis('X', color(255, 0, 0, 60)); drawAxis('Y', color(0, 255, 0, 60)); drawAxis('Z', color(0, 0, 255, 60)); drawShape(); popMatrix(); }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

TN8001

2021/12/07 09:19

黒い筒をちょびっと大きくする(あるいは黄色い箱を小さくする)のではダメですか? pillar(60.1,20,20,0,0,0);
_._._ami

2021/12/09 01:07

なるほど!ダメじゃないです.ありがとうございます!!
TN8001

2021/12/09 02:04

試してみて見た目も問題なくほかに不都合がなければ、自己回答で閉じていただいて結構です。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問