FUNCTION PRACTICE 1 Easy Picture Function Turn all

  • Slides: 7
Download presentation
FUNCTION PRACTICE !!! 1

FUNCTION PRACTICE !!! 1

Easy Picture Function # Turn all mostly-red pixels blue ("mostly-red" means within a distance

Easy Picture Function # Turn all mostly-red pixels blue ("mostly-red" means within a distance of 140 of red) # Hints: use “distance”, “get. Color”, “set. Color” def red. To. Blue (pic): # add 3 more lines 2

Medium Picture Function # turn bottom-right corner of a picture (100 x 100 pixels)

Medium Picture Function # turn bottom-right corner of a picture (100 x 100 pixels) white # Hints: use “get. Width”, “get. Height”, “get. Pixel. At”, “set. Color” def white. Corner (pic): # add 4 more lines 3

Easy Sound Function # Shift all samples in a sound "up" by 32767 #

Easy Sound Function # Shift all samples in a sound "up" by 32767 # Hints: use “get. Samples”, “get. Sample. Value”, “set. Sample. Value” def up. Shift (sound): # 3 more lines 4

Medium Sound Function # Create a new sound that cuts the frequency of a

Medium Sound Function # Create a new sound that cuts the frequency of a sound in half (doubles its length so it sounds "lower") # Hints: use “get. Samples”, “get. Sample. Value”, “set. Sample. Value. At” def halve. Frequency (sound): target = target. Index = for s in get. Samples (sound): # 4 lines inside loop target. Index = # 1 more line below here 5

Easy “Miscellaneous” Function # Count from 0 to 100 by 5 s def count.

Easy “Miscellaneous” Function # Count from 0 to 100 by 5 s def count. And. Print (): # 2 more lines 6

Medium “Miscellaneous” Problem # Print a line of 10 hellos, a line of 9

Medium “Miscellaneous” Problem # Print a line of 10 hellos, a line of 9 hellos, . . . , a line of 1 hello # Hints: use 2 “for” loops. The command print “hello”, # will keep the printing on the same line. The command print # will send printing to the next line def hello. There(): # 4 more lines, including the “for”s for i in range for j in range 7