We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Is there a way to randomly select blendmode? I tried replacing blendMode(DARKEST) with a variable, but that didn't seem to work. Console log spits out a random blendmode, but when I try to use it it fails.
var blendModes = ['BLEND', 'ADD', 'DARKEST', 'ADD', 'DIFFERENCE ', 'EXCLUSION', 'MULTIPLY', 'SCREEN', 'REPLACE', 'OVERLAY', 'HARD_LIGHT', 'SOFT_LIGHT', 'DODGE', 'BURN']; //https://p5js.org/reference/#/p5/blendMode
var randBlendmode = blendModes[Math.floor(Math.random() * blendModes.length)]; console.log(randBlendmode);
blendMode(randBlendmode);
Test: https://codepen.io/mskogly/pen/ZojbYe?editors=0111 (the blendmode line is commented out)
Answers
It's not pretty, but it'll do it.
You might luck out... try
println(BLEND)
(and all the other modes) and see if that is actually a value. Then you could tryblendMode(0);
, maybe. Maybe.I think your problem is that you're creating Strings rather than using the constants?
eg. this seems to work - got an error without using constants inside setup()
creating an if would solve it. not as elegant, but works :)
@mskogly actually using the right constants solves it! ;-)
To underscore the solution:
Wrong -- don't use strings:
Right -- do use the names of built-in constant variables: