David Stein, 7 Weeks of Making - Day 1, July 6th, 2022
#colors
I do not understand how artists create such wonderful color palettes. How the great painters such as Monet and Van Gogh without the aid of computers were able to select and mix colors using only their eyes and paint?
By Claude Monet - 1. Unknown source2. 2QE-QPkJp0h94g at Google Arts & Culture, Public Domain, https://commons.wikimedia.org/w/index.php?curid=2326984
By Vincent van Gogh - mwF3N6F_RfJ4_w at Google Cultural Institute maximum zoom level, Public Domain, https://commons.wikimedia.org/w/index.php?curid=21977797
It is going to take a huge amount of work and practice to learn how to manually create a palette of colors, but in the meantime, I have learned a trick using simple code to create a palette by sampling colors from real pictures.
The following sketch will load an image and select random pixels within the image for the purpose of choosing a colors. The resulting technique will produce a large variety of colors that will all look good together.
We are using a photo of cows from my favorite cheese farm in Hardwick, MA. It is our expectation that the resulting artwork will use the colors in the same proportion as the photo to the right.
David Stein, Cows at Roundtable Farm, Hardwick MA
My Editor of choice for P5 is Microsoft Visual Studio Code with Sam Lavigne's p5.vscode which includes simple steps to create the supporting files as well as the Live Server Extension to run my sketches. (An alternative choice would be to use the P5 Editor)
Once the p5.vscode plugin is installed in MSVC, the following steps create a p5 project:
To sample colors from an image, I preload the image by placing it in the P5 preload() function. If this function exists, P5 will automatically call it when the sketch starts and load all of the images before the P5 sketch starts calling the draw() function.
Once the image is loaded, it is placed in the img variable which has methods to get a pixel as well as to examine the height and width of the image.
let img;
function preload() {
img = loadImage('assets/CowsAtMarlos.png');
}
// later within a routine for drawing, random color from image
let color = img.get(random(img.width),random(img.height));