We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I am rewriting a lot of Sketches with PGraphics, so that they can be transmitted via Syphon to external software (such as Isadora, MAX or Resolume). I got stuck when trying to convert one of the examples developed on Gene's Kogan Generative Art Class @ tenlegs. I guess the problem is related to the variables, but cannot figure a way out of that. Any suggestions?
int a, b, d;
void setup() {
size (640, 480);
frameRate(60);
background(255);
a = 0;
b = height;
d = 3;
}
void draw() {
if (a > width) {
stroke(255);
d = -d;
}
else if (a < 0) {
stroke(0);
d = -d;
}
line(a, 0, a, b);
a += d;
}
import codeanticode.syphon.*;
PGraphics lineSeg;
SyphonServer server;
int a = 0;
int b = height;
int d = 3;
void setup() {
size (640, 480, P3D);
lineSeg = createGraphics(640, 480, P3D);
server = new SyphonServer(this, "Processing Syphon");
// frameRate(60);
// background(255);
}
void draw() {
lineSeg.beginDraw();
lineSeg.background(255);
if (a > width) {
lineSeg.stroke(255);
d = -d;
}
else if (a < 0) {
lineSeg.stroke(0);
d = -d;
}
q
lineSeg.line(a, 0, a, b);
a += d;
image(lineSeg, 0, 0);
}
Answers
I believe that I have fixed your changes - they were mostly trivial, but that probably comes with experience dealing with the language. I haven't tested the Syphon part (I don't have a Mac, or Syphon for that matter), but it works as expected otherwise.
The things that stood out:
endDraw()
.background()
insetup()
, notdraw()
for this type of effect.setup()
-height
, for instance, is0
untilsize()
runs.Corrected code:
P.S.: Also, I moved the topic to the sub-forum "Questions about Code" because you include a specific code snippet.
hi, i pasted you code and tried to run it, but i get:
java.lang.NullPointerException as follows.
and now I am referring to this http://wiki.processing.org/w/Why_do_I_get_a_NullPointerException?, to see if I can solve the problem.
Are you sure you need to use the P3D mode? Looks like the sketch is 2D. You get an OpenGL error, because of this P3D. Try without it.
PhiLho, actually the core aspect of my question was about the best way to include variables on a PGraphics context. I have converted a lot of Sketches to PGraphics to transmit then via Syphon to Isadora, but got stuck with this particular one. My assumption was that the problem was related with the variables. Anyway, I get the NullPointer Exception both with P2D and P3D. Thanks for commenting!
Use JAVA2D! P2D is a disguised OpenGL engine in Processing 2.x.x! [..]