In the previous lesson we've seen how to use standard colors or pick a color from the web using the hexadecimal color code. In this lesson we'll see how to make own own colors.
In the computer, the colors are made of three components red, green and blue, usually called as th RGB components. Each component takes a value between 0-255.
The following example creates a red color and fills a circle with it.
fill = color(r=255, g=0, b=0) c = circle(fill=fill, stroke='none') show(c)
You could try creating multiple circles with increasing value of red.
fill = color(r=50, g=0, b=0) c = circle(x=-100, y=0, r=50, fill=fill, stroke='none') show(c) fill = color(r=150, g=0, b=0) c = circle(x=0, y=0, r=50, fill=fill, stroke='none') show(c) fill = color(r=250, g=0, b=0) c = circle(x=100, y=0, r=50, fill=fill, stroke='none') show(c)
Sometimes it good to create colors that are slightly transparent, so that we can see what is behind when there are overlapping shapes. It also makes very interesting patterns.
In the world of computer colors, the transparency is specified by an alpha value in the range of 0 and 1. The value 1 means the color is completely transparent and value 0 means it is completely opaque and you can't see any thing behind it. A value of 0.5 means it is half transparent.
Lets try creating overlapping circles with transparent colors.
# red with half transparency c1 = color(r=255, g=0, b=0, a=0.5) shape1 = circle(x=-50, y=0, r=100, fill=c1, stroke='none') # green with half transparency c2 = color(r=0, g=255, b=0, a=0.5) shape2 = circle(x=50, y=0, r=100, fill=c2, stroke='none') show(shape1, shape2)
Write a program to draw three circles showing shades of gray with intensity 200, 150 and 100 respectively.
Can you guess how the RGB values be for creating gray shade?
Write a program to draw three circles with center at origin and with radius 50, 100 and 150. Fill them with red color with an alpha value of 0.5.