Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements Comparison...

96
Computer Science 1 Week 10

Transcript of Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements Comparison...

Page 1: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Computer Science 1Week 10

Page 2: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

This Week ...This Week ...

• QBasic If StatementsQBasic If Statements Comparison operatorsComparison operators Logical operatorsLogical operators

• Computer ConceptsComputer Concepts GraphicsGraphics SoundSound VideoVideo

Page 3: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.
Page 4: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Comparison Comparison OperatorsOperators

Comparing Data to DataComparing Data to Data

Page 5: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Review:Review:Numeric OperatorsNumeric Operators

OperatorOperator NameName

^̂ ExponentExponent

** MultiplicationMultiplication

// DivisionDivision

++ AdditionAddition

-- Subtraction & Unary MinusSubtraction & Unary Minus

Page 6: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Comparison Operator Comparison Operator OverviewOverview

• Used to Used to comparecompare two data items two data items Equal, UnequalEqual, Unequal Greater than, Less thanGreater than, Less than

• Can be used with Can be used with bothboth numbers numbers and stringsand strings

• Essential for writing complex Essential for writing complex expressions in programsexpressions in programs

Page 7: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Comparison Comparison OperatorsOperators

OperatorOperator NameName

= Equal To

<> Not Equal To

> Greater Than

>= Greater Than or Equal

< Less Than

<= Less Than or Equal

Page 8: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Number ExamplesNumber Examples

1 = 4

24 <> 31

11 < 10

100 >= 100

False

True

False

True

Page 9: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

ASCII ChartASCII ChartReviewReview

NULNUL SOLSOL STXSTX ETXETX EOTEOT ENQENQ ACKACK BELBEL BSBS HTHT LFLF VTVT FFFF CRCR SOSO SISI

DLEDLE CD1CD1 DC2DC2 DC3DC3 DC4DC4 NAKNAK SYNSYN ETBETB CANCAN EMEM SUBSUB ESCESC FSFS GSGS RSRS USUS

spsp !! "" ## $$ %% && '' (( )) ** ++ ,, -- .. //

00 11 22 33 44 55 66 77 88 99 :: ;; << == >> ??

@@ AA BB CC DD EE FF GG HH II JJ KK LL MM NN OO

PP QQ RR SS TT UU VV WW XX YY ZZ [[ \\ ]] ^̂ __

`̀ aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo

pp qq rr ss tt uu vv ww xx yy zz {{ || }} ~~ DELDEL

Page 10: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Comparing LettersComparing Letters

AA 0100000101000001 6565

BB 0100001001000010 6666

CC 0100001101000011 6767

DD 0100010001000100 6868

EE 0100010101000101 6969

FF 0100011001000110 7070

aa 0110000101100001 9797

bb 0110001001100010 9898

cc 0110001101100011 9999

dd 0110010001100100 100100

ee 0110010101100101 101101

ff 0110011001100110 102102

"A" < "a"

ASCII Value

Page 11: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Letter ExamplesLetter Examples

"a" = "A"

"a" > "A"

"abC" < "abc"

"dog" <> "cat"

False

True

True

True

Page 12: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.
Page 13: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

LogicalLogicalOperatorsOperators

Creating Expressive LogicCreating Expressive Logic

Page 14: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Logical OperatorsLogical Operators

OperatorOperator NameName

AND Logical And

OR Logical Or

XOR Logical Exclusive Or

NOT Unary Logical Negation

Page 15: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Logical OperatorsLogical Operators

• OR OperatorOR Operator true if true if eithereither operand is operand is truetrue

• AND OperatorAND Operator true only if true only if bothboth operands are operands are truetrue

• NOT OperatorNOT Operator true if the operand is true if the operand is falsefalse

Page 16: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

AND ExampleAND Example

1 < 2 AND 10 < 40

Result: True

True True

Page 17: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

AND Example 2AND Example 2

1 < 2 AND 12 < 10

Result: False

True False

Page 18: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

OR ExampleOR Example

1 < 2 OR 10 < 40

Result: True

True True

Page 19: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

OR Example 2OR Example 2

1 < 2 OR 12 < 10

True False

Result: True

Page 20: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

OR Example 3OR Example 3

10 < 2 OR 12 < 10

False False

Result: False

Page 21: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

NOT ExampleNOT Example

NOT 1 < 2

Result: False

True

Page 22: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

NOT ExampleNOT Example

NOT 1 = 2

Result: True

False

Page 23: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

ExamplesExamples

1 < 3 AND 10 < 40

1 = 3 AND 10 < 40

NOT 1 = 2

1 > 3 OR 30 < 20

True

False

True

False

Page 24: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

QBasic Precedence QBasic Precedence LevelsLevels

8 ^7 -6 * /5 + -4 = <> > >= < <=3 NOT2 AND1 OR XOR

Highest Level

Lowest Level

Page 25: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Calculate The ResultCalculate The Result

2 = 4 OR 1 > 2 AND 5 > 4 OR 1 < 3

False OR False AND True OR True

False OR False OR True

False OR True

True

Page 26: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Calculate The Result 2Calculate The Result 2

NOT 1 < 4 AND 5 > 4 OR NOT 1 > 4

NOT True AND True OR NOT False

False AND True OR True

False OR True

True

Page 27: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.
Page 28: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

QBasicQBasicIf StatementsIf Statements

Allowing QBasic to Make DecisionsAllowing QBasic to Make Decisions

Page 29: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

If StatementIf Statement

• This statement ...This statement ... executes statements if the executes statements if the

expression is expression is truetrue can also contain a false branchcan also contain a false branch

• Uses Uses blocksblocks of statements of statements• Found in virtually every Found in virtually every

programming languageprogramming language

Page 30: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

IF Condition THEN

Statements

END IF

Basic SyntaxBasic Syntax

Either True or False

Multiple statements

Page 31: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

LET Age = 22

IF Age >= 21 THEN

PRINT “Older than 21"

END IF

ExampleExample

Page 32: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Older than 21!

ExampleExampleOutputOutput

Page 33: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

LET Age = 18

IF Age >= 21 THEN

PRINT "Older than 21!"

END IF

Example 2Example 2

Page 34: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Example 2Example 2OutputOutput

Nothing. The Print Statement is

skipped

Page 35: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

LET Age = 18

IF Age >= 21 THEN

PRINT "Older than 21!"

END IF

Example 2: Example 2: Please NotePlease Note

Only executed if true

Page 36: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

INPUT "Enter 1 to 10", Num

IF Num < 1 OR Num > 10 THEN PRINT "Sorry!"

PRINT Num; " is invalid!"END IF

Example 3Example 3

Page 37: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Enter 1 to 10: 13

Sorry!

13 is invalid!

Example 3Example 3OutputOutput

Page 38: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

DIM Answer AS STRING

PRINT "Do you love programming?"

INPUT "y or n: ", Answer

IF Answer = "y" OR Answer = "Y" THEN

PRINT "Most excellent!"END IF

Example 4Example 4

Page 39: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Do you love programming?

y or n: Y

Most excellent!

Example 4Example 4OutputOutput

Page 40: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

The Else ClauseThe Else Clause

• Sometimes you need an alternative Sometimes you need an alternative branch in your programbranch in your program

• Used to process statements:Used to process statements: only if the condition is only if the condition is FalseFalse the "else" keyword separates the two blocksthe "else" keyword separates the two blocks

Page 41: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

IF Condition THEN

Statements-1

ELSE

Statements-2

END IF

IFIF Statement Syntax Statement Syntax

Processed if the Condition is false

Page 42: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

INPUT "Your Age: ", Age

IF Age >= 21 THEN

PRINT "Kegger! :)"

ELSE

PRINT "Milk. :("

END IF

Else ExampleElse Example

Page 43: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Your Age: 22

Kegger! :)

Else ExampleElse ExampleOutputOutput

Page 44: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Your Age: 18

Milk. :(

Else ExampleElse ExampleOutputOutput

Page 45: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

INPUT "Your age: ", Age

IF Age >= 1 AND Age <= 100 THEN LET Days = Age * 365

PRINT "Days lived:"; Days

ELSE

PRINT "Invalid Age!"

END IF

Else Example 2Else Example 2

Page 46: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Your age: 20

Days lived: 7300

Example 2Example 2OutputOutput

Page 47: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Your age: 300

Invalid Age!

Example 2Example 2Output 2Output 2

Page 48: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

QBasic LabQBasic Lab

If Statements If Statements

Page 49: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Lab: Lab: Furry OlympicsFurry Olympics

• Overview:Overview: its the Furry Olympicsits the Furry Olympics use the If Statementuse the If Statement

• Objectives:Objectives: input scores from three Judgesinput scores from three Judges determine if the athlete qualifiesdetermine if the athlete qualifies

Page 50: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Remember ...Remember ...

• Turn in your program Turn in your program && your outputs your outputs to Lab8 in SacCT to Lab8 in SacCT

• You must do your own workYou must do your own work• If you do not turn in your program, If you do not turn in your program,

you will you will notnot get credit! get credit!

Page 51: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.
Page 52: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

BitmapBitmapGraphicsGraphics

The basics of picturesThe basics of pictures

Page 53: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Bitmap BasicsBitmap Basics

• BitmapBitmap graphic graphic also known as a “raster graphic”also known as a “raster graphic” the most common class of graphicthe most common class of graphic

• Consists of Consists of littlelittle dots called dots called pixelspixels these are arranged in a gridthese are arranged in a grid the color of each pixel is a binary numberthe color of each pixel is a binary number

Page 54: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

A Close Look at A Close Look at PixelsPixels

Page 55: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

How Colors Are How Colors Are RepresentedRepresented

• Colors are represented usingColors are represented using RedRed--GreenGreen--Blue Blue levelslevels Hue-Saturation-IntensityHue-Saturation-Intensity

• Stored as a binary numberStored as a binary number as the actual as the actual RRGGBB value value a color code - a color code - palette indexpalette index

Page 56: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Color DepthColor Depth

• Color DepthColor Depth refers to the refers to the totaltotal number of colors in an image number of colors in an image the more bits, the more colorsthe more bits, the more colors

• Bits Per PixelBits Per Pixel used to describe color depthused to describe color depth usually a power of 2 number – e.g. 2, 4, 16, 32usually a power of 2 number – e.g. 2, 4, 16, 32

Page 57: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.
Page 58: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

ColorColorPalettesPalettes

Representing Colors By CodesRepresenting Colors By Codes

Page 59: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Color PalettesColor Palettes

• RRGGBB is not always used is not always used maintain a small file sizemaintain a small file size reduce memory requirementsreduce memory requirements

• Color PaletteColor Palette basically a lookup table for colorsbasically a lookup table for colors similar to "color by numbers"similar to "color by numbers" table has table has RedRed--GreenGreen--Blue Blue valuesvalues

Page 60: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Color PalettesColor Palettes

Actual valueActual value

Page 61: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Classifications of Classifications of Color ImagesColor Images

• Grayscale paletteGrayscale palette usually 256 shades of grayusually 256 shades of gray great for black-and-white picturesgreat for black-and-white pictures

• MonochromeMonochrome 2 colors – usually black and white2 colors – usually black and white 1 bit per pixel – allowing 8 pixels per byte1 bit per pixel – allowing 8 pixels per byte used by early computers – e.g. Xerox Starused by early computers – e.g. Xerox Star

Page 62: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Monochrome ExampleMonochrome Example

Page 63: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Classifications of Classifications of Color ImagesColor Images

• 16 Color16 Color 4 bits per pixel – allowing two pixels per byte4 bits per pixel – allowing two pixels per byte used by 80's computers – e.g. Commodore 64used by 80's computers – e.g. Commodore 64

• 256 Color256 Color 8 bits per pixel 8 bits per pixel usually used with a color paletteusually used with a color palette

Page 64: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Classifications of Classifications of Color ImagesColor Images

• High ColorHigh Color 16 bits per pixel – 65,536 colors16 bits per pixel – 65,536 colors also tends to use a palette – not alwaysalso tends to use a palette – not always

• True ColorTrue Color 3 or more bytes3 or more bytes 24 bit = 3 bytes = 16.7 million colors24 bit = 3 bytes = 16.7 million colors RedRed--GreenGreen--BlueBlue values used values used

Page 65: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Changing the Color Changing the Color DepthDepth

• Dithering Dithering uses patterns of two or more colorsuses patterns of two or more colors produce the illusion of additional colorsproduce the illusion of additional colors relies on the eye to blend colors and shapesrelies on the eye to blend colors and shapes

• Color MappingColor Mapping find the closest matching colorfind the closest matching color works well for chartsworks well for charts

Page 66: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

I am intrue color!

I am intrue color!

Page 67: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

I'm only in 16 colors using

dithering

I'm only in 16 colors using

dithering

Page 68: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Now I am 256 color

grayscale

Now I am 256 color

grayscale

Page 69: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

I am monochrome

using dithering!

I am monochrome

using dithering!

Page 70: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Color SummaryColor Summary

NameName Bits Per PixelBits Per Pixel Number of ColorsNumber of Colors

MonochromeMonochrome 11 22

16 Color16 Color 44 1616

GrayscaleGrayscale 88 256256

256 Color256 Color 88 256256

Hi ColorHi Color 1616 65,53665,536

True ColorTrue Color 2424 16,777,21616,777,216

Page 71: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.
Page 72: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

BitmapBitmapResolutionResolution

How Big are Pictures?How Big are Pictures?

Page 73: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Image ResolutionImage Resolution

• ResolutionResolution dimensions of the grid that forms a bitmap graphicdimensions of the grid that forms a bitmap graphic the higher the resolution, the better the qualitythe higher the resolution, the better the quality

• Measured by the number of pixelsMeasured by the number of pixels 150 x 100 = 150 pixels across & 100 pixels high150 x 100 = 150 pixels across & 100 pixels high 640 x 480 = 480,000 pixels = 1 half megapixel640 x 480 = 480,000 pixels = 1 half megapixel

Page 74: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Some Example Some Example ResolutionsResolutions

ResolutionResolution NotesNotes

32 x 3232 x 32 Classic Icon Size – pre Windows XPClassic Icon Size – pre Windows XP

800 x 600800 x 600 Late 1990's Desktop ResolutionLate 1990's Desktop Resolution

1024 x 7681024 x 768 Modern Desktop ResolutionModern Desktop Resolution

1152 x 8641152 x 864 1 Megapixel Image1 Megapixel Image

1600 x 12001600 x 1200 2 Megapixel Image2 Megapixel Image

Page 75: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Calculate Size:Calculate Size:MonochromeMonochrome

640 × 480

= 307,200 pixels

× 1 bit per pixel

= 307,200 bits

= 38,400 Bytes

640

480

Page 76: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Calculate Size:Calculate Size:True ColorTrue Color

800 × 600

= 480,000 pixels

× 24 bits per pixel

= 11,520,000 bits

= 1,440,000 Bytes!

800

600

Page 77: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

We Need We Need Compression!Compression!

• LossyLossy compression compression some data is lostsome data is lost excellent compressionexcellent compression used in many graphics, video and sound filesused in many graphics, video and sound files

• LosslessLossless compression compression data is preserveddata is preserved not as compressed, but still goodnot as compressed, but still good

Page 78: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.
Page 79: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

VectorVectorGraphicsGraphics

Graphics using InstructionsGraphics using Instructions

Page 80: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Vector Graphic BasicsVector Graphic Basics

• Consists of set of instructionsConsists of set of instructions used to "draw" a pictureused to "draw" a picture essentially a essentially a graphic program!graphic program!

• Typical attributesTypical attributes shape – square, circle, line, etc...shape – square, circle, line, etc... sizesize color – may include shadingcolor – may include shading

Page 81: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Advantages and Advantages and DisadvantagesDisadvantages

• AdvantagesAdvantages vectors can be resized without losing data!vectors can be resized without losing data! take little storagetake little storage easy to edit – the instructions can be changedeasy to edit – the instructions can be changed

• DisadvantagesDisadvantages usually not as realistic as bitmap imagesusually not as realistic as bitmap images cannot be used for storing photoscannot be used for storing photos

Page 82: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.
Page 83: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Bitmap vs. VectorBitmap vs. Vector

Stored as raw data (pixels) Stored as instructions

Bitmap Vector

Files can be large Files tend to be small

Data lost when resized No data lost - scalable

Photos and clip art Clip art only

Page 84: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.
Page 85: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Common File Common File TypesTypes

The Ones You Know and LoveThe Ones You Know and Love

Page 86: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Windows BitmapWindows Bitmap

• Native Native bitmap bitmap format of Microsoft Windows format of Microsoft Windows • Can be used to store any bitmapCan be used to store any bitmap• Uses lossless compressionUses lossless compression

although, the compression is minimalalthough, the compression is minimal files are quite largefiles are quite large

• Extension: Extension: bmpbmp

Page 87: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Bitmap: Portable Bitmap: Portable Network GraphicNetwork Graphic

• FeaturesFeatures 48-bit : 48-bit : 281,474,976,710,656281,474,976,710,656 colors! colors! lossless compressionlossless compression supports transparencysupports transparency public domain format – anyone can create editorspublic domain format – anyone can create editors

• Can be used in webpages Can be used in webpages • Extension: Extension: pngpng

Page 88: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Bitmap: JPEG Bitmap: JPEG

• JJoint oint PPhotographic hotographic EExperts xperts GGrouproup• Designed for PhotographsDesigned for Photographs• Lossy CompressionLossy Compression

compression is designed on contrast changescompression is designed on contrast changes sharp contrast changes cause problemssharp contrast changes cause problems however, sharp changes are rare in photoshowever, sharp changes are rare in photos

• Extension: Extension: jpgjpg or or jpegjpeg

Page 89: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Example JPEGsExample JPEGs

Page 90: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Bitmap: GIF Bitmap: GIF

• GGraphical raphical IInterchange nterchange FFormatormat• AttributesAttributes

Up to 256 colors – paletteUp to 256 colors – palette Lossless compressionLossless compression supports transparencysupports transparency can be used for simple animationscan be used for simple animations

• Can be used in webpagesCan be used in webpages• Extension: Extension: gifgif

Page 91: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Example GIFsExample GIFs

Page 92: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Lossless vs. LossyLossless vs. LossyGIF vs. JPEGGIF vs. JPEG

• This image is high This image is high contrastcontrast

• It will be saved in both It will be saved in both GIF and JPEG formatGIF and JPEG format

• Lossy compression Lossy compression will be visiblewill be visible

Page 93: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Lossless vs. Lossy Lossless vs. Lossy GIF vs. JPEGGIF vs. JPEG

GIFGIF JPEGJPEG

NoiseNoise

Page 94: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Common Vector File Common Vector File TypesTypes

• WWindows indows MMeta eta FFileile used for clipartused for clipart extremely popular extremely popular extension: extension: wmfwmf

• EEnhanced Windows nhanced Windows MMeta eta FFileile contains advanced featurescontains advanced features extension: extension: emfemf

Page 95: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Common Vector File Common Vector File TypesTypes

• SScalable calable VVector ector GGraphicraphic can be used in web pagescan be used in web pages automatically resized when automatically resized when

displayed on different screensdisplayed on different screens extension: extension: svgsvg

Page 96: Computer Science 1 Week 10. This Week... QBasic If Statements QBasic If Statements  Comparison operators  Logical operators Computer Concepts Computer.

Example Vector Example Vector GraphicsGraphics