Esempio n. 1
0
File: e1.py Progetto: Zhaeong/School
def same_dimensions():
    filename = media.choose_file()
    pic = media.load_picture(filename)
    filename2 = media.choose_file()
    pic2 = media.load_picture(filename2)

    h1 = media.get_height(pic)
    w1 = media.get_width(pic)
    h2 = media.get_height(pic2)
    w2 = media.get_width(pic2)
    if h1 == h2 and w1 == w2:
        print "true"
    else:
        print "false"
Esempio n. 2
0
File: e1.py Progetto: Zhaeong/School
def same_dimensions():
    filename = media.choose_file()
    pic = media.load_picture(filename)
    filename2 = media.choose_file()
    pic2 = media.load_picture(filename2)
    
    h1=media.get_height(pic)
    w1=media.get_width(pic)
    h2=media.get_height(pic2)
    w2=media.get_width(pic2)
    if h1==h2 and w1==w2:
        print "true"
    else:
        print "false"
Esempio n. 3
0
def open_pic(label):
    '''Prompt for a Picture file, load that picture, and display it in Label
    label.'''
    
     # Keep a reference to the picture so it can be modified.
    label.picture = media.load_picture(media.choose_file())
    update_label(label)
Esempio n. 4
0
def open_pic_GUI (label):
    '''Prompt for a Picture file, load that picture, and display it in Label
    label.'''
    #Clear all the temp pics in front of the current pic current_pic
    global temp_label
    global current_pic
    temp_label = temp_label[0:current_pic+1]
    #This function is based on label_image.py
    label.picture = media.load_picture(media.choose_file())
    #Keep a copy of the current pic for the functions Undo and Redo
    temp_label.append(label.picture)
    current_pic += 1
    #Update the label
    update_label(label)
Esempio n. 5
0
def problem_42(score):
    '''The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word.

Using words.txt (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words, how many are triangle words?'''
    words = words_in_file(media.choose_file())
    
    #Counts the number of triangle words in the file
    count = 0
    for word in words:
        if is_triangle_word(remove_quotes(word), score):
            count += 1
    print count
Esempio n. 6
0
def problem_22(score):
    '''Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.

For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938  53 = 49714.

What is the total of all the name scores in the file?'''
    filename = media.choose_file()
    names = sort_names(filename)
    
    total_scores = 0
    
    #Remember that the score of a name is (position of name in score) x (letter_score)
    for i in range(1, len(names) + 1):
        total_scores += (i * calculate_name_score_letter(names[i - 1], score))
        
    print total_scores
Esempio n. 7
0
File: a2.py Progetto: Zhaeong/School
def main_human_versus_computer():
    '''() -> NoneType
    Play the game with a single player vs. the computer.'''
    	
    filename = media.choose_file()
    symbol_board_player = get_symbol_board(filename)
    view_board_player = get_view_board()
    hits_player = SIZES[:]
    
    symbol_board_computer = make_computer_board()
    view_board_computer = get_view_board()
    hits_computer = SIZES[:]
    
    player_turn = True

    while not is_win(hits_player) and not is_win(hits_computer):
		
	if player_turn:	    
	    symbol_board = symbol_board_computer
	    view_board = view_board_computer
	    print "Player 1's turn:"
	    display_board(view_board_computer)
	    [row, col] = make_move(view_board_computer)
	    hits_list = hits_player
	else:
	    symbol_board = symbol_board_player
	    view_board = view_board_player
	    print "Computer's turn: "
	    display_board(view_board_player)
	    #display_board(symbol_board_player)
	    [row, col] = make_computer_move(view_board_player)
	    hits_list = hits_computer
	    
    
	hit = is_hit(row, col, symbol_board, hits_list)
	display_hit_message(hit)
  
	update_board(row, col, view_board, symbol_board)
	display_board(view_board)
	raw_input('Please enter to continue... ')
	player_turn = not player_turn
	
    if is_win(hits_player):
	print 'You won in %d moves!' % (get_num_moves(view_board_computer))
    else:
	print 'The computer won in %d moves.  Please try again' % \
	      (get_num_moves(view_board_player))
Esempio n. 8
0
File: a2.py Progetto: Zhaeong/School
def main_human_versus_computer():
    '''() -> NoneType
    Play the game with a single player vs. the computer.'''

    filename = media.choose_file()
    symbol_board_player = get_symbol_board(filename)
    view_board_player = get_view_board()
    hits_player = SIZES[:]

    symbol_board_computer = make_computer_board()
    view_board_computer = get_view_board()
    hits_computer = SIZES[:]

    player_turn = True

    while not is_win(hits_player) and not is_win(hits_computer):

        if player_turn:
            symbol_board = symbol_board_computer
            view_board = view_board_computer
            print "Player 1's turn:"
            display_board(view_board_computer)
            [row, col] = make_move(view_board_computer)
            hits_list = hits_player
        else:
            symbol_board = symbol_board_player
            view_board = view_board_player
            print "Computer's turn: "
            display_board(view_board_player)
            #display_board(symbol_board_player)
            [row, col] = make_computer_move(view_board_player)
            hits_list = hits_computer

        hit = is_hit(row, col, symbol_board, hits_list)
        display_hit_message(hit)

        update_board(row, col, view_board, symbol_board)
        display_board(view_board)
        raw_input('Please enter to continue... ')
        player_turn = not player_turn

    if is_win(hits_player):
        print 'You won in %d moves!' % (get_num_moves(view_board_computer))
    else:
        print 'The computer won in %d moves.  Please try again' % \
              (get_num_moves(view_board_player))
Esempio n. 9
0
File: a2.py Progetto: Zhaeong/School
def main_human_no_opponent():
    '''() -> NoneType
    A single player game with no opponent.  This exists for testing purposes.'''

    filename = media.choose_file()
    symbol_board = get_symbol_board(filename)
    view_board = get_view_board()
    display_board(view_board)
    hits_list = SIZES[:]

    while not is_win(hits_list):

        [row, col] = make_move(view_board)

        hit = is_hit(row, col, symbol_board, hits_list)
        display_hit_message(hit)

        update_board(row, col, view_board, symbol_board)
        display_board(view_board)

    print 'You won in %d moves!' % (get_num_moves(view_board))
Esempio n. 10
0
File: a2.py Progetto: Zhaeong/School
def main_human_no_opponent():
    '''() -> NoneType
    A single player game with no opponent.  This exists for testing purposes.'''
	
    filename = media.choose_file()
    symbol_board = get_symbol_board(filename)
    view_board = get_view_board()
    display_board(view_board)
    hits_list = SIZES[:]
	
    while not is_win(hits_list):
		
	[row, col] = make_move(view_board)
		
	hit = is_hit(row, col, symbol_board, hits_list)
	display_hit_message(hit)
	    
	update_board(row, col, view_board, symbol_board)
	display_board(view_board)
    
    print 'You won in %d moves!' % (get_num_moves(view_board))
# -*- coding: utf-8 -*-

import media

pic = media.load_picture(media.choose_file())
media.show(pic)

for p in media.get_pixels(pic):
    new_green = int(0.5 * media.get_green(p))
    media.set_green(p, new_green)

media.show(pic)
Esempio n. 12
0
import media
f = media.choose_file()
pic = media.load_picture(f)
media.show(f)
media.show(f)
Esempio n. 13
0
# -*- coding:utf-8 -*-
#
#  Date: 2014-03-20 18:01:09
#
#  Copyright 2014 chaubeau <*****@*****.**>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  Desc :
#

import media

f = media.choose_file()

pic = media.load_picture(f)

media.show(pic)
Esempio n. 14
0
    return new_pic


def flip(pic):
    '''(Pic) -> Picture 
    Return a new picture that contains the pixels of the original picture flipped across the vertical axis.'''

    copy = media.copy(pic)
    max_x = media.get_width(pic)
    max_y = media.get_height(pic)

    for x in range(max_x / 2):
        for y in range(max_y):
            originalpix = copy.get_pixel(x, y)
            reversepix = copy.get_pixel((max_x - x - 1), y)
            color = media.get_color(originalpix)
            reversecolor = media.get_color(reversepix)
            media.set_color(originalpix, reversecolor)
            media.set_color(reversepix, color)
    return copy


if __name__ == "__main__":
    pic = media.create_picture(50, 50, media.red)
    pic.inspect()
    pic2 = media.create_picture(50, 50, media.blue)
    pic2.inspect()
    str1 = 'redundancy'
    str2 = 'redundancy'
    filename = media.choose_file()
    mypic = media.load_picture(filename)
Esempio n. 15
0
File: a1.py Progetto: Zhaeong/School
    '''(Pic) -> Picture 
    Return a new picture that contains the pixels of the original picture flipped across the vertical axis.'''
    
    copy  = media.copy(pic)
    max_x = media.get_width(pic)
    max_y = media.get_height(pic)
    
    for x in range(max_x/2):
        for y in range(max_y):
            originalpix = copy.get_pixel(x,y)
            reversepix  = copy.get_pixel((max_x - x - 1), y)
            color = media.get_color(originalpix)
            reversecolor = media.get_color(reversepix)
            media.set_color(originalpix,reversecolor)
            media.set_color(reversepix,color)
    return copy
    

        

    

if __name__ == "__main__":
    pic = media.create_picture(50, 50, media.red)
    pic.inspect()
    pic2 = media.create_picture(50, 50, media.blue)
    pic2.inspect()
    str1 = 'redundancy'
    str2 = 'redundancy'
    filename = media.choose_file()
    mypic = media.load_picture(filename)
import media

def chromakey(person, background):
    '''Replace blue pixels in the person picture with the corresponding
    pixels in the background picture.  The pictures must have the same dimensions.'''
    
    colour = media.get_color(media.get_pixel(person, 60, 60))
    for p in person:
		# 42 is a guess. Other values might work much better.
        if media.distance(media.get_color(p), colour) < 42:
            x = media.get_x(p)
            y = media.get_y(p)
            background_px = media.get_pixel(background, x, y)
            media.set_color(p, media.get_color(background_px))

if __name__ == '__main__':
    pic1 = media.load_picture(media.choose_file())
    #media.show(pic1)
    pic2 = media.load_picture(media.choose_file())
    #media.show(pic2)
    chromakey(pic1, pic2)
    media.show(pic1)