コード例 #1
0
ファイル: playerclass.py プロジェクト: entiri/Battleship
    def update_boards(self, x, y):
        ''' (self, x, y) -> NoneType
        Given an x and a y coordinate, turn the cooresponding board co-ordinate
        red if it is a hit, or white if it is a miss.
        '''
        # tuple holding coordinates of attack
        coordinates = (x, y)

        # If attack coordinates correspond to a point at which
        # a ship is occupying on the opponent board, draw a red square.
        # if it doesn't, draw a white square.
        if coordinates not in self.opp_list:
            media.add_rect_filled(self.boards[1], x * 25 + 10,\
                                  y * 25 + 10, 25, 25, media.white)
        else:
            media.add_rect_filled(self.boards[1], x * 25 + 10,\
                                  y * 25 + 10, 25, 25, media.red)

        # Draw player's board using opponent's last move.
        # A white block is drawn if they missed, a red block if they hit.
        if self.attack != []:
            if self.attack[-1] not in self.coordinates:
                media.add_rect_filled(self.boards[0], self.attack[-1][0] * 25\
                                      + 10, self.attack[-1][1] * 25 + 10, 25,\
                                      25, media.white)
            else:
                media.add_rect_filled(self.boards[0], self.attack[-1][0] * 25\
                                      + 10, self.attack[-1][1] * 25 + 10, 25,\
                                      25, media.red)

        media.show(self.boards[0])
        media.show(self.boards[1])
コード例 #2
0
ファイル: e1.py プロジェクト: Zhaeong/School
def copyright():
    pic=media.create_picture(20,20)
    black=media.black
    media.add_oval(pic,0,0,16,16,black)
    media.add_text(pic, 6,3,"C",black)
    media.show(pic)
    return pic
コード例 #3
0
ファイル: e1.py プロジェクト: Zhaeong/School
def copyright():
    pic = media.create_picture(20, 20)
    black = media.black
    media.add_oval(pic, 0, 0, 16, 16, black)
    media.add_text(pic, 6, 3, "C", black)
    media.show(pic)
    return pic
コード例 #4
0
ファイル: loop.py プロジェクト: auroua/test
def pic_process():
    pic = media.load_image("/home/auroua/workspace/lena.jpg")
    width,height = media.get_width(pic),media.get_height(pic)
    for x in range(0,height,2):
        for y in range(0,width+1):
            p = media.get_pixel(pic,x,y)
            media.set_color(p,media.black)

    media.show(pic)
コード例 #5
0
ファイル: e1.py プロジェクト: Zhaeong/School
def moderate_blue(pic):
    new_pic=media.copy(pic)
    for pix in new_pic:
        red=media.get_red(pix)
        green=media.get_green(pix)
        red1=int(red)
        green1=int(green)
        modblue=(red1+green1)/2
        media.set_blue(pix, modblue)
        media.show(new_pic)
    return new_pic
コード例 #6
0
ファイル: e1.py プロジェクト: Zhaeong/School
def moderate_blue(pic):
    new_pic = media.copy(pic)
    for pix in new_pic:
        red = media.get_red(pix)
        green = media.get_green(pix)
        red1 = int(red)
        green1 = int(green)
        modblue = (red1 + green1) / 2
        media.set_blue(pix, modblue)
        media.show(new_pic)
    return new_pic
コード例 #7
0
ファイル: playerclass.py プロジェクト: entiri/Battleship
    def draw_board(self):
        '''(self) -> NoneType
        draw player board and opponent board and return in list'''

        # Each space will be 25 pixels long, with a 10 pixel border on top
        board_l = self.l * 25 + 10
        # Each space will be 25 pixels wide, with a 10 pixel border on the side
        board_w = self.w * 25 + 10

        list_boards = []   # list holding boards

        # Draw player's board
        board_player = media.create_picture(board_w, board_l, media.navy)

        # Draw opponent's board
        board_opponent = media.create_picture(board_w, board_l, media.gray)

        list_boards.append(board_player)   # Add player board to list
        list_boards.append(board_opponent)  # Add opponent board to list

        for item in list_boards:  # loop through list of boards to add borders
            # Draw bar along top
            media.add_rect_filled(item, 0, 0, 10, board_l, media.white)
            media.add_rect_filled(item, 0, 0, board_w, 10, media.white)
            counter = 0  # counter for while loop to draw numbers to board
            while counter < self.w:  # loop to draw x coordinates on board
                temp = str(counter)
                x_val = (counter) * 25 + 10
                media.add_text(item, x_val, 2, temp, media.black)
                counter += 1
            counter = 0
            while counter < self.l:  # draw y coordinates on board
                temp = str(counter)
                y_val = (counter) * 25 + 10
                media.add_text(item, 2, y_val, temp, media.black)
                counter += 1

        # Loop through list of player ships to place them on board
        for item in self.coordinates:
            media.add_rect_filled(list_boards[0], item[0] * 25 + 10,\
                                  item[1] * 25 + 10, 25, 25, media.gray)
        media.show(list_boards[0])
        media.show(list_boards[1])

        self.boards = list_boards
コード例 #8
0
def play_game(tree_size):
    '''Play the rotation game with tree_size nodes in the tree.'''

    # Blank the screen and make the trees.
    media.add_rect_filled(pic, 0, 0, 400, 400, media.white)
    game_tree = random_tree(tree_size)
    target_tree = random_tree(tree_size)

    # Draw the new trees; the current node is initially the root.
    curr = game_tree.root
    draw(pic, game_tree.root, 0, 0, curr)
    draw(pic, target_tree.root, 0, WIDTH / 2, curr)
    media.show(pic)

    # Ask for user operations until the game tree and target tree are the
    # same.
    while game_tree != target_tree:
        curr = process_user_command(game_tree, target_tree, curr, pic)
        assert bst.is_valid_tree(game_tree.root)
コード例 #9
0
# -*- 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)
コード例 #10
0
ファイル: 4-6.py プロジェクト: lujun9972/python-practice
import media
f = media.choose_file()
pic = media.load_picture(f)
media.show(f)
media.show(f)
コード例 #11
0
ファイル: open_pic.py プロジェクト: chaubeau/Python
# -*- 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)
コード例 #12
0
ファイル: PP_Ch_06_B.py プロジェクト: hazza1999/ECP3004S21
def is_dinosaur(name):
    '''
    Return True if the named creature is recognized as a dinosaur,
    and False otherwise.
    '''
    return name in ['Tyrannosaurus', 'Triceratops']
if __name__ == '__main__':
    help(__name__)

 

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

 

 
...
----------------------------------------------------------------------
Ran 3 tests in 0.002s

OK

 

 
media.crop_picture(pic, 150, 50, 450, 300)
media.show(pic)
コード例 #13
0
import media
lake = media.load_picture('lake.png')
width, height = media.get_width(lake), media.get_height(lake)
for y in range(0, height, 2): # Skip odd-numbered lines
    for x in range(0, width):
        p = media.get_pixel(lake, x, y)
        media.set_color(p, media.black)
media.show(lake)
コード例 #14
0
ファイル: show_madeleine.py プロジェクト: Bambina/learning-py
import media

pic1 = media.load_picture('pic207.jpg')
media.show(pic1)
pic2 = media.load_picture('pic207cropped.jpg')
media.show(pic2)
pic3 = media.load_picture('pic207named.jpg')
media.show(pic3)
コード例 #15
0
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)