A color that can be represented on a computer screen is represented by three values:
Color is a three-dimensional object!
In HTML: rgb(red, green, blue)
red
, green
, blue
are integers from 0 to 255.Manipulation of r, g, b
color values is not intuitive
red
, green
, blue
have natural physical interpretationsred
, green
, blue
do not have natural perceptual interpretations (at least to me)Question. What are the RGB values of the color above?
Used predefined colors:
<div class="flag">
<div style="background-color: red;" class="stripe"></div>
<div style="background-color: orange;" class="stripe"></div>
<div style="background-color: yellow;" class="stripe"></div>
<div style="background-color: green;" class="stripe"></div>
<div style="background-color: blue;" class="stripe"></div>
<div style="background-color: purple;" class="stripe"></div>
</div>
Question. What do you think of HTML’s color choices?
Make a rainbow with 8 stripes!
Dowload rainbow-eight.html
to get started, use RGB color picker
A color is a 3D object: interpret RGB values as coordinates of points in 3D space
Perceptual Dimensions:
Can define mathematical relationship between HSL and RGB coordinates
RGB:
color: rgb(red, green, blue);
red
, green
, blue
are integers from 0 to 255HSL:
color: hsl(hue, saturation, lightness);
hue
is a number (degress), nominally from 0 to 359saturation
and lightness
are percentages (0%
to 100%
)There are infinitely many ways to represent colors!
Others made for differnt hardware/aspects of perception
No all people have all three types of color receptors!
Universal design: make graphical that are visually distinctive
Tool: Firefox color vision simulation
And now
With JavaScript we can
Creating and adding elements to a site!
hello-javascript.zip
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Page Title</title>
<script src="hello.js"></script>
<script>
...javascript code here...
</script>
</head>
</html>
hello.js
Get an element in the document (selector
is like CSS selector)
const someElement document.querySelector("selector");
first element in document matching selector is returned
Create an element (some-tag
is desired tag of element)
let myElement = document.createElement("some-tag");
Add text to element
myElement.textContent = "some text";
Add element as child of another
someElement.appendChild(myElement);
If someElement
is an element, we can…
set an id
someElement.id = "some-id";
add a class
someElement.classList.add("some-class");
add a style
someElement.style.backgroundColor = "rgb(200,200,200)";
Let’s style our example site!