Color can be a great way to make your artwork more interesting. If you've used tools such as Photoshop before, you may know that there are different systems to describe a color. There is CMYK, LAB, HSB, HSV, RGB, XYZ, and so on. In Processing, you can use the RGB and HSB color modes to change the background, or set the fill or stroke of a shape. In this recipe, we'll explore how you can do this.
The first thing we'll do is declare a color variable named c
, right before the setup()
function. We'll set its value to a random color.
color c; void setup() { size( 640, 480 ); smooth(); c = color( random( 255 ), random( 255 ), random( 255 ) ); }
The second thing we'll do is to draw a rectangle with a gradient from black to white. This piece of code draws 255 rectangles, each with a different fill. This is the first piece of code that goes inside the draw()
function.
Void draw() { colorMode( RGB, 255 ); background( 255 ); // grayscale noStroke(); ...