画面に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}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/07 00:38