Any idea how to make this in processing p5.js?

Hi Jarin7,

You can use abs(cos()) function to get something similar.

1 Like

Do you mean, draw that exact shape with bars, or should it be based on something – like a particular curve / wave, or probability distribution?

Or hooked up to something, like audio?

Or visualizing a list of data entries like a bar graph…?

Yeah, it should look “something” like this. It’s 1 period of two-way regulated sinusoid. y = 0 at (0,0),(50,0)(100,0) Lines should be 1 pixel big and between lines there should be 1 pixel gap. It has nothing to do with audio. Sorry for not specifing closer earlier, thanks for any idea.

It sounds like you want to draw a series of rectangles, starting rom 0 and going to x – use a for loop for that, and rect().

Then, you want to change the height of each rectangle according to a sine wave function. Use sin() for that.

…in fact… you might want to take a look at the Processing short example for using sin

2 Likes

That is if you want to use Processing. If you want to use p5.js, you can go to https://p5js.org/reference/ to find the equivalent functions.

2 Likes

Oops! That’s right – I missed that it was p5.js.

https://p5js.org/reference/#/p5/sin

A guide on how to sin, you say? :smiling_imp:

1 Like

Thanks! That helped me a lot but don’t you know how to make it look exactly like in the picture?

https://editor.p5js.org/kll/sketches/ByamrNy3m

2 Likes

Thanks a lot! I really appreciate it.