lecture 26 - dynamic graphics project

76
APS105 Winter 2012 Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 26 March 21, 2012

Upload: others

Post on 31-Mar-2022

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 26 - Dynamic Graphics Project

APS105Winter 2012

Jonathan Deberjdeber -at- cs -dot- toronto -dot- edu

Lecture 26March 21, 2012

Page 2: Lecture 26 - Dynamic Graphics Project

2

Today

• Debugging

• Recursion

Page 3: Lecture 26 - Dynamic Graphics Project

Debugging

3

Page 4: Lecture 26 - Dynamic Graphics Project

All Software Has Bugs

4

• Unavoidable

• Techniques to help avoid them, and to help find them

Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?

Brian Kernighan

Page 5: Lecture 26 - Dynamic Graphics Project

5Image: Naval Historical Center

Grace Hopper’s Lab Notebook

Page 6: Lecture 26 - Dynamic Graphics Project

Types of Bugs

• Code that does not do what it’s supposed to

• Code that does what it’s supposed to, but that isn’t the right thing to do

• May be a bug in the design

6

Page 7: Lecture 26 - Dynamic Graphics Project

Diagnosing Bugs• Need to be precise

7

My program doesn’t work.

My program crashes with a Segmentation Fault when given the input !.

My program crashes with a Segmentation Fault on line !"# when given the input !.

My program crashes.

My program crashes with a Segmentation Fault.

My program crashes with a Segmentation Fault on line !"# when given the input ! because I’m never storing a pointer in $%&'(.

Page 8: Lecture 26 - Dynamic Graphics Project

Fixing Them

• In order to fix a bug, you have to find it

• Finding it is usually the hard part

8

Page 9: Lecture 26 - Dynamic Graphics Project

Diagnosing Bugs

• Manual )&%*($+, statements

• Debugger

9

Page 10: Lecture 26 - Dynamic Graphics Project

Knowing Where You Crashed

• Often that’s enough

• A debugger will tell you which line

• Need to compile with -. flag (.//0-12330-. ...)

10

40.560'782&9

+.56,0&8*

!"#$%&'()*!+,-+./0-1,/11!*22(#3(#445"$$'(676666666666666666676666666866666"#9(:&($;<#5"(=&>?@ABCD(#3($;<#5"EF'GG(((((((((((HI(>(&J

Crash is on this line

Page 11: Lecture 26 - Dynamic Graphics Project

!"#$%&'(• Add in )&%*($+, statements to tell you what’s going on

11

%*(0/&92(9:%'(;.&2<=;>+/?2&0&;>@AB0/?2&0'C<6;3B000000000000000%*(0D2389B0%*(0<2EF2389B0%*(0<2E=;>G9*.(?,H00000005;86390)9&/9*(2.90I0+5;8639,D23890J0<2EF2389K000000%*(0*8<LC<6;3'0I0&%*(+)9&/9*(2.90M0<2E=;>G9*.(?,K000000)&%*($+NO&2>%*.0P50;8(0;$0P502'0P50'C<6;3'Q0R*NB0000000000000D2389B0<2EF2389B0*8<LC<6;3',K00QQQ

Page 12: Lecture 26 - Dynamic Graphics Project

12

S59$%*90OTUVWWXYW0$23'9

%$0+OTUVWWXYW,H00)&%*($+NZ&%*(%*.0&;>0P5Q0R*NB0%,K[

Page 13: Lecture 26 - Dynamic Graphics Project

13

Debugger• “Breakpoints” let you stop your program at a specific line

• Allows you to step through your code

• Step Over (go to the next line, skipping function calls)

• Step Into (go to the next line, entering function calls)

• Step Out (go back to the caller)

• Displays values of variables

• .56 is .//’s debugger, they’re also built-in to IDEs

Page 14: Lecture 26 - Dynamic Graphics Project

14

The remaining 10% of the code accounts for the other 90% of the development time.

Tom Cargill

The first 90% of the code accounts for the first 90% of the development time.

Page 15: Lecture 26 - Dynamic Graphics Project

Recursion

15

In order to understand recursion,you must first understand recursion.

Anonymous

Page 16: Lecture 26 - Dynamic Graphics Project

16

Recursion

• A problem defined in terms of itself

Page 17: Lecture 26 - Dynamic Graphics Project

17

If I need to put away a pile of books:

Put away the first bookPut away the remaining pile

If I need to climb a flight of stairs:

Climb one stair

Climb the remaining flight of stairs

If I need to calculate *\Multiply *0M0+*0-0!,\

Page 18: Lecture 26 - Dynamic Graphics Project

18

Page 19: Lecture 26 - Dynamic Graphics Project

19

Page 20: Lecture 26 - Dynamic Graphics Project

20

Recursion

• A problem defined in terms of itself

• No more (or less) powerful than loops (iteration)

Page 21: Lecture 26 - Dynamic Graphics Project

21

Put away the books one at a time

Climb the stairs one at a time

Start at ! and multiply it by each number up to *

If I need to put away a pile of books:

Put away the first bookPut away the remaining pile

If I need to climb a flight of stairs:

Climb one stair

Climb the remaining flight of stairs

If I need to calculate *\Multiply *0M0+*0-0!,\

Page 22: Lecture 26 - Dynamic Graphics Project

22

If I need to put away a pile of books:

Put away the first bookPut away the remaining pile

If I need to climb a flight of stairs:

Climb one stair

Climb the remaining flight of stairs

If I need to calculate *\Multiply *0M0+*0-0!,\

Page 23: Lecture 26 - Dynamic Graphics Project

22

What happens when I run out of books?

What happens when I get to the top?

When do I stop?

If I need to put away a pile of books:

Put away the first bookPut away the remaining pile

If I need to climb a flight of stairs:

Climb one stair

Climb the remaining flight of stairs

If I need to calculate *\Multiply *0M0+*0-0!,\

Page 24: Lecture 26 - Dynamic Graphics Project

23

Recursion

• A problem defined in terms of itself

• No more (or less) powerful than loops (iteration)

• All recursive problems must have a “base case”, which is a trivial version of the problem

Page 25: Lecture 26 - Dynamic Graphics Project

24

If there are no more books, we’re done

If we’re at the top, we’re done

If * is !, *\ is !

If I need to put away a pile of books:

Put away the first bookPut away the remaining pile

If I need to climb a flight of stairs:

Climb one stair

Climb the remaining flight of stairs

If I need to calculate *\

Multiply *0M0+*0-0!,\

Otherwise

Otherwise

Otherwise

Page 26: Lecture 26 - Dynamic Graphics Project

25

Recursion and Programming

• A recursive function is a function that calls itself

• That’s it!

• Provides another way to iterate

• No more (or less) powerful than loops

• Similar to $;& loops vs. >?%39 loops

• Why bother? Makes some algorithms simpler

Page 27: Lecture 26 - Dynamic Graphics Project

Factorial

26

*\0%'0*0M0+*0-0!,0M0+*0-0",0M0QQQ0M0"0M0!

%*(0$2/(;&%23X(9&2(%D9+%*(0*,H0000%*(0&9'83(0I0!K00000000$;&0+%*(0%0I0!K0%0]I0*K0%^^,0000H00000000&9'83(0MI0%K0000[00000000&9(8&*0&9'83(K[

Page 28: Lecture 26 - Dynamic Graphics Project

Factorial

27

+*0-0!,\

+*0-0",\

*\0%'0*0M0+*0-0!,0M0+*0-0",0M0QQQ0M0"0M0!

*\0%'0*0M0+*0-0!,\

Page 29: Lecture 26 - Dynamic Graphics Project

Factorial

28

%*(0$2/(;&%23=9/8&'%D9+%*(0*,H00000000%*(0&9'83(K000000&9'83(0I00*0M0$2/(;&%23=9/8&'%D9+*0-0!,K000000&9(8&*0&9'83(K[

*\0%'0*0M0+*0-0!,\

Page 30: Lecture 26 - Dynamic Graphics Project

Factorial

28

%*(0$2/(;&%23=9/8&'%D9+%*(0*,H00000000%*(0&9'83(K000000&9'83(0I00*0M0$2/(;&%23=9/8&'%D9+*0-0!,K000000&9(8&*0&9'83(K[

%$0*0_0!

%$0*0II0!

*\0%'0*0M0+*0-0!,\

*\0%'0!

Page 31: Lecture 26 - Dynamic Graphics Project

29

%*(0$2/(;&%23=9/8&'%D9+%*(0*,H0000000%*(0&9'83(K000000%$0+*0II0!,00H0000&9'83(0I0!K00[000000000000&9'83(0I00*0M0$2/(;&%23=9/8&'%D9+*0-0!,K

00&9(8&*0&9'83(K[

Page 32: Lecture 26 - Dynamic Graphics Project

30

%*(0$2/(;&%23=9/8&'%D9+%*(0*,H0000000%*(0&9'83(K000000%$0+*0II0!,00H0000&9'83(0I0!K00[0000000000

00&9(8&*0&9'83(K[

00&9'83(0I00*0M0$2/(;&%23=9/8&'%D9+*0-0!,K

0093'900H

00[

Page 33: Lecture 26 - Dynamic Graphics Project

Recursive Structure

• Steps for writing a recursive algorithm:

• Figure out the recursive structure of the problem

• Must be able to break the problem into two parts

• Each must be either trivial or a smaller version of the same problem

• Figure out the trivial base case(s)

• Convert pseudocode to C

31

Page 34: Lecture 26 - Dynamic Graphics Project

Fibonacci

32

`+*,0I0`+*-!,0^0`+*-",

`+a,0I0aB0`+!,0I0!

aB0!B0!B0"B0bB0cB0#B0!bB0"!B0bdB0ccB0#eB0!ddB0"bbB0bffB0g!aB0

e#fB0!cefB0"c#dB0d!#!B0QQQ

Page 35: Lecture 26 - Dynamic Graphics Project

33

%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,

0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[

6 8 K ? B

&L8 & &"73

Page 36: Lecture 26 - Dynamic Graphics Project

33

%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,

0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[

6 8 K ? B

&L8

& &"73

Page 37: Lecture 26 - Dynamic Graphics Project

33

%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,

0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[

6 8 K ? B

&L8 &

&"73

Page 38: Lecture 26 - Dynamic Graphics Project

33

%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,

0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[

6 8 K ? B

&L8 &

Page 39: Lecture 26 - Dynamic Graphics Project

33

%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,

0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[

6 8 K ? B

&L8 & &"73

Page 40: Lecture 26 - Dynamic Graphics Project

33

%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,

0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[

6 8 K ? B

&L8

& &"73

Page 41: Lecture 26 - Dynamic Graphics Project

33

%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,

0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[

6 8 K ? B

&L8 &

&"73

Page 42: Lecture 26 - Dynamic Graphics Project

33

%*(0$%6;*2//%X(9&2(%D9+%*(0*,H0000%*(0$%6h*0I0!K0000000JJ0$%6+!,0000%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,

0000$;&0+%*(0%0I0"K0%0]I0*K0%^^,0000H00000000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K0000000000000000$%6h*i%*8'!0I0$%6h*K00000000$%6h*0I0*9E(j9&<K0000[000000000000%*(0&9'83(K00000000%$0+*0II0a,0000H00000000&9'83(0I0$%6h*i%*8'!K0000[000093'90000H00000000&9'83(0I0$%6h*K0000[00000000&9(8&*0&9'83(K[

6 8 K ? B

&L8 &

Page 43: Lecture 26 - Dynamic Graphics Project

34

%*(0$%6;*2//%=9/8&'%D9+%*(0*,H0000%*(0&9'83(K

0000%$0+*0II0a,0000H00000000&9'83(0I0aK0000[000093'90%$0+*0II0!,0000H00000000&9'83(0I0!K0000[000093'90000H00000000&9'83(0I0$%6;*2//%=9/8&'%D9+*0-0!,00000000000000000000000^0$%6;*2//%=9/8&'%D9+*0-0",K0000[00000000&9(8&*0&9'83(K[

Page 44: Lecture 26 - Dynamic Graphics Project

35

%*(0$%6;*2//%X(9&2(%D9+%*(0*,H00%*(0$%6h*0I0!K0000000JJ0$%6+!,00%*(0$%6h*i%*8'!0I0aK0JJ0$%6+a,

00$;&0+%*(0%0I0"K0%0]I0*K0%^^,00H0000%*(0*9E(j9&<0I0$%6h*0^0$%6h*i%*8'!K000000000000$%6h*i%*8'!0I0$%6h*K0000$%6h*0I0*9E(j9&<K00[0000000000%*(0&9'83(K000000%$0+*0II0a,00H0000&9'83(0I0$%6h*i%*8'!K00[0093'900H0000&9'83(0I0$%6h*K00[000000&9(8&*0&9'83(K[

%*(0$%6=9/8&'%D9+%*(0*,H00%*(0&9'83(K

00%$0+*0II0a,00H0000&9'83(0I0aK00[0093'90%$0+*0II0!,00H0000&9'83(0I0!K00[0093'900H0000&9'83(0I0$%6=9/8&'%D9+*0-0!,00000000000000^0$%6=9/8&'%D9+*0-0",K00[000000&9(8&*0&9'83(K[

Page 45: Lecture 26 - Dynamic Graphics Project

Tracing Functions

36

• A key to understanding recursion is tracing the function calls

%*(0$2/(;&%23=9/8&'%D9+%*(0*,H0000000%*(0&9'83(K0000000%$0+*0II0!,000H000000&9'83(0I0!K000[000000093'9000H000000&9'83(0I0*0M0$2/(;&%23=9/8&'%D9+*0-0!,K000[0000000&9(8&*0&9'83(K[

Page 46: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

Page 47: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

Page 48: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

?

Page 49: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

&'

5"$<P3'

$2/=9/8&'%D9+,

?

K

Page 50: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

&'

5"$<P3'

$2/=9/8&'%D9+,

&'

5"$<P3'

$2/=9/8&'%D9+,

?

K

8

Page 51: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

&'

5"$<P3'

$2/=9/8&'%D9+,

&'

5"$<P3'

$2/=9/8&'%D9+,

8

?

K

8

Page 52: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

&'

5"$<P3'

$2/=9/8&'%D9+,

5"$<P3'

$2/=9/8&'%D9+,

8

?

K

Page 53: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

&'

5"$<P3'

$2/=9/8&'%D9+,

5"$<P3'

$2/=9/8&'%D9+,

8

?

K

8

Page 54: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

&'

5"$<P3'

$2/=9/8&'%D9+,

?

K

8

Page 55: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

&'

5"$<P3'

$2/=9/8&'%D9+,

?

K

8

Page 56: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

&'

5"$<P3'

$2/=9/8&'%D9+,

?

K

8

Page 57: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

&'

5"$<P3'

$2/=9/8&'%D9+,

K

?

K

8

Page 58: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

5"$<P3'

$2/=9/8&'%D9+,

K

?

8

Page 59: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

5"$<P3'

$2/=9/8&'%D9+,

K

?

8

K

Page 60: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

?

K

Page 61: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

?

K

Page 62: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

?

K

Page 63: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

&'

5"$<P3'

$2/=9/8&'%D9+,

S

?

K

Page 64: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

5"$<P3'

$2/=9/8&'%D9+,

S K

Page 65: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

5"$<P3'

$2/=9/8&'%D9+,

S K

S

Page 66: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

S

Page 67: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

S

Page 68: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

S

Page 69: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

&'

5"$<P3'

B

$2/=9/8&'%D9+,

KB

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

S

Page 70: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

5"$<P3'

$2/=9/8&'%D9+,

KB

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

S

Page 71: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

5"$<P3'

$2/=9/8&'%D9+,

KB

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

S

KB

Page 72: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ

KB

Page 73: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ KB

Page 74: Lecture 26 - Dynamic Graphics Project

<2%*+,

M#F'

:&3(M#F!"F<5$:N"=:&3(&DO((((((:&3(5"$<P3J((((((:M(=&(>>(8D((O((((5"$<P3(>(8J((Q(((((("P$"((O((((5"$<P3(>(&(H(M#F!"F<5$:N"=&L8DJ((Q((((((5"3<5&(5"$<P3JQ

:&3(R#:&=N%:4DO((:&3(M#F(>(M#F!"F<5$:N"=BDJ((((5"3<5&(6JQ KB

Page 75: Lecture 26 - Dynamic Graphics Project

38

Print out a line of n stars *0I0! M*0I0c MMMMM

D;%50)&%*(=;>+%*(0*,H0000$;&0+%*(0%0I0aK0%0]0*K0%^^,0000H00000000)&%*($+NMN,K0000[[

Page 76: Lecture 26 - Dynamic Graphics Project

39

MMMMM

{

{

row of * stars

row of *0-0! stars

*0I0!

*0I0c

! star{

Print out a line of n stars M

MMMMM