Skip to content
Advertisement

How to go through two colours with sine wave in p5.js

I know how to do it with black and white

JavaScript
JavaScript

example

I would like it to be purple instead of black but I can’t do it. I would like to achieve something like this.

Advertisement

Answer

I dont know much about p5.js. But simple googling and would offer this solution

JavaScript
JavaScript

With lerp color you could create implementation that supports even more colors.

JavaScript

With some refactoring and more work this could support arbitrary number of colors. You could have a sin go through the entire rainbow.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement