PImage
1PrintWriter outfile; 2float time; 3 4 5void setup() 6{ 7 // size(400, 400); 8 colorMode(RGB, 256); 9 noStroke(); 10 smooth(); 11 background(255, 255, 255); 12 13 outfile = createWriter("pos_t.txt"); 14 frameRate(20); 15 16 img = loadImage("kougishiryou.jpg"); 17 size( img.width, img.height ); 18 image(img, 0, 0); 19 strokeWeight(1); 20} 21int x, y; 22boolean pressed=false, released=false; 23 24void draw() 25{ 26 if (mousePressed == true) { 27 stroke(0, 0, 0); 28 line(mouseX, mouseY, pmouseX, pmouseY); 29 } 30 if (pressed) { 31 fill(255, 0, 0); 32 text("Pressed("+x+","+y+")", x, y, x+160, y+20); 33 outfile.println(mouseX + "," + mouseY); 34 outfile.flush(); 35 pressed=false; 36 } 37 if (released) { 38 fill(0, 0, 255); 39 text("Released("+x+","+y+")", x, y, x+160, y+20); 40 outfile.println(mouseX + "," + mouseY); 41 outfile.flush(); 42 released=false; 43 } 44} 45 46void mousePressed() { 47 x=mouseX; 48 y=mouseY; 49 pressed=true; 50} 51 52void mouseReleased() { 53 x=mouseX; 54 y=mouseY; 55 released=true; 56} 57void keyPressed() { 58 if(key == 'a'){ 59 outfile.close(); 60 exit(); 61 } 62} 63コード 64```processingで画像にラインを引くと,そのラインの最初の座標(x、y)と最後の座標(x、y)がテキストファイルに書き込まれるプログラムを組んでいます。 65 66このテキストファイルはプログラムが実行されるたびに上書きされています。 67質問内容はテキストファイルを上書きではなく、追記かプログラムを実行するたびにファイル名を変えてテキストファイルを保存したいです。 68(例:test.txt...test1.txt...test2.txt...のように) 69 70processingを始めたばかりでわからないことだらけですのでよろしくお願いします。```processing
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/16 06:38
2018/10/16 06:43
2018/10/16 06:45
2018/10/16 07:35
2018/10/16 07:39
2018/10/16 07:45
2018/10/16 07:47
2018/10/16 07:52
2018/10/16 07:53
2018/10/16 07:54
2018/10/16 08:00
2018/10/16 08:08
2018/10/16 08:10
2018/10/16 08:13
2018/10/16 08:17
2018/10/16 08:18
2018/10/16 08:25
2018/10/16 08:52
2018/10/16 08:52