2016-09-18 3 views
1

나는 처리 3과 함께 일하고 있는데 실제로 2 개의 창을 사용하려고합니다.왜 처리로 SecondApplet을 다시 그릴 수 없습니까?

두 번째 창을 다시 그리기를 원하지만 아무것도 다시 그리지 않습니다 (직렬 포트에서 들어오는 최종 프로젝트 데이터에서 다시 그리기를 할 것입니다). 나는 이유를 모른다.

/* 
* 17.09.16 : Logan Gallois 
* future imporvement : 
* Windows print graph of PWMs values from RGB LED 
* Add autoDetect position to move windows at the good location 
*/ 

import processing.serial.*; 
Serial myPort; 
SecondApplet sa; 

int[] numbers = new int[600]; 
boolean flag = false; 
float var1; 
float var2; 
float var3; 
float var4; 

void setup() { 
    size(1024, 576); //Affiche en plein écran 
    surface.setResizable(false); 
    noStroke(); 
    println(Serial.list()); /* Verifier dans la liste ou se trouve l'arduino */ 
    /* Puis changer en dessous la valeur en fonction */ 
    /* En general 0 pour windows et 1 pour un mac */ 
    String os=System.getProperty("os.name"); /* Detection automatique de l'OS */ 
    if(os != "Mac OS X") { 
    if(Serial.list().length > 0) { 
     myPort = new Serial(this, Serial.list()[0], 115200); 
    } 
    } else { 
    if(Serial.list().length > 1) { /* Module BLE en position 0 */ 
     myPort = new Serial(this, Serial.list()[1], 115200); 
    } 
    } 
    //Important : se câler sur la valeur en baud du prog Arduino 
    myPort.bufferUntil('\n'); 
    String[] args = {"TwoFrameTest"}; 
    sa = new SecondApplet(); 
    PApplet.runSketch(args, sa); 
    delay(100); 
} 

void draw() { 
    if(!flag) { 
    surface.setLocation(displayWidth/2-width/2-400,displayHeight/2-height/2); 
    sa.frame.setTitle("Monitoring RGB Values"); 
    flag = true; 
    } 
    background(color(int(var1), int(var2), int(var3))); 
    //sa.background(0, 255, 0); 
    /*for(int i = 0 ;i<=width/10;i++){ 
    sa.stroke(200); 
    sa.line((-frameCount%10)+i*10,0,(-frameCount%10)+i*10,height); 

    sa.line(0,i*10,width,i*10); 
    } 

    sa.noFill(); 
    sa.stroke(0); 
    sa.beginShape(); 
    for(int i = 0; i<numbers.length;i++){ 
     sa.vertex(i,350-numbers[i]); 
    } 
    sa.endShape(); 
    for(int i = 1; i<numbers.length;i++){ 
     numbers[i-1] = numbers[i]; 
    } 
    numbers[numbers.length-1]=mouseY;*/ 
} 

void mouseClicked() { 
    print("clicked"); 
    sa.background(0, 0, 255); 
    sa.fill(100); 
    sa.redraw(); //This line do not redraw my 'sa' window 
    background(0, 0, 255); 
    redraw(); 
} 

void serialEvent (Serial myPort) { 

    String inString = myPort.readStringUntil('\n'); 
    //println(inString); 
    if (inString != null) { 

    inString = trim(inString); 
    int inputs[] = int(split(inString,',')); // on élude les virgules 

    // on affecte nos 4 valeurs 
    if(inputs.length == 4) { 
    var1 = inputs[0]; 
    var2 = inputs[1]; 
    var3 = inputs[2]; 
    var4 = inputs[3]; 

    // On ré-échelonne la valeur analogique en valeur RGB 
    var1 = map(var1, 0, 1023, 0, 255); 
    var2 = map(var2, 0, 1023, 0, 255); 
    var3 = map(var3, 0, 1023, 0, 255); 
    var4 = map(var3, 0, 1023, 0, 255); 
    print(int(var1)); 
    print(" ,"); 
    print(int(var2)); 
    print(" ,"); 
    print(int(var3)); 
    print(" ,"); 
    println(var4); 
    } 
    } 
} 

public class SecondApplet extends PApplet { 

    public void settings() { 
    size(600, 600); 
    noLoop(); //I tried with and without that 
    } 
    public void draw() { 

    } 

    public void mouseClicked() { 
    print("clicked2"); 
    background(0, 255, 0); 
    redraw(); //This line works great 
    } 
} 

어떤 아이디어 : 여기

내 코드?

답변

2

게시 할 때 문제를 MCVE으로 좁혀보십시오. 즉, 모든 직렬 기능을 제거하고 기본 마우스 이벤트 만 사용하는 것입니다.

두 번째 스케치의 draw() 기능이 비어 있습니다. redraw()에게 실제로 전화를 걸 때 무엇을 기대합니까?

여기 예 MCVE입니다 :

SecondApplet sa; 

void setup() { 
    size(500, 500); //Affiche en plein écran 

    String[] args = {"TwoFrameTest"}; 
    sa = new SecondApplet(); 
    PApplet.runSketch(args, sa); 
    delay(100); 
} 

void draw() { 
    background(255, 0, 0); 
} 

void mouseClicked() { 
    sa.redraw(); 
} 

public class SecondApplet extends PApplet { 

    public void settings() { 
    size(100, 100); 
    noLoop(); 
    } 
    public void draw() { 
    background(0); 
    ellipse(random(width), random(height), 25, 25); 
    } 

    public void mouseClicked() { 
    redraw(); 
    } 
} 

이 MCVE 완벽하게 작동하고, 올바르게 모두 제 1 및 제 2 스케치 창에서 두 번째 스케치의 draw() 기능을 트리거합니다.

이 MCVE에서 작업하는 것이 좋습니다. 여전히 작동시키지 못한다면 직렬 질문없이 (하드웨어에 액세스 할 수 없기 때문에 스케치를 실행할 수 없게하는) 후속 질문을 게시 할 수 있습니다. 행운을 빕니다.

+0

좋아, 그 기능을 변경하여 *** 배경 *** 변경 배경 생각. 모두 현재 현재 작동 중입니다. 감사 –

관련 문제