Request or advice: Noise brush

We’ve got GradientBrush, and we’ve got ImageBrush… i’d like to have a ‘noise brush’ too… like a solid colour brush but that painted with random noise around the chosen colour. I think the easiest solution would be to generate a noise bitmap in an image editor, and make sure that it can be tiled reasonably nicely, then just use an image brush… but i’d like to code one to generate the noise specially.

I guess though, that using ‘setPixel’ would be ridiculously inefficient. Any suggestions on how it may be done?

Yes, I guess doing it as an image brush would work pretty well. Instead of using setpixel, you’d use the lockPixelDataReadWrite method to get the bits, and then use the PixelRGB class to help set the colours - have a search for places where that’s been used in the juce code to get more of an idea how it works.

i’m puzzled!

In the Brush class, the functions i need to define provide me with a LowLevelGraphicsContext reference… but i need to get the image to draw to. How can i get that?

[EDIT] oh, hang on… i get it… i make my own image, right?

yeah, you make your own image…

i tried a bunch of things out, and by far the quickest method was an implementation that just used an ImageBrush to paint a rectangle using a noise source image. The only downside is that there’s no direct control over the noise’s colour - it fills a rectangle with the chosen colour, and then the noiseStrength parameter controls the opacity of the noise overlaid. It works well enough though :slight_smile: although it’s not a brush.

Thanks for your advice