2016-05-18 45 views
0

我無法通過虹吸管將草圖發送到Madmapper。 常規的「發送框架」草圖工作,但是當我嘗試將參數合併到我的草圖時,可視化不顯示。使用虹吸管發送框架用於MADMAPPER

請看看我的代碼,讓我知道我在做什麼錯:

//Final Project 
import codeanticode.syphon.*; 


float rotation=0.1; 
int num = 100, frms = 320; 
float theta, time; 
long rs; 
PGraphics canvas; 
SyphonServer server; 

//long: Use this datatype when you need a number to have a greater magnitude than can be 
//stored within an int. 

void setup() { 
    size(800, 800, P2D); 
    canvas = createGraphics(800, 800, P2D); 
    loop(); 
    server = new SyphonServer(this, "sublime"); 
}; 


void draw() { 

    background(0); 

canvas.beginDraw(); 
canvas.smooth(); 
    noStroke(); 
    fill(255, 255, 255, 20); 
    rect(mouseX, mouseY, 50, 50); 

    time = (frameCount % frms)/float(frms); 
    paintQuads(); 
    theta += 2/TWO_PI/frms; 
} 



void paintQuads() { 
    for (int i=0; i<num; i++) { 
    fill(0); 
    stroke(255); 
    float r = random(-.5, .5); 
    float sz = random(5, 15); 
    resetMatrix(); // Replaces the current matrix with the identity matrix. 
    // This effectively clears all transformation functions set before it. 



    //multiply the quads 

    //Translate 
    //Specifies an amount to displace objects within the display window. 
    //The x parameter specifies left/right translation, the y parameter specifies up/down 
    //translation, and the z parameter specifies translations toward/away from the screen. 
    //Using this function with the z parameter requires using P3D as a parameter in 
    //combination with size as shown in the above example. 


    translate(random(width), random(height)); 
    rotate(r); 
    rotate(rotation); 

    //images 

    noStroke(); 

    fill(255, 0, 0, 70); 
    quad(38, 31, 86, 20, 69, 63, 30, 76); 

    fill(255, 210, 0, 10); 
    quad(width-9, height-9, 86, 20, 69, 63, 30, 76); 

    fill(255, 0, 0, 30); 
    ellipse(36, 36, 16, 16); 

    fill(50, 46, 100, 20); 
    quad(46, 20, 14, 14, 46, 20, 14, 14); 

    fill(50, 46, 100, 75); 
    quad(50, 0, 12, 12, 50, 0, 12, 12); 

    rotation=rotation+0.5; 
    } 
    canvas.endDraw(); 
    image(canvas, 0, 0); 
    //send canvas to Syphon 
    server.sendImage(canvas); 
} 

謝謝! -k

+0

當你說可視化文件沒有顯示時,你究竟是什麼意思?它不顯示哪裏?你有任何異常或堆棧跟蹤? –

+0

嗨凱文,我的意思是,可視化不能在瘋狂的映射器中看到。素描可行,但我似乎無法將視覺效果發送到我想要的區域。我無法在Madmapper中看到圖像。 – krizz

回答

1

看來你並沒有正確使用PGraphics實例:一些調用使用它,一些繪製到主草圖中,但不是畫布PGraphics,這是你發送給虹吸的東西。

一個快速的解決方法是調用server.sendScreen();代替server.sendImage();

這種方式有什麼見處理是你通過虹吸管MadMapper看到: syphon mad mapper preview

或者,您可以解決您的PGraphics電話:

//Final Project 
import codeanticode.syphon.*; 


float rotation=0.1; 
int num = 100, frms = 320; 
float theta, time; 
long rs; 
PGraphics canvas; 
SyphonServer server; 

//long: Use this datatype when you need a number to have a greater magnitude than can be 
//stored within an int. 

void setup() { 
    size(800, 800, P2D); 
    canvas = createGraphics(800, 800, P2D); 
    loop(); 
    server = new SyphonServer(this, "sublime"); 
}; 


void draw() { 

    background(0); 

    canvas.beginDraw(); 
    canvas.smooth(); 
    canvas.background(0); 
    noStroke(); 
    fill(255, 255, 255, 20); 
    rect(mouseX, mouseY, 50, 50); 

    time = (frameCount % frms)/float(frms); 
    paintQuads(canvas); 
    theta += 2/TWO_PI/frms; 

    canvas.endDraw(); 
    image(canvas,0,0); 
    server.sendImage(canvas); 
} 



void paintQuads(PGraphics g) { 
    for (int i=0; i<num; i++) { 
    g.fill(0); 
    g.stroke(255); 
    float r = random(-.5, .5); 
    float sz = random(5, 15); 
    g.resetMatrix(); // Replaces the current matrix with the identity matrix. 
    // This effectively clears all transformation functions set before it. 



    //multiply the quads 

    //Translate 
    //Specifies an amount to displace objects within the display window. 
    //The x parameter specifies left/right translation, the y parameter specifies up/down 
    //translation, and the z parameter specifies translations toward/away from the screen. 
    //Using this function with the z parameter requires using P3D as a parameter in 
    //combination with size as shown in the above example. 


    g.translate(random(width), random(height)); 
    g.rotate(r); 
    g.rotate(rotation); 

    //images 

    g.noStroke(); 

    g.fill(255, 0, 0, 70); 
    g.quad(38, 31, 86, 20, 69, 63, 30, 76); 

    g.fill(255, 210, 0, 10); 
    g.quad(width-9, height-9, 86, 20, 69, 63, 30, 76); 

    g.fill(255, 0, 0, 30); 
    g.ellipse(36, 36, 16, 16); 

    g.fill(50, 46, 100, 20); 
    g.quad(46, 20, 14, 14, 46, 20, 14, 14); 

    g.fill(50, 46, 100, 75); 
    g.quad(50, 0, 12, 12, 50, 0, 12, 12); 

    rotation=rotation+0.5; 
    } 

    // image(canvas, 0, 0); 
    //send canvas to Syphon 

    // server.sendScreen(); 
} 

或者如果PGraphics現在使用混亂,請完全跳過併發送屏幕:

//Final Project 
import codeanticode.syphon.*; 


float rotation=0.1; 
int num = 100, frms = 320; 
float theta, time; 
long rs; 

SyphonServer server; 

//long: Use this datatype when you need a number to have a greater magnitude than can be 
//stored within an int. 

void setup() { 
    size(800, 800, P2D); 
    smooth(); 

    server = new SyphonServer(this, "sublime"); 
}; 


void draw() { 

    background(0); 

    noStroke(); 
    fill(255, 255, 255, 20); 
    rect(mouseX, mouseY, 50, 50); 

    time = (frameCount % frms)/float(frms); 
    paintQuads(); 
    theta += 2/TWO_PI/frms; 

    server.sendScreen(); 
} 



void paintQuads() { 
    for (int i=0; i<num; i++) { 
    fill(0); 
    stroke(255); 
    float r = random(-.5, .5); 
    float sz = random(5, 15); 
    resetMatrix(); // Replaces the current matrix with the identity matrix. 
    // This effectively clears all transformation functions set before it. 



    //multiply the quads 

    //Translate 
    //Specifies an amount to displace objects within the display window. 
    //The x parameter specifies left/right translation, the y parameter specifies up/down 
    //translation, and the z parameter specifies translations toward/away from the screen. 
    //Using this function with the z parameter requires using P3D as a parameter in 
    //combination with size as shown in the above example. 


    translate(random(width), random(height)); 
    rotate(r); 
    rotate(rotation); 

    //images 

    noStroke(); 

    fill(255, 0, 0, 70); 
    quad(38, 31, 86, 20, 69, 63, 30, 76); 

    fill(255, 210, 0, 10); 
    quad(width-9, height-9, 86, 20, 69, 63, 30, 76); 

    fill(255, 0, 0, 30); 
    ellipse(36, 36, 16, 16); 

    fill(50, 46, 100, 20); 
    quad(46, 20, 14, 14, 46, 20, 14, 14); 

    fill(50, 46, 100, 75); 
    quad(50, 0, 12, 12, 50, 0, 12, 12); 

    rotation=rotation+0.5; 
    } 
}