def __init__(self, width=500, height=400, color="white", title="Simulated World"): self._canvas = Canvas(width, height, color, title) self._canvas.setAutoRefresh(False) self._star = None self._controller = None self._timestamp = 0
def __init__(self, states, width=950): ratio = 0.5263 self._canvas = Canvas(width, ratio * width) self._canvas.setTitle('United States') self._states = {} # map from abbrev to RenderedState bounds = None self._canvas.setAutoRefresh(False) for s in states: rendered = _RenderedState(s) self._canvas.add(rendered) self._states[s.abbrev()] = rendered bounds = _mergeBounds(rendered.getBounds(), bounds) self._canvas.zoomView(width / 950.0, Point(0, 0)) self._canvas.setAutoRefresh(True)
class Country: def __init__(self, states, width=950): ratio = 0.5263 self._canvas = Canvas(width, ratio * width) self._canvas.setTitle('United States') self._states = {} # map from abbrev to RenderedState bounds = None self._canvas.setAutoRefresh(False) for s in states: rendered = _RenderedState(s) self._canvas.add(rendered) self._states[s.abbrev()] = rendered bounds = _mergeBounds(rendered.getBounds(), bounds) self._canvas.zoomView(width / 950.0, Point(0, 0)) self._canvas.setAutoRefresh(True) # self._canvas.setView(Point(bounds[0],bounds[3]), Point(bounds[1],bounds[2])) def setTitle(self, title): """Set the Canvas title to the given string.""" self._canvas.setTitle(title) def setFillColor(self, stateCode, color): """Set the fill color of the state with given abbreviation to the indicated color.""" if not isinstance(stateCode, str): raise TypeError('state code must be a string') if stateCode not in self._states: raise ValueError('unknown state code: ' + stateCode) self._states[stateCode].setFillColor(color)
def __init__(self, width, height, bgColor, title): self.frame = Canvas(width, height, bgColor, title)
class Frame: def __init__(self, width, height, bgColor, title): self.frame = Canvas(width, height, bgColor, title) # constructs a new Frame object def getWidth(self): return self.frame.getWidth() # returns the width of the Frame def getHeight(self): return self.frame.getHeight() # returns the height of the Frame def setWidth(self, width): self.frame.setWidth(width) # sets a new width for the Frame def setHeight(self, height): self.frame.setHeight(height) # sets a new height for the Frame def add(self, obj): self.frame.add(obj) # adds a new object to the Frame def getContents(self): return self.frame.getContents() def close(self): self.frame.close() def wait(self): self.frame.wait() def remove(self, obj): self.frame.remove(obj) def setTitle(self, title): self.frame.setTitle(title)
#-*- encoding: utf-8 -*- from cs1graphics import Canvas, Layer, Rectangle, Image, Text, Circle, Point import os import sys import random as rd from time import sleep paper = Canvas() paper.setWidth(1000) # 가로 paper.setHeight(600) # 세로 paper.setBackgroundColor("skyblue") console_clear = "cls" if os.name == "nt" else "clear" def execute(): global paper paper.clear() os.system(console_clear) ##################################################### Main = Layer() start = Rectangle(200, 100, Point(275, 450)) start.setFillColor('yellow') Main.add(start) way = Rectangle(200, 100, Point(525, 450)) way.setFillColor('yellow') Main.add(way) paper.add(Main) Man = Layer() man = Image("python/man.png")
class World: def __init__(self,width=500,height=400,color="white",title="Simulated World"): self._canvas = Canvas(width,height,color,title) self._canvas.setAutoRefresh(False) self._star = None self._controller = None self._timestamp = 0 def getWidth(self): return self._canvas.getWidth() def getHeight(self): return self._canvas.getHeight() def setController(self,controller): self._controller = controller def getGravity(self): if self._controller: return self._controller.getGravity() else: return 0.0 def getStar(self): return self._star def _setStar(self,star): if (self._star): self._canvas.remove(star) self._star = star star.setDepth(0) self._canvas.add(star) self._canvas.refresh() def add(self,updatable): try: updatable.advance # note this is not a call, just a check to see if advance exists except: raise StandardError, "You may only add objects which support an appropriate 'advance' method" self._timestamp += 1 updatable.setDepth(self._timestamp) self._canvas.add(updatable) self._canvas.refresh() def remove(self, obj): self._canvas.remove(obj) def numObj(self): return len(self._canvas.getContents()) def _mainloop(self): more = True while more: # global debug # if debug: # print "within world's mainloop" objects = self._canvas.getContents() # latest list of objects for obj in objects: obj.advance(self) self._canvas.refresh() if self._controller: more = self._controller.processDelay(self)
from random import shuffle from cs1graphics import Canvas, Text, Image img_path = "./images/" suit_names = ['Clubs', 'Diamonds', 'Hearts', 'Spades'] face_names = [ 'Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King' ] value = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10] bj_board = Canvas(600, 400, 'dark green', 'Blackjack') class Card: def card_string(self): return self.face + " of " + self.suit def create_deck(): deck = [] for suit in suit_names: for i in range(len(face_names)): card = Card() card.suit = suit card.face = face_names[i] card.value = value[i] card.image = Image(img_path + suit + "_" + face_names[i] + ".png") card.hidden = False deck.append(card) shuffle(deck) return deck
def resource_path(relative_path): """ Get absolute path to resource, works for dev and for PyInstaller """ try: # PyInstaller creates a temp folder and stores path in _MEIPASS base_path = sys._MEIPASS except Exception: base_path = os.path.abspath(".") return os.path.join(base_path, relative_path) ################################## Initializing Variables ################################## paper = Canvas() userName = givenNumber = predictedNumber = "" balls = strikes = tries = 0 console_clear = "cls" if os.name == "nt" else "clear" ##################################### Display Functions ##################################### def image_set(name_image): # 이미지 기본 셋팅 global paper name_image.moveTo(400, 300) name_image.setDepth(50) paper.add(name_image) def displayFix(name_image): #고정멘트 이미지 추가