Search Header Logo
Introduction to functions in CMU graphics

Introduction to functions in CMU graphics

Assessment

Presentation

Other

9th - 12th Grade

Medium

Created by

Benjamin Griffel

Used 4+ times

FREE Resource

8 Slides • 6 Questions

1

Introduction to functions in CMU graphics

Slide image

2

Functions are built in programs that you can use

  • When we write a program, we are combining the built in functions or sometimes writing new ones

3

We have already used many functions such as

  • Circle()

  • gradient()

  • rgb()

  • and others

4

Multiple Choice

Which of these is not a function?

1

Rect(200,200,100,140)

2

Circle(200,200,40)

3

fill = 100

4

gradient('red','blue')

5

Parts of a function - using Circle as example

Circle(200,150,50, fill = 'red', opacity = 40)

  • name of the function is Circle()

  • 200, 150, and 50 are the required arguments (they represent x, y , and radius)

  • fill and opacity are optional arguments, you don't need them for the code to work

6

Using functions,

  • Up till now, when we wanted to use a function we just typed in the name with the options we wanted

  • this is called "calling a function"


7

onMousePress(mouseX, MouseY) is a special function

we do not call this function by typing a line of code. We modify the function itself using code, but this function only is "called" when the mouse is clicked. In other words the computer does not follow these instructions in the function unless we click.

8

Slide image

9

function body

  • the computer does everything in the function body when the function is used

  • for onMousePress( ) that means all that stuff happens when you click

10

Multiple Choice

Question image

What does this code do and when?

1

draws a darkOrange circle when you click run

2

draws a darkOrange circle but only when you click on the canvas

3

draws a blue circle when you click run

4

draws a blue circle when you click on the canvas

11

Multiple Choice

Question image

Where does the circle get drawn?

1

the middle of the screen

2

it's picked randomly

3

at the spot we click the mouse

12

Multiple Choice

Question image

How many shapes are drawn when you click run?

1

0

2

1

3

2

4

3

13

Multiple Choice

How many total shapes are on the screen after we click run, and then click on the canvas?

1

0

2

1

3

2

4

3

14

Multiple Choice

Why don't the shapes appear where the mouse pointer is pointing?

1

because the code doesn't use the values of mouseX or mouseY in the shape functions

2

because we are not clicking at the right part of the screen

3

we need to double click

4

the code is wrong!

Introduction to functions in CMU graphics

Slide image

Show answer

Auto Play

Slide 1 / 14

SLIDE