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

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

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

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Processing

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

Q&A

解決済

1回答

1045閲覧

描画したい線が設定しても別のところで設定した色と太さになってしまう

ameshikou

総合スコア8

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Processing

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

0グッド

0クリップ

投稿2020/06/06 16:21

画面にindex()の内容のとおりに線を描画したいのですが、実行するとm.display()で設定した色、太さになってしまいます。設定する色や太さを別々にするにはどうすればいいのでしょうか。
宜しくお願いします。

ソースコードは以下の通りです。

shikibou.pde

java

1//import ddf.minim.*; 2 3//Minim minim; 4//AudioPlayer player; 5 6PImage img1; 7PImage orche; 8//Mover[] movers = new Mover[1]; 9Mover m; 10 11void settings(){ 12 orche = loadImage("orchestra2.jpg"); 13 size(orche.width,orche.height); 14} 15 16void shikibou(){ 17 image(img1,mouseX,mouseY); 18 img1.resize(183,99); 19 imageMode(CENTER); 20} 21 22void setup(){ 23 /*minim = new Minim(this); 24 player = minim.loadFile("Theme_of_FinalFantasy.mp3"); 25 player.play();*/ 26 m = new Mover(width/2,height/2); 27 /*for (int i = 0; i < movers.length; i++) { 28 movers[i] = new Mover(); 29 }*/ 30 img1 = loadImage("shikibou.png"); 31} 32 33void draw(){ 34 background(orche); 35 shikibou(); 36 37 //for (int i = 0; i < m.length; i++) { 38 m.update(); 39 m.display(); 40 index(); 41 //} 42} 43 44void index(){ 45 line(width/2,height*5/6,width/2,height*1/6); 46 stroke(128); 47 strokeWeight(50); 48} 49 50/*void stop(){ 51 player.close(); 52 minim.stop(); 53 super.stop(); 54}*/

Mover.pde

java

1class Mover { 2 ArrayList<PVector> history = new ArrayList<PVector>(); 3 4 // The Mover tracks position, velocity, and acceleration 5 PVector position; 6 PVector velocity; 7 PVector acceleration; 8 // The Mover's maximum speed 9 float topspeed; 10 float maxforce; 11 12 Mover(float x,float y) { 13 14 // Start in the center 15 acceleration = new PVector(0,0); 16 //position = new PVector(random(width),random(height)); 17 position = new PVector(x,y); 18 velocity = new PVector(0,0); 19 topspeed = 15; 20 maxforce = 0.1; 21 } 22 23 void update() { 24 25 // Compute a vector that points from position to mouse 26 PVector mouse = new PVector(mouseX-91,mouseY-49); 27 acceleration = PVector.sub(mouse,position); 28 // Set magnitude of acceleration 29 //acceleration.setMag(0.2); 30 //acceleration.normalize(); 31 //acceleration.mult(0.7); 32 //acceleration.mult(0); 33 34 // Velocity changes according to acceleration 35 velocity.add(acceleration); 36 // Limit the velocity by topspeed 37 velocity.limit(topspeed); 38 // position changes by velocity 39 position.add(velocity); 40 acceleration.mult(0); 41 42 history.add(position.get()); 43 if (history.size() > 250) { 44 history.remove(0); 45 } 46 } 47 48 void applyForce(PVector force) { 49 // We could add mass here if we want A = F / M 50 acceleration.add(force); 51 } 52 53 void arrive(PVector target) { 54 PVector desired = PVector.sub(target,position); // A vector pointing from the position to the target 55 float d = desired.mag(); 56 // Scale with arbitrary damping within 100 pixels 57 if (d < 100) { 58 float m = map(d,0,100,0,topspeed); 59 desired.setMag(m); 60 } else { 61 desired.setMag(topspeed); 62 } 63 64 // Steering = Desired minus Velocity 65 PVector steer = PVector.sub(desired,velocity); 66 steer.limit(maxforce); // Limit to maximum steering force 67 applyForce(steer); 68 } 69 70 void display() { 71 beginShape(); 72 colorMode(HSB); 73 stroke(210,255,255); 74 strokeWeight(10); 75 fill(255,0,0); 76 ellipse(position.x,position.y,20,20); 77 noFill(); 78 for(PVector v: history) { 79 vertex(v.x,v.y); 80 } 81 endShape(); 82 83 } 84 85}

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

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

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

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

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

guest

回答1

0

ベストアンサー

どうなればいいか、というのがよくわかりませんが、

Processing

1void index(){ 2 stroke(128); 3 strokeWeight(50); 4 line(width/2,height*5/6,width/2,height*1/6); 5}

とすれば希望の動作になるのでしょうか?

投稿2020/06/07 00:05

thkana

総合スコア7639

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

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

ameshikou

2020/06/07 00:38

ちゃんと動作しました!こんな初歩的なミスに気付かないとはお恥ずかしい限りです… ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問