# What difference can the amount of parameters have for stroke()?

I have a project, which draws lines along Lissajous-like paths.
Every now and then i want the line to change from one path to a newly generated one. In that moment i let the currentline disappear and the new one appear. every time a Line changes State from currently running to disappearing it jumps like 25 pixels(draw-function-calls) forward. I tested what may cause this and i think it’s because of my stroke() call. because if i change the stroke call to one with 3 parameters it works just fine and isn’t jumping any Pixels… Or if i give the stroke function a static parameter it stops jumping as well…

is it possibly a problem with my understanding of the stroke function? What can i change so it wont happen again?

If i should change my post/question, pls tell me.(First time)

eg:

``````static final int NUM_DOTS=350;
static final int NUM_LINES=1;
static final float FACTOR=1;
static final int TIMER=500;
int t=1;
float[] x_a=new float[NUM_LINES]; //a 5 - 50 b 80 - 200
float[] x_c=new float[NUM_LINES];
float[] y_a=new float[NUM_LINES]; //a 5 - 50 b 80 - 200
float[] y_c=new float[NUM_LINES];
float[] old= {0,0,0,0};
int curr=0;
void setup(){
//frameRate(1);
size(500,500);
background(20);
for(int i=0;i<NUM_LINES;i++){
curr++;
rerand(curr);
}
curr=0;
}
void draw(){
background(20);
strokeWeight(2);
translate(width/2,height/2);
for(int j=0;j<NUM_LINES;j++){
if(j!=curr%NUM_LINES){
for(int i=0;i<NUM_DOTS;i++){                                     //currently running lines
stroke(255 - i*255/NUM_DOTS+20);
point(x(t-i*FACTOR,j),y(t-i*FACTOR,j));
}
}else{
int tmp_dots=(t%TIMER)*NUM_DOTS/TIMER*2;
for(int i=0;i<tmp_dots&&i<NUM_DOTS;i++){                        //current new one (growing)
int tmp_a=tmp_dots<NUM_DOTS?255-i*255/tmp_dots+20:255-i*255/NUM_DOTS+20;

stroke(tmp_a); //stroke(tmp_a,tmp_a,tmp_a);                  // ||THIS LINE IS THE ONE I AM TALKING ABOUT ||

point(x(t-i*FACTOR,j),y(t-i*FACTOR,j));
}
}
}
for(int i=0;i<NUM_DOTS;i++){
int stroke=255-(i*255/NUM_DOTS)-(t%TIMER)*2;
stroke(stroke>=20?stroke:20);                                   //old one disappearing
point(x(t-i*FACTOR,-1),y(t-i*FACTOR,-1));
}
t++;
if(t%TIMER==0){
curr++;
rerand(curr);
}
}
void rerand(int curr){
old=x_a[curr%NUM_LINES];
old=x_c[curr%NUM_LINES];
old=y_a[curr%NUM_LINES];
old=y_c[curr%NUM_LINES];
x_a[curr%NUM_LINES]=random(25,50);
x_c[curr%NUM_LINES]=random(25,50);
y_a[curr%NUM_LINES]=random(25,50);
y_c[curr%NUM_LINES]=random(25,50);
}
float x(float ts,int j){
if(j>=0){
return sin(ts/x_a[j]) *100 + sin(ts/x_c[j])*100;
}
return sin(ts/old) *100 + sin(ts/old)*100;
}
float y(float ts,int j){
if(j>=0){
return cos(ts/y_a[j]) *100 + cos(ts/y_c[j])*100;
}
return cos(ts/old) *100 + cos(ts/old)*100;
}
``````
1 Like

When you use a single parameter for stroke() it sets the grayscale value for your lines, while using three parameters turns it into a colour. In the case of stroke(tmp_a,tmp_a,tmp_a) it shows a black, grey or white line, since all parameters are the same value.

What might be the issue is that the variable tmp_a sometimes becomes bigger than 255. By trying out the following code you could see why this would be an issue when using a single parameter for stroke():

``````int tmp_a;

void setup() {
size(500, 500);
noLoop();
background(20);
strokeWeight(2);
}

void draw() {
tmp_a = 255;
stroke(tmp_a);
line(0, 100, width, 100);    // white line
stroke(tmp_a, 0, 0);
line(0, 200, width, 200);    // red line

tmp_a = 500;
stroke(tmp_a);
line(0, 300, width, 300);    // white line won't be visible
stroke(tmp_a, 0, 0);
line(0, 400, width, 400);    // red line will be visible
}
``````

If you prevent tmp_a from becoming bigger than 255, does it solve the pixel skip problem?

2 Likes