We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hey coders,
i translate a p5js scetch to processing because i want to generate a mov file. the scetch is based on a tutorial from daniel shiffman on kadenze. but i´ve got a problem now with a boolean output. how can i code this piece of p5js code in processing
function draw() {
for( var i = 0; i < particles.length; i++) {
if(particles[i].isDead()) {
//code
}
}
}
function Particles() {
this.isDead = function() {
var distance = p5.Vector.sub(attractor.pos, this.pos);
var d = distance.mag();
if(d < 5) {
return true;
} else {
return false;
}
}
}
first i tried it with void, but void hasn´t got an output. then i tried something like this with boolean but it also doesn´t work.
void setup() {
//code
}
void draw () {
for (int i = 0; i < particles.length; i++) {
if(particles[i].isDead()) {
//code
}
}
}
Class Particle {
Particle() {
//code
}
boolean isDead() {
PVector distance = PVector.sub(a.location, location);
float d = distance.mag();
if(d < 5) {
return true;
} else {
return false;
}
}
}
it will be great if somebody can help me.
regards mattias
Answers
It's pretty rare conversions from web to desktop! @-)
Unfortunately your posted code isn't runnable b/c it tries to access members not present, such as variable attractor.
Therefore I've decided as 1st step get some minimum runnable p5.js sketch. Then work from there.
Tweaked code is posted below and "watchable" from this link:
http://CodePen.io/anon/pen/akxYWo?editors=1010
Now the corresponding Java Mode sketch: :bz
thanks a lot :)
Crossposted: http://stackoverflow.com/questions/39047288/problems-with-translating-a-p5js-sketch-into-processing
Please let us know when you crosspost to multiple websites, that way we don't waste our time answering questions that already have answers on other sites.