Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Final Exam – rest of class scheduleFinal Exam – rest of class schedule Where we areWhere we are 2D Graphics2D Graphics Graphics in MatlabGraphics in Matlab Game of LifeGame of Life
Spring R. Smith - University of St Thomas - Minnesota Where we Are Using Matlab to do arithmeticUsing Matlab to do arithmetic Math on Scalars and vectorsMath on Scalars and vectors Writing scripts and functionsWriting scripts and functions Control Structures: if, while, forControl Structures: if, while, for Strings and TextStrings and Text Lab 5Lab 5
Spring R. Smith - University of St Thomas - Minnesota 2D Graphics – Black & White How do we represent a picture with numbers?How do we represent a picture with numbers? Basic version: bitmapped graphicBasic version: bitmapped graphic –2D matrix, each element is binary: 0=white, 1=black Grayscale graphicsGrayscale graphics –2D matrix, each element gives the intensity of the image –Direction varies with implementation Is white > black, or black > white?Is white > black, or black > white? –Representation varies Integer range from 0-255, 32767, etc.Integer range from 0-255, 32767, etc. Rational range: 0.0 -> 1.0 or alternativesRational range: 0.0 -> 1.0 or alternatives Matlab likes the rational rangeMatlab likes the rational range –Also handles grayscale
Spring R. Smith - University of St Thomas - Minnesota 2D Graphics - Color Questions:Questions: Which ‘primary’ colors do the numbers represent?Which ‘primary’ colors do the numbers represent? –Additive vs Subtractive Colors What numbers do we provide?What numbers do we provide? Do we use shortcuts to reduce the image size?Do we use shortcuts to reduce the image size?
Spring R. Smith - University of St Thomas - Minnesota Additive - Color Models - Subtractive
Spring R. Smith - University of St Thomas - Minnesota Three Coloring “Formats” Gray scale (bit-mapped as a subset)Gray scale (bit-mapped as a subset) “True” Color – Hi-res Color“True” Color – Hi-res Color –What does 24-bit color mean? –What does 32-bit color mean? “Mapped” Color“Mapped” Color –A way to provide colors with fewer bits per pixel –The color of a pixel is an “index” into a matrix of larger color values – either RGB or CMY –Do you see a disadvantage here?
Spring R. Smith - University of St Thomas - Minnesota Graphics in Matlab Color intensities as fractional amounts 0->1Color intensities as fractional amounts 0->1 Integer intensities as color map offsetsInteger intensities as color map offsets “image(var)” displays 2D matrix as image“image(var)” displays 2D matrix as image “imagesc(var)” scales the matrix values to fit inside the current color map. Example maps:“imagesc(var)” scales the matrix values to fit inside the current color map. Example maps: –mono: spring, summer, autumn, winter, bone, copper, gray –color: HSV, Jet, Hot, Cool, Lines
Spring R. Smith - University of St Thomas - Minnesota Conway’s Game of Life Played on a 2D bit mapped matrixPlayed on a 2D bit mapped matrix –“Living” is filled in, “Dead” is blank (white) Rules for a square’s survivalRules for a square’s survival –If living and next to 2 or 3 live cells, keep living, otherwise die –If dead and next to 3 live cells, start living Life3 functionLife3 function Rand(size) – yields 2d matrix of that sizeRand(size) – yields 2d matrix of that size 0.6 > rand(size) – bit map that’s not too full0.6 > rand(size) – bit map that’s not too full
Spring R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.