week$3:$loops$and$ custom$blocks cmps10€¦ ·...

13
Week 3: Loops And Custom Blocks CMPS10 PARDIS“PARIS”MIRI UNIVERSITY OF CALIFORNIA,SANTA CRUZ DEPARTMENT OF COMPUTER SCIENCE 1

Upload: others

Post on 21-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

Week  3:  Loops  And  Custom  BlocksCMPS10PARDI S “PAR IS ”  M I R I

UN I VERSI TY  O F  CAL I FORNIA,  S AN TA  CRU Z

DEPARTMENT  OF  COMPUTER  S C I ENCE

1

Page 2: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

OutlineØ Part  1:  Nested  loop  Coding  Examples  (*if  we  had  time*)

Ø Part  2:  Drawing  a  Pentagon  and  a  Hexagon  ExamplesØ custom  blocks

Ø Part  3:  Drawing  a  Flower  and  Stem  Ø Part  4:  Fancy  Flower  Field

Ø Part  5:  Week  3  Homework  Assignment

2

Page 3: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

Part  1:Nested  loop  Coding  Examples  

Ø Try  out  these  lines  of  code  in  snap!ØReport  the  value  of  x.  Ø Report  the  value  of  I,j,kØ Note:  Import   tools  to  see  the  for  loop.

3

Page 4: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

Part  1:Nested  loop  Coding  Examples  (python)Ø Try  out  these  lines  of  code  in  python!

Ø http://www.tutorialspoint.com/execute_python_online.php.  

4

Page 5: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

Part  2:  Drawing  a  Pentagon  and  a  Hexagon  ExamplesØ Pentagon  Math:Ø 3  *  180  /  5  =  108Ø 180  – 108  =  72

Ø Start  Math:Ø 108  /3  =  36Ø 180  – 36  =  144

Ø Hexagon  Math:Ø 4  *  180  /  6  =  120Ø 180  – 120  =  60

5

Page 6: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

Part  3:  Drawing a  FlowerØMath:Ø Figuring  out  how  many  pentagon  to  draw  in  360  space.Ø Loop  with  number  of  petalsØ Turn  number  of  petals/360  

6

Page 7: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

Part3:  Drawing  a  Flower  stem

7

Assuming  that  drawing  the  stem  is  the  last  part,  pen  up  is  necessary!

Page 8: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

Part4:  Drawing  a  Flower  Field

8

Ø Repeat  ØGo  to  a  random  location  (within  the  boundary)ØPut  the  pen  downØDraw  a  unique  flower  (shape,  size,  color)ØDraw  a  stem  ØPen  up  

Page 9: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

Part4:  Fancy  Flowers  from  Last  Quarter

9

Extra  credit  for  drawing  flower  stem  leaves.

Page 10: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

Part  5:Week  3 Lab  Assignment  Assignment  Link:   ecommons

Assignment  duration:  About  two  to  three  hours

Assignment:   Complete the  following  “Loops  and  Building  Blocks”  activities   (on  your  own  or  

via  a  partner):Loops  and  Building  your  own  Blocks.!Output:   Export the  field  of  flowers  and  save  it  as XML.

example: flowers.xml

What  to  submit? Submit  your  xml  file  as "Attachments"  in  the  submission  area.

If  you collaborated with  someone,  mention  their  name  and  email  address  in  the  comment  area.

If  you  are resubmitting (after  being  graded  in  the  lab),  mention  mention  that  in  the  comment  area.

Due:    Jan  25th,  8am.

10

Page 11: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

Part  5:Week  3 Lab  Assignment  Grading  Criteria:  

Ø If  you  don’t   submit   as  a  XML,   you  will  receive  zero.  

Ø Full   credit  is  10.   Two  points   of  extra  credit  is  available  for  this  assignment.

Ø Extra  credit  +2  for  a  drawing  a  fancy  flower  field. Feel  free  to  be  creative!◦ If  you  draw  a  stem  flower  leaves,  you  will  receive  the  +2  credit.

ØUse  of  Custom  Blocks   is  a  must  in  this  project  (at  least  two  nested  custom  blocks).

ØUse  of  randomness   is  a  must  in  this   project  (e.g.,  random   location  for  drawing  a  flower).

ØBe  mindful   about  where  you   are  drawing  the  flowers.  It  does   not  make  sense   to  draw  them  in  the  air  or  sea.

11

Page 12: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

Part  2:  SNAP!  :  Snap  Programming  SyllabusØWeek  1:  Complete   your  choice   of  one  of  the  three  “Hour  of  Code”  Activities.ØWeek  2:  “Intro  to  Snap!”

ØWeek  3:  “Loops   and  Blocks”ØWeek  4:  “Conditional   and  Variables”

ØWeek  5:  “Abstraction   and  Testing”ØWeek  6:  “Multiple   Sprites”  – mini  project

ØWeek  7:  “Lists”      +  midterm   (18th Feb)ØWeek  8:  “Recursion   and  Fractals”

ØWeek  9  and  10:  “Final   Project”

12

Page 13: Week$3:$Loops$And$ Custom$Blocks CMPS10€¦ · Outline!Part&1:&Nested&loop&Coding&Examples&(*if&we&had&time*)! Part&2:Drawing&a&Pentagon&and&a&Hexagon&Examples!custom&blocks! Part&3:&Drawing&a&Flower&and&Stem&

Questions?

13