Syllabus 20091124

From XPUB & Lens-Based wiki

Points on the agenda for today:

  • Review results from 2nd technical assignment
  • Gettings results from first two technical assignments online (on the Wiki!)
  • Compressing videos (for posting on the wiki)

and:

  • The power of functional abstraction: DIY interfaces with shell scripts & Python functions
  • Sliding values revisited


import sys, pygame
pygame.init()

width, height = (640, 480)
screen = pygame.display.set_mode((width, height))
clock = pygame.time.Clock()

def slide(start, end, slider):
    x = ((end-start)*slider)+start
    return x

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT or \
          (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
            sys.exit()

    pygame.draw.rect(screen, (0, 0, 0), (0,0,width,height), 0)
    mx, my = pygame.mouse.get_pos()
    
    x_slider = (mx/float(width))
    y_slider = (my/float(height))

    rect_x = slide(0, width, x_slider)
    rect_y = slide(height, 0, y_slider)
    
    print rect_x, rect_y
        
    pygame.draw.rect(screen, (255, 0, 0), (rect_x,rect_y,10,10), 0) 

    pygame.display.flip()
    clock.tick(30)