Skip to content

Create random palettes of colors that will go well together

Few days ago I was following a thread on twitter by Vegard Myklebust. He was explaining an easy way to create palettes of five different colors picked randomly that will go well together.

This techniques works really well and it’s super easy so I decided to create a small sketch in Processing to generate infinite palettes.

This is the original thread

Rules for picking colors

These are the simple rules to follow:

  1. Work in HSB (hue, saturation and brightness) color space and not in RGB (red, green and blue).
  2. The secret is to consider the hue value around a circle so the hue is the angle of the wheel. The values are between 0 and 360. First of all, we have to pick a number randomly.
  3. Let’s pick saturation and brightness values randomly as well (usually between 0 and 100).
  4. Now we have our first color which is positioned at the centre of our palette.
  5. Choose another random number. This techniques works best if we pick between 0 and 180. Then we have to add and subtract this value to the original hue.
  6. Now we have the second and fourth color.
  7. Add and subtract again the last number we chose to the second and fourth color.
  8. To have perfect results, set saturation and brightness randomly for every color.

The processing sketch

 * Create a palette of 5 random colours with a techniques explained
 * here
 * Sketch made by Federico Pepe
 * 27.05.2020

color palette[] = new color[5];

void setup() {
  size(540, 540);
  colorMode(HSB, 360, 100, 100);

void draw() {

void mousePressed() {

void keyPressed() {
  if(key == 's') {

void createPalette() {
  int hue = round(random(360));
  int r1  = round(random(180));
  palette[0] = color(hue - (r1*2), round(random(100)), round(random(100)));
  palette[1] = color(hue - r1, round(random(100)), round(random(100)));
  palette[2] = color(hue, round(random(100)), round(random(100)));
  palette[3] = color(hue + r1, round(random(100)), round(random(100)));
  palette[4] = color(hue + (r1*2), round(random(100)), round(random(100)));
  println("#" + hex(palette[0], 6), 
    "#" + hex(palette[1], 6), 
    "#" + hex(palette[2], 6), 
    "#" + hex(palette[3], 6), 
    "#" + hex(palette[4], 6));

void drawPalette() {
  rect(0, 0, width/5, height);
  rect(width/5, 0, width/5, height);
  rect(width/5*2, 0, width/5, height);
  rect(width/5*3, 0, width/5, height);
  rect(width/5*4, 0, width/5, height);

The code is quite simple: I created two functions to create and draw the palette on the screen. Colors are saved in an array.

Everytime you click the mouse a new palette is generated. By pressing s on the keyboard the palette is saved as .png file in the sketch’s folder.

The color values are printed in the console as hexadecimal values.

Here’s some examples:

Will online courses take over universities?

I signed up on Coursera exactly one year ago. Even though I never enjoyed watching video tutorials on YouTube and following on-line courses on platforms like iTunes U, I was curious about attending an on-line class. I was eager to start: during the first week I signed up to a lot of different courses. At that time I was quite busy with my job so I knew that I couldn’t watch all the video lectures and do all the assignments but my main goal was to understand how the whole system worked and find out if I could use it to improve my teaching skills.

The only course that I actually completed at the beginning was “Introduction to Digital Sound Design” by professor Steve Emerett from Emory University. My background helped me a lot so it hasn’t been difficult to get a distinction on my statement of accomplishment at the end of the course (on Coursera you can get a Verified Certificate if you join the Signature Track which is available for some courses starting at $49.00).

After that first experiment I didn’t attend other courses but I kept myself in the loop and I enjoyed following the growing discussion about on-line education.

Four on the floor

At the end of the summer I felt that I needed to learn something new so I started browsing Coursera again and decided to commit myself to complete four different courses.

The first was Berklee College of Music’s “Introduction to Music Production“: as you probably guessed, this subject isn’t new for me but I was excited to attend a course from one of the world’s most renowned music school.

California Institute of Arts’ “Introduction to Programming for Musicians and Digital Artists” has been my second choice. Although I’ve been following Ge Wang’s work for a long time now, I never had the chance to learn ChucK (the programming language that he developed). When I saw this course I thought that this was the chance to fill this gap.

The third course that I attended has been: “Digital Signal Processing” from the École Polytechnique Fédérale de Lausanne. To be honest I quit after the first week. I was really looking forward to learn something but when I started I already knew that I couldn’t cope with all the math’s problems (math has always been my weak point).

The fourth and last course: “An Introduction to Marketing” from University of Pennsylvania. I know that this course is completely unrelated with the others but I also worked as marketing manager so I thought that this could be very helpful.

The pros and the cons

Attending an on-line course has a lot of pros: you can study what you want whenever you want (actually this is also one of the cons: do you know the term «procrastination»?). You can always access the video lectures and even play them at double speed if you haven’t enough time (I did this a lot!). One thing that I never used were the discussion boards, even though many students found them extremely helpful. I definitely learned A LOT of new things and I think I’ve improved my teaching skills by watching those lectures.

Obviously there are some cons too… from a teacher perspective, you can’t be a hundred percent sure that all the assignment are made by the students. I actually caught a lot of my peers copy and paste content from wikipedia and other websites. From a learner point of view it has been great to be part of these classes with thousands of students from around the globe but I really missed the “human factor”: discussing an assignment or a lecture behind a monitor is not the same as doing it in front of a cup of coffee/tea. I also got angry  once because I thought that my assignment weren’t reviewed following the course’s guidelines (and I’m convinced that I’ve been downgraded for that reason).

If you want to join one an online course, you have to be really commit to complete it because even if no one is looking at what you do, watching the video lectures and doing the assignments take the same amount of time that doing those things in a class (and, probably, you are doing an on-line course because you don’t have time to do it).


I don’t think that online courses will take over (and kill) universities. The institutions that will embrace these platforms and develop new content for their curricula will take a lot of advantages from it. My guess is that, in the future, students will prefer an enhanced learning experience instead of “traditional” lectures. Many new platforms were born in the last months and the number of courses is growing constantly. This is the right time to sign up on Coursera, EdX, FutureLearn, etc. and try to learn something new.