Class 33 — Friday April 10

Chrestomatics and patterning

TBD


Look both ways


Zoom


Agenda


To do


Downloads




Practice module luna.py

elapsed time = distance / speed

DISTANCE_IN_MILES_TO_MOON = 238900.0

h( 119.45 ) = 2000.0

h( 597.25 ) = 400.0



Practice module calc.py

19.5 + 5.25 = 24.75

12.5 - 6.5 = 6.0

12.5 * 4.5 = 56.25

10.0 / 2.25 = 4.444444444444445

1.0 @ 5.0 = None



Practice module eval.py

x1 = [ ]; y1 = [ ]

x2 = [ 3, 1, 4 ]; y2 = [ ]

x3 = [ ]; y3 = [2, 7, 8]

x4 = [ 3, 1, 4 ]; y4 = [1, 5, 1, 9]

f( x1, y1 ) = [ ]

f( x2, y2 ) = [ 3, 1, 4 ]

f( x3, y3 ) = [ 2, 7, 8 ]

f( x4, y4 ) = [ 3, 1, 4, 1, 5, 1, 9 ]



Example module uate.py

x1 = [ 0, 1, 2 ]

x2 = [ 0, 4, 1, 2, 2, 1, 3, 6, 3, 3, 4 ]

x3 = [ ]

g( x1 ) = [ 0, 1, 2 ]

g( x2 ) = [ 0, 4, 1, 2, 3, 6 ]

g( x3 ) = [ ]



Example module sigma.py

d1 = [ [ 0 ], [ 1, 2 ], [ 1, 2, 3 ], [ 0 ] ]

d2 = [ [ 1, 0, 1, 2, 2 ], [ 3, 0, 1, 1, 1, 0 ], [ 2 ], [ 0, 0, 1 ] ]

d3 = [ [ 3, 0, 3], [ 3, 0, 3, 0, 1], [ 1, 0, 2 ] ]

d4 = [ ]

s( d1 ) = 9

s( d2 ) = 15

s( d3 ) = 16

s( d4 ) = 0



Homework module trio.py

x1 = [ 0, -3, 0, -4, -2 ]

x2 = [ -3, 1, -2, 1, -3, -3, -2, -4, -1, -4 ]

x3 = [ 2, -1, 0, 3, 0, 3, -2, -2, -1, -4, 3, -4, 3, -1, 3 ]

x4 = [ ]

t( x1 ) = [ 3, 2, 0 ]

t( x2 ) = [ 8, 0, 2 ]

t( x3 ) = [ 7, 2, 6 ]

t( x4 ) = [ 0, 0, 0 ]



Homework module flat.py

d1 = [ [ 0 ], [ 1, 2 ], [ 1, 2, 3 ], [ 0 ] ]

d2 = [ [ 1, 0, 1, 2, 2 ], [ 3, 0, 1, 1, 1, 0 ], [ 2 ], [ 0, 0, 1 ] ]

d3 = [ [ 3, 0, 3], [ 3, 0, 3, 0, 1], [ 1, 0, 2 ] ]

d4 = [ ]

n( d1 ): [0, 1, 2, 1, 2, 3, 0]

n( d2 ): [1, 0, 1, 2, 2, 3, 0, 1, 1, 1, 0, 2, 0, 0, 1]

n( d3 ): [3, 0, 3, 3, 0, 3, 0, 1, 1, 0, 2]

n( d4 ): []



Some possible image transformations

original original

Duplicated image


original original

Mirrored image


originaloriginal

Flipped image


originaloriginal

Clockwise rotation


Basic photo-manipulation problem-solving pattern

# get dimensions of the original

ow, oh = ...

 

# set dimensions of the new image

nw, nh = ...

 

# get a new appropriately sized image

new_image = Image.new( 'RGB', ( nw, nh ) )

 

# fill in every pixel of the new image

for nx in range( 0, nw ) : # consider every x value for the new image

  for ny in range( 0, nh ) : # in tandem with every y value for the image

 

  # set the spot to be filled in the new image

  nspot = (nx ,ny )

 

  # determine the corresponding spot of interest in the original

  ospot = ...

 

  # get the pixel at the ospot

  opixel = ...

 

  # determine the pixel for the new image

  npixel = ...

 

  # set the nspot in the new image

  ...

 

# return the filled in new image

return new_image


Basic photo-manipulation problem-solving Python function

def manip( original, size, color, where ) :

  ''' Provide a pattern for image manipulation

  '''

  # set dimensions of the new image

  nw, nh = size( original )

  # get a new appropriately sized image

  new_image = Image.new( 'RGB', ( nw, nh ) )

  # fill in every pixel of the new image

  for nx in range( 0, nw ) : # consider every x value for the new image

  for ny in range( 0, nh ) : # in tandem with every y value for the image

  # set the spot to be filled in the new image

  nspot = ( nx, ny )

  # determine the corresponding spot of interest in the original

  ospot = where( nspot, original )

  # get the pixel at the ospot

  opixel = original.getpixel( ospot )

  # determine the pixel for the new image

  npixel = color( opixel )

  # set the nspot in the new image

  new_image.putpixel( nspot, npixel )

  # return the filled in new image

  return new_image


crossword snapshot

 


 
  © 2020 Jim Cohoon   Resources from previous semesters are available.