Computer Science and Engineering The Ohio State University
Color and Images
Computer Science and Engineering College of Engineering The Ohio State University
Copyright By PowCoder代写 加微信 powcoder
Colors in CSS
Use: fonts, borders, backgrounds
Provides semantic signal:
Green – go, success, complete, solution Red – stop, failure, incomplete, problem Yellow – yield, warning, attention
Helps to set mood/emotion/tone: Bright – cheerful, playful, positive Dark – somber, serious, negative Warm – energetic, alert, active
Cool – calm, tranquil, peaceful
Computer Science and Engineering The Ohio State University
Elementary Color Theory
Computer Science and Engineering The Ohio State University
Combination of
Physics (eg wavelengths in nm)
Nonspectral colors (eg pink, brown, white) require
presence of multiple wavelengths
Biology (perception of “red” vs “yellow”)
Visible spectrum: 390-700nm
Color Perception
Human eyes have 3 types of cones Respond to different wavelengths (LMS)
Color = cone response
Computer Science and Engineering The Ohio State University
Metamerism
Computer Science and Engineering The Ohio State University
Different (continuous) spectra that
stimulate our eyes in identical ways
Example: white
Spectrum 1: all wavelengths equally present
Spectrum 2: three wavelengths present, stimulating LMS cones equally
Consequence: continuous spectrum can be
projected down to 3 dimensions
Consequence: Different spectra with indistinguishable (to humans) color
Color Mixing
Computer Science and Engineering The Ohio State University
There are two ways to combine colors
1. Subtractive: Color is a filter
2. Additive: Color is a light source
Mixing = filter out both
Used for printing (& dyes, paints, gels)
Mixing = sum
Used for monitors
CMYK: Subtractive Color Mixing
Computer Science and Engineering The Ohio State University
Filters transmit different spectra
Primary colors: cyan, magenta, yellow
Mixture transmits the product of both Mix all three primaries = black
Black (K) added for quality and cost Traditional set (RYB) popular for painting
Primary yellow (transmits R & G) (absorb B)
Colors as Filters
Computer Science and Engineering The Ohio State University
Filters out (only) blue
Rosi et al., Euro. J. of Physics, 37(6), 2016
Additive Color Mixing: RGB Cube
Computer Science and Engineering The Ohio State University
primary secondary
http://www.flickr.com/photos/ethanhein/3103830956/
#fff /*white*/
#000 /*black*/
HSL Color Wheel (100% Sat.)
Computer Science and Engineering The Ohio State University
http://www.erinsowards.com/articles/2011/01/colors.php
HSL Grid for Red (ie 0,x,y)
Computer Science and Engineering The Ohio State University
(0,75%,88%)
(0,100%,50%)
(0,0%,25%)
CSS Color Values
Keywords: case-insensitive identifiers red, navy, firebrick, chocolate
RGB as decimal (0-255), percentage, or hex rgb (255,0,0) /*pure red*/
rgb (100%,0%,0%)
#f00 /*expand by repeating digit*/
HSL (Hue, Saturation, Light)
hsl (0,100%,50%) /*full bright red*/
Alpha channel (transparency): 1 is opaque! rgba (255,0,0,0.5)
hsla (0,100%,50%,1)
Hue (0-360) is angle on color wheel: 0 is red, 120 green, 240 blue
Saturation & light are both %’s
Computer Science and Engineering The Ohio State University
Color Keywords
Computer Science and Engineering The Ohio State University
Color Depth
“Depth” = # of bits in representation
8 bits : 256 different colors
24 bits : 16,777,216 different colors (eg 8 bits each for r,g,b)
Alpha may be (incorrectly) included rgba is a point in 4-dimensional space
Problem: image color depth > display
color depth
Quantization: each pixel gets closest available color (leads to banding) Dithering: add noise, which looks better!
Computer Science and Engineering The Ohio State University
Quantization of Continuous Func
Computer Science and Engineering The Ohio State University
Quantization vs Dithering
Computer Science and Engineering The Ohio State University
Quantization vs Dithering
Computer Science and Engineering The Ohio State University
www.coffeecup.com/help/articles/dither-modes-in-animation-studio/
HTML Tag Attributes
Computer Science and Engineering The Ohio State University
src: location of image file
width, height:
alt: text to show if graphic can not be displayed or seen (ie alternative) title: text to augment displayed graphic (eg tooltip)
Area in window to reserve for image Image is scaled to those dimensions These attributes affect browser flow, regardless of when/if image is displayed
Image Representation
Computer Science and Engineering The Ohio State University
Raster vs vector graphics
Compression of raster images
Lossy: better compression, lower quality image
Lossless: largest file size, best quality
Raster: stored pixel-by-pixel Vector: mathematical description
Major Formats
Computer Science and Engineering The Ohio State University
Raster graphics, lossy compression (oldest) 8 bit, basic transparency (on/off)
Frame-based animation (groan)
Good for small file size, crisp lines, logos
Raster, lossy compression
24 bit, no transparency
Good for photos, gradual gradients
Raster, lossless (but still often good) compression Variable depth, full alpha transparency
Good replacement for GIF (but no animation)
vector graphics (newest)
Good for crisp lines, simple logos, graphs
Scaling Images
Vector graphics scale perfectly
Raster images should be pre-scaled
Width (height) attributes of image tag should match actual width (height) of image
Computer Science and Engineering The Ohio State University
Alternative: CSS
Computer Science and Engineering The Ohio State University
.deleteButton {
background:
-webkit-linear-gradient(top, #be6868 0%, #941b17 50%,
#880d07 50%, #be483c 100%); border: 3px solid #000; color: #fff;
cursor: pointer; font-size: 15pt;
padding: 10px 34px; text-shadow: 0 -1px 0 #000; border-radius: 13px; box-shadow: 0 1px 0 #454545;
Recall: Blocks, Inline, and Flow
Computer Science and Engineering The Ohio State University
paragraph heading
Floating: Remove From Flow
Computer Science and Engineering The Ohio State University
Floating: Overlays Block
Computer Science and Engineering The Ohio State University
float: left
codepen.io/cse3901/pen/bLYdLz
Problem: Blocks Below
Computer Science and Engineering The Ohio State University
Floating element may be taller than
containing element
May be undesirable, eg for footer that
should be below everything including
Solution: clear
Computer Science and Engineering The Ohio State University
Styling for block element after float
#footer { clear: left; }
Requires that side to be clear of
id=”footer”
CSS: Grid Layout
Computer Science and Engineering The Ohio State University
Display property for arranging elements
in a 2D grid
Parent element is the grid container
Direct children are the grid items
Style with CSS property (display: grid) Set number/size of rows/columns
Set gap between rows/columns
Set alignment, justification, placement
One item can be sized/placed to a grid are a (ie a rectangular subgrid)
Grid Layout: Example
Computer Science and Engineering The Ohio State University
.wrapper {
display: grid; grid-template-columns: 1fr 2fr 2fr; grid-template-rows: repeat(4,20px); grid-gap: 20px;
…
codepen.io/cse3901/pen/aqVNJN
Grid Areas
.top { grid-area: tp; }
.sidebar { grid-area: sd; }
#footer { grid-area: ft; }
Computer Science and Engineering The Ohio State University
.wrapper {
display: grid;
grid-template-columns: 1fr 2fr 2fr;
grid-template-areas:
“tp tp tp” “sd. .” “sd. .” “sd ft ft”;
codepen.io/cse3901/pen/oEoKXV
CSS Units for Size
“Absolute” units (but browsers cheat) in, cm, mm
pt (point) = 1/72 inch, pc (pica) = 12 pts Absolute (for a given resolution)
px (pixels)
Relative to current element’s font em = width of ‘m’ in element’s font
ex = height of ‘x’ in element’s font Relative to parent (or ancestor) size
%, rem (like em, but with root’s font)
Standard advice for fonts: Prefer relative units
Computer Science and Engineering The Ohio State University
Aside: The Problem with Pixels
Computer Science and Engineering The Ohio State University
Historically, pixel size determined by hardware (ie screen resolution)
ppi: “pixels per inch”
Problems using px unit:
Different resolutions = different size of px
Different devices = different view distances Solution: W3C’s “reference pixel” (optics)
0.0213 degrees
Fonts: Concepts
Fonts are a key part of visual design Serious, technical, whimsical, friendly…
Font family (should be “typeface”) Arial, Helvetica, Times, Courier, Palatino, Garamond, Verdana, Tahoma, Lucida,…
Font = typeface + weight, slant, etc
Computer Science and Engineering The Ohio State University
Normal, bold, light (CSS: font-style) Normal, oblique, italic (CSS: font-weight)
Properties and Metrics
Computer Science and Engineering The Ohio State University
Serif vs sans-serif
Kerning: proportional vs monospace
Size = ascent + descent (usually)
m-width, x-height
Whitespace
Computer Science and Engineering The Ohio State University
Critical for aesthetics, readability
Margins around body text, headings
Space from baseline to baseline
CSS: line-height
Larger x-height = easier to read
But larger x-height also requires more line spacing
“Music is the silence between the notes”
Font Families
De gustibus non est disputandum
Nevertheless, some common opinions
Less is more: Use fewer fonts/sizes
Cohesive appearance
Helvetica/Arial: clean but ubiquitous
They are identical / completely different Times is hard to read (on a monitor)
Better for print
Comic Sans is for 12-year-olds and owners of NBA basketball teams
Computer Science and Engineering The Ohio State University
Identical & Completely Different
Computer Science and Engineering The Ohio State University
Fallback Fonts
Not sure what fonts host OS will have
CSS font-family: List alternatives in decreasing
order of preference
font-family: Helvetica, Arial,
“Liberation Sans”, sans-serif;
Always end with one of 5 generic fonts: sans-serif (Arial?)example
OS (and browser) determine which font family
each generic actually maps to
serif (Times New Roman?) example monospace (Courier New?)example cursive (Comic Sans?) example fantasy (Impact?) example
Computer Science and Engineering The Ohio State University
CSS3: Web Fonts @font-face
Computer Science and Engineering The Ohio State University
Looks like a selector, but is a “directive”
@font-face {
font-family: HandWriting; src: url(‘PAGSCapture.ttf’);
Font family then available in rest of CSS
p { font-family: HandWriting; … }
User agent dynamically downloads font
Different syntaxes for font files
.ttf, .otf, .eot, .woff, .svg, …
Beware: copyright issues! See fonts.google.com
Colors: RGB vs HSL
Computer Science and Engineering The Ohio State University
Formats jpeg, png, gif, svg Tradeoffs of size, quality, features
Floating elements
Removed from flow, layered on top
Fallback fonts to account for uncertainty Web fonts for dynamic loading
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com