hi !
I'm having great fun learning and experimenting with Processing,
and I'm trying to run a sketch on processing.js.
First of all, the sketch runs very slowly on processing.js while I have no problem in processing.
I'm using P3D mode because I'm using modelX() function.
Maybe the sketch would run better in 2D mode, but I can't find a similar function (modelX) in 2D mode.
Here is my code :
int nmax = 3000;
int NB = 0;
Ball[] ball = new Ball[0];
float xoff = 0.0;
float yoff = 0.0;
float xincrement = 0.004;
float yincrement = 0.01;
float vitesse = 0.5;
boolean info = true;
boolean arm = true;
String s;
class Ball
{
float taille;
float xinc;
float yinc;
Ball(float X,float Y)
{
xinc = X;
yinc = Y;
}
void display()
{
noStroke();
fill(0,0,255,40);
ellipse(xinc,yinc,10,10);
}
void move()
{yinc += vitesse;
}
}
void setup()
{
size(800,400,P3D);
background(255);
smooth(4);
frameRate(25);
}
void draw()
{
background(255);
if(info){infos();}
float n = noise(xoff)*PI*4.00;
xoff += xincrement;
float m = noise(yoff)*PI*4.00;
yoff += yincrement;
pushMatrix();
translate(width/2,height/2,0);
stroke(255,0,0,200);
rotateZ(n);
if(arm){line(0,0,0,75,0,0);}
pushMatrix();
translate(75,0,0);
rotate(m);
if(arm){line(0,0,0,75,0,0);}
translate(75,0,0);
float x = modelX(0, 0, 0);
float y = modelY(0, 0, 0);
popMatrix();
popMatrix();
NB += 1;
if(NB > nmax){NB = nmax;}
if(NB < nmax)
{
ball = (Ball[]) expand(ball, ball.length + 1);
ball[ball.length-1] = new Ball(x,y);
}
if(NB == nmax)
{
for(int j = 0; j<ball.length-1; j++)
{
ball[j] = ball[j+1];
}
ball[ball.length-1] = new Ball(x,y);
}
for(int i=0; i<ball.length;i++)
{
ball[i].display();
ball[i].move();
}
}
void keyPressed()
{
if(key == 'i'){info=!info;}
if(key == 'a'){arm=!arm;}
}
void infos()
{
fill(255,0,0);
s = " Bras \n";
s += "------------\n";
s += "fps " + round(frameRate) + "\n";
s += "------------\n";
s +="i -> infos\n";
s +="a -> arm\n";
text(s,width-95,20);
s = null;
}
I would greatly appreciate some help or advices.
Thank you in advance.
I'm trying to make a sketch where some balls move, and there is connections drawing between them.
I feel like I succeed to do it, but It seems to me that each connection (lines) are displayed two times. One time with the good positionning, and a second time with the positionning of the previous frame or something like this.
Here I set a low framerate to show this.
I would greatly appreciate if someone could help me pointing out what is the problem.
final int objNB = 8;
final int circlesNB = 3;
int taillemax = 90;
int maxspeed = 5;
Circle[] circles = new Circle[objNB];
void setup()
{
size(1024,576);
background(0);
smooth();
frameRate(15);
for(int i = 0;i<objNB;i++)
{
circles[i] = new Circle(random(taillemax-10,taillemax));