0% found this document useful (0 votes)
8 views21 pages

CIP 2025 - Section Week 5

The document outlines a Week 5 section agenda led by Cameron Mohne and Maggie Lee, focusing on functions and graphics in programming. It includes a recap of key concepts such as parameters, return statements, and the use of a canvas for visualizing code. The section culminates in a coding activity where participants will create a program to draw random circles on a canvas.

Uploaded by

Ali Imran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views21 pages

CIP 2025 - Section Week 5

The document outlines a Week 5 section agenda led by Cameron Mohne and Maggie Lee, focusing on functions and graphics in programming. It includes a recap of key concepts such as parameters, return statements, and the use of a canvas for visualizing code. The section culminates in a coding activity where participants will create a program to draw random circles on a canvas.

Uploaded by

Ali Imran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Welcome to

Section!
Week 5
Slides by Cameron Mohne and Maggie Lee
Agenda

1. 2. 3.
Section Problem:
Check-in Recap
Random Circles
Before we start...

Let’s do a quick check-in activity!

In breakout rooms:
Grab the closest thing to you and try to sell it to your
partner.

As a group, one-by-one:
What did you try to sell?
Questions?
Before we jump into the recap, are there any
questions?
Lecture Recap
Recap -
Functions 2.0
Functions 2.0

def function_one(): Incorrec


variable_one = 0
Parameters function_two() t
Parameters are a way Not possible! function_two
to pass data to your doesn’t know that
def function_two():
helper functions. variable_one exists!
variable_two = variable_one
Variables made in a
function are invisible
to other functions
unless it is passed def function_one(): Correct
through a parameter. variable_one = 0
function_two(variable_one) We use a
parameter to
def function_two(example_param): pass the data
variable_two = example_param instead
Functions 2.0

Returns
Similar to parameters, but in
the reverse direction! We use
return statements to pass def function_one():
data from a function to input()
name = input(“Enter your name: ”)
wherever it was called. returns
data for
def input(prompt):
One example is the input() you to use,
... # Some code
function that you’ve been wherever
return user_input
using! Whenever you have a you called
function that returns it from!
something, you usually want
a variable to store that data!
Recap -
Graphics
Canvas
The canvas is a fun way
for us to visualize and
interact with our code in
a somewhat similar way
to Karel!
(0,
0)

Canvas
Remember how pixels are
laid out: starting at (0, 0) (150, 150)
for the top left and
increasing in x/y-values
as you go right/down
respectively
(300, 300)
y1
Canvas
To draw something, we need to use x1
40px
four parameters. These numbers (0,
represent the coordinates of the 0)
40px
two points used to draw the image.
(40,
Since the function is a part of our 40)
canvas, we use our canvas
followed by a period and then the x2 y2

function name. We can also add an


extra parameter for color if we
want.
(300, 300)
Example:
x1 y10,
canvas.create_rectangle(0, x240,
y2 40, color
“Purple”)
Recap Questions
Wow! That was a lot! You’ve also been learning a lot.
Are there any questions over lecture content or
anything else?
Section Problem:
Random Circles
Random Circles
As an intro to functions &
graphics, we want to get
comfortable with:
1) The conceptuals of
drawing and indexing with
pixels
2) Calling functions with
parameters/returns.

To practice, let’s write a


program that draws 20
circles at random positions
with random colors on the
canvas.
Example Starting
Canvas

X2
0
End Goal
Our program takes in a blank
canvas and then draws 20 Example Output
circles at random Canvas
positions with random
colors on the canvas.
Problem Details

Canvas Colors
The canvas is created We provide a function
for you already with that returns a random
some functions color
provided

Canvas Circle
Details Details
We give you the
Canvas width/height diameter size of the
are provided as global circles and the
variables number of circles to
make
Pre-code Discussion
Say we want to make a single circle, how would we
do that?
Hi, I’m a
circle!
And
single!

Are there any questions regarding the


canvas, graphics, drawing, or anything else?
Coding Time!
Let’s split into breakout
rooms to code up the
solution!
Post-code
Discussion
Are there any questions at all?
Extensions
x ✔
#
Number of Size of Bounds of
Circles Circles Circles
Create a random Make sure all circles
Have the circles be
amount of circles are in the bounds of
of random size
instead of a set the canvas!
instead of a set size!
amount!

You might also like