首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MADMAPPER使用信标发送帧

MADMAPPER使用信标发送帧
EN

Stack Overflow用户
提问于 2016-05-18 18:34:25
回答 1查看 361关注 0票数 0

我很难把素描从信标发给Madmapper。常规的“发送帧”草图可以工作,但是当我尝试将参数合并到我的草图中时,可视化不会显示。

请看一下我的代码,让我知道我做错了什么:

代码语言:javascript
复制
   //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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-18 19:02:20

您似乎没有正确地使用PGraphics实例:有些调用使用它,有些调用在主草图中绘制,但不使用画布PGraphics,这是您发送给Syphon的内容。

一个快速的解决方法是调用server.sendScreen();而不是server.sendImage();

这样,在处理过程中所看到的就是通过Syphon在MadMapper中看到的:

或者,您也可以修复PGraphics调用:

代码语言:javascript
复制
//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目前使用起来很混乱,跳过它并发送屏幕:

代码语言:javascript
复制
//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;
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37307606

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档