Programming 1 Term 3 Lesson
Programming 1 Term 3 Lesson
• Red - (255,0,0)
• Green - (0.255.0)
• Blue - (0,0,255)
• Yellow - (255,255,0)
• Orange - (255,165,0)
• The graphic designer and programmer sometimes prefer to use a
different notation based on the hexadecimal RGB code, where each of
the three decimal values is converted to a two-digit hexadecimal code,
resulting in a six-digit (3×2) hexadecimal code. For example:
• Red: #FF0000
• Green: #00FF00
• Blue: #0000FF
• Yellow: #FFFF00
• Orange: #FFA500 (FF - red saturation, A5 - green saturation, 00 - blue
saturation).
• Test your color identification skills, play the color mixing game, follow
the link: https://michaelbach.de/ot/col-match/index.html
Task 1: Guess the colors
• (0, 0, 0)
• (0, 255, 0)
• (255, 0, 0)
• (255, 255, 255)
• (0, 0, 255)
• (255, 0, 255)
• (255, 255, 0)
• (197, 83, 255)
Answers
• (0, 0, 0) black
• (0, 255, 0) green
• (255, 0, 0) red
• (255, 255, 255) white
• (0, 0, 255) blue
• (255, 0, 255) pink
• (255, 255, 0) yellow
• (197, 83, 255) purple
Task 2 ”RGB"
Check if the given RGB color code is valid or not
Given three numbers R, G and B as the color code for Red, Green and Blue respectively as in the form
of RGB color code. The task is to know whether the given color code is valid or not.
RGB Format: The RGB(Red, Green, Blue) format is used to define the color of an HTML element by
specifying the R, G, B values range between 0 to 255. For example: RGB value of Red color is (255, 0,
0), Green color is (0, 255, 0), Blue color is (0, 0, 255) etc.
color: rgb(R, G, B);
• Note: The color code is valid when all numbers are in the range [0, 255].
• Examples:
• Input: R=0, G=100, B=255
Output: True
Explanation: Every color is in range [0, 255]
• Input: R=0, G=200, B=355
Output: False
Explanation: Blue is not in range [0, 255]
PIL library
Using the PIL library, you can create new images. The Image.new function takes
an RGB palette type, a tuple with the size of the new image, and a color to fill
the image with.
The following example creates a 300 x 300 pixels im image object filled with red: