Grandparents U, 2018 Part 2 Computer Programming for Beginners Filip Jagodzinski
Preliminaries : Course Website All of these slides will be provided for you online... The URL for the slides are provided to you on your handout
Almost there Computer programming is done using a computer CODE, or coding You learn by making mistakes, sort of like learning how to ride the bicycle Q: How many people were involved in making Pokemon Go
Today A few of the more technical things that make life easier and coding less repetitive!
Turtle Graphics Finally some graphics Turtle # variable values color shape # functions Turtle() forward(int) left(int) This diagram represents the class Turtle It contains functions for modifying a Turtle object s attributes
Turtle Graphics Finally some graphics Turtle # variable values color shape # functions Turtle() forward(int) left(int) This diagram represents the class Turtle It contains functions for modifying a Turtle object s attributes screen = turtle.screen() screen.bgcolor("lightgreen") # create turtle named billy billy = turtle.turtle() billy.color("red") billy.shape("turtle") billy.speed(10) billy.forward(60) billy.up() billy.goto(50,120) billy.down() billy.color("purple") billy.stamp() # create a turtle named susan susan = turtle.turtle() susan.color( blue ) susan.left(165) susan.forward(50) Create a screen & Background color
Turtle Graphics Finally some graphics Turtle # variable values color shape # functions Turtle() forward(int) left(int) This diagram represents the class Turtle It contains functions for modifying a Turtle object s attributes screen = turtle.screen() screen.bgcolor("lightgreen") # create turtle named billy billy = turtle.turtle() billy.color("red") billy.shape("turtle") billy.speed(10) billy.forward(60) billy.up() billy.goto(50,120) billy.down() billy.color("purple") billy.stamp() # create a turtle named susan susan = turtle.turtle() susan.color( blue ) susan.left(165) susan.forward(50) Create a new object of type turtle, and name it billy
Turtle Graphics Finally some graphics Turtle # variable values color shape # functions Turtle() forward(int) left(int) This diagram represents the class Turtle It contains functions for modifying a Turtle object s attributes screen = turtle.screen() screen.bgcolor("lightgreen") # create turtle named billy billy = turtle.turtle() billy.color("red") billy.shape("turtle") billy.speed(10) billy.forward(60) billy.up() billy.goto(50,120) billy.down() billy.color("purple") billy.stamp() # create a turtle named susan susan = turtle.turtle() susan.color( blue ) susan.left(165) susan.forward(50) Change the objects attributes
Turtle Graphics Finally some graphics Turtle # variable values color shape # functions Turtle() forward(int) left(int) This diagram represents the class Turtle It contains functions for modifying a Turtle object s attributes screen = turtle.screen() screen.bgcolor("lightgreen") # create turtle named billy billy = turtle.turtle() billy.color("red") billy.shape("turtle") billy.speed(10) billy.forward(60) billy.up() billy.goto(50,120) billy.down() billy.color("purple") billy.stamp() # create a turtle named susan susan = turtle.turtle() susan.color( blue ) susan.left(165) susan.forward(50) Modify the objects position
Turtle Graphics Finally some graphics Turtle # variable values color shape # functions Turtle() forward(int) left(int) This diagram represents the class Turtle It contains functions for modifying a Turtle object s attributes screen = turtle.screen() screen.bgcolor("lightgreen") # create turtle named billy billy = turtle.turtle() billy.color("red") billy.shape("turtle") billy.speed(10) billy.forward(60) billy.up() billy.goto(50,120) billy.down() billy.color("purple") billy.stamp() # create a turtle named susan susan = turtle.turtle() susan.color( blue ) susan.left(165) susan.forward(50) Create a second object of type turtle, and name it susan
Functions And if you need to do the same thing OVER and OVER again In addition to using Python s functions (such as print), you can create your OWN function, and then use it over and over again as needed. Here s how
Functions And if you need to do the same thing OVER and OVER again First, define a function The format is def functionname(): And in the body of the function include your code
Functions And if you need to do the same thing OVER and OVER again Then, you can invoke the function Multiple times to run it Q: What do you think this draws?
Functions And if you need to do the same thing OVER and OVER again Then, you can invoke the function Multiple times to run it
Today Continue to work on in-lab exercises proceed to graphics when you are ready