###前提・実現したいこと
processingで複数window(window1とwindow2)でwindow1から画像の色情報を読み取り,window2で読み取った色の図形を表示するシステムを作っています.システムの手順を下記に記します.
①window1の任意の画像上でマウスをクリック
②クリックしたピクセルの色情報をwindow2のプログラムに送信
③window2で受けっとった色で塗りつぶされた図形を描画(クリックするごとに図形が追加されていく)
というシステムです.
複数windowと色情報を読み取り図形を描画するシステムはそれぞれ出来ているのですが,
私が勉強不足のためオブジェクト指向を理解できておらず
2つのプログラムを合体することができません.
どなたか2つのプログラムの合体方法を教えてください.
よろしくお願いします.
###該当のソースコード
○複数windowのプログラム スケッチ名:double_window1 class SecondApplet extends PApplet { PApplet parent; SecondApplet(PApplet _parent) { super(); // set parent this.parent = _parent; //// init window try { java.lang.reflect.Method handleSettingsMethod = this.getClass().getSuperclass().getDeclaredMethod("handleSettings", null); handleSettingsMethod.setAccessible(true); handleSettingsMethod.invoke(this, null); } catch (Exception ex) { ex.printStackTrace(); } PSurface surface = super.initSurface(); surface.placeWindow(new int[]{0, 0}, new int[]{0, 0}); this.showSurface(); this.startSurface(); } void settings() { size(800, 600); } void draw() { background(255); } } スケッチ名:SecondApplet SecondApplet second; void settings() { size(800, 600); } void setup() { second = new SecondApplet(this); } void draw() { background(255); } ○色情報を読み取り描画するシステム スケッチ名:arraylist ArrayList <Test> test = new ArrayList<Test>(); int x, y; import java.io.File; PImage img; void setup(){ size(300, 300); colorMode(HSB, 360, 100, 100); test = new ArrayList<Test>(); selectInput( "Select an image", "imageChosen" ); //画像の読み込み } void draw(){ background(255); if ( img != null ) //画像の表示 { image( img, width/2,height/2, 200,180 ); } for(Test t : test){ t.display(); } } void mouseClicked(){ test.add(new Test(mouseX, mouseY));//渡す }``` スケッチ名:test class Test{ PVector location; Test(int x1, int y1){ location = new PVector(x1, y1); } void display(){ color c = get(mouseX,mouseY); //マウスのピクセルの色情報を取得 fill(hue(c),saturation(c),brightness(c)); rect(location.x, location.y, 20, 20); } } void imageChosen( File f ) { if( f.exists() ) { img = loadImage( f.getAbsolutePath() ); } }
あなたの回答
tips
プレビュー