Coloring between lines in processing

After drawing a few lines using the sin function, I wondered how you would fill the gap between each of the two lines

float a = 0.0;
float inc = TWO_PI/25.0;

for(int i=0; i<100; i=i+4) {
  line(i, 50, i, 50+sin(a)*40.0);
  a = a + inc;
}

      

+3


source to share


2 answers


Decision

@maskacovnik will work. You can also be a little cheeky and just draw the shape:

float a = 0.0;
float inc = TWO_PI/25.0;
beginShape();
for(int i=0; i<=100; i=i+4) {
  vertex(i, 50+sin(a)*40.0);
  a = a + inc;
}
endShape();

      

You can run the preview here (using js):



function setup() {
  createCanvas(100,100);
  background(192);
  var a = 0.0;
  var inc = TWO_PI/25.0;
  beginShape();
  for(var i=0; i<=100; i=i+4) {
    vertex(i, 50+sin(a)*40.0);
    a = a + inc;
  }
  endShape();
}
      

<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.6/p5.min.js"></script>
      

Run codeHide result


+4


source


I would fill it in like this:

(This is pseudocode, you did not specify the language)

EDIT like @GeorgeProfenza seen in the comment below you have specified the language



float a = 0.0;
float inc = TWO_PI/100.0; //4x decreased inc

for(int i=0; i<100; i=i+1) { //4x increased count of looping
  if(i%4==0){
      stroke(0);
  }else{
      stroke(255,0,0);
  }
  line(i, 50, i, 50+sin(a)*40.0);
  a = a + inc;
}

      

I would draw lines close to each other and every fourth would be black

+1


source







All Articles