def draw(maze, path_list, off=7): win = GraphicsWindow(maze_size * off * 1.2, maze_size * off * 1.2) canvas = win.canvas() cell_size = off # Height and width of checkerboard squares. for i in range( maze_size): # Note that i ranges from 0 through 7, inclusive. for j in range(maze_size): # So does j. cell = maze[i][j] if not cell.ifBlocked: color = 'white' else: color = 'black' canvas.setFill(color) # draw cell_size * cell_size rectangle at point (offset_x + i * cell_size, offset_y + j * cell_size) canvas.drawRect(off + i * cell_size, off + j * cell_size, cell_size, cell_size) ptr = path_list.next while (ptr.next != None): ptr = ptr.next while (ptr != None): current_x = ptr.x current_y = ptr.y canvas.setFill('red') canvas.drawRect(off + current_x * cell_size, off + current_y * cell_size, cell_size, cell_size) # print("path at [{} {}]".format(current_x, current_y)) ptr = ptr.parent win.wait()
def draw(windowSize=1050, off=50): win = GraphicsWindow(windowSize, windowSize) canvas = win.canvas() offset_x = off # Distance from left edge. offset_y = off # Distance from top. cell_size = off # Height and width of checkerboard squares. grid = setup() # start for i in range(31): # Note that i ranges from 0 through 7, inclusive. for j in range(31): # So does j. cell = grid[i][j] if not cell.ifBlocked: color = 'white' else: color = 'black' # if i == 0 and j == 0: # color = 'red' canvas.setFill(color) # draw cell_size * cell_size rectangle at point (offset_x + i * cell_size, offset_y + j * cell_size) canvas.drawRect(offset_x + i * cell_size, offset_y + j * cell_size, cell_size, cell_size) win.wait()
def configureWindow(winSize): win = GraphicsWindow(winSize, winSize) canvas = win.canvas() #canvas.setFill("red") canvas.setBackground(0, 128, 0) return canvas
def on_modified(self, event): # self.process(event) # ('./lol.txt', 'modified') # Verificar conteudo da linha # Caso correcto, limpa canvas e mostra global counter global canvas if str(event.src_path[2:]) in patterns: time.sleep(0.3) for line in fileinput.input(files=event.src_path): cells = arg_as_list(line) if (len(cells) == (n_cells_per_side * n_cells_per_side)): if counter: win = GraphicsWindow(n_cells_per_side * n_pixeis + 1, n_cells_per_side * n_pixeis + 1) win.setTitle("RGB Matrix") canvas = win.canvas() counter = False else: canvas.clear() for i in range(n_cells_per_side * n_cells_per_side): x = int(i / n_cells_per_side) y = i % n_cells_per_side canvas.setColor(cells[i][0], cells[i][1], cells[i][2]) canvas.drawRectangle(x * n_pixeis, y * n_pixeis, n_pixeis, n_pixeis)
def main(): parser = argparse.ArgumentParser('RGB Matrix App') parser.add_argument('-a', action="store", dest="ncps", type=int, help="Matrix side length") parser.add_argument('-b', action="store", dest="np", type=int, help="Num. pixels per cell") parser.add_argument('files', metavar='FILE', nargs='*', help='files to read, if empty, stdin is used. Each line is [[r,g,b],...]') global n_cells_per_side global n_pixeis global filess global patterns if os.path.isfile('RGBMatrixConf.txt') == True: my_file = open('RGBMatrixConf.txt','r') first_line = my_file.readline().rstrip() arglist = first_line.split( ) arglist.extend(sys.argv) res = parser.parse_args(arglist) n_cells_per_side = res.ncps n_pixeis = res.np filess = res.files #print (sys.argv[1], " ", len(sys.argv[1])) if len(sys.argv)>1 and os.path.isfile(sys.argv[1]) == True: patterns.append(sys.argv[1]) observer = Observer() observer.schedule(MyHandler(), path='.') observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join() else: # ler do stdin print ("ler do stdin") for line in sys.stdin: cells = arg_as_list(line) if (len(cells) == (n_cells_per_side*n_cells_per_side)): global counter global canvas if counter: win = GraphicsWindow(n_cells_per_side*n_pixeis+1,n_cells_per_side*n_pixeis+1) win.setTitle("RGB Matrix") canvas = win.canvas() counter = False else: canvas.clear() for i in range(n_cells_per_side*n_cells_per_side): x = int(i/n_cells_per_side) y = i%n_cells_per_side canvas.setColor(cells[i][0],cells[i][1],cells[i][2]) canvas.drawRectangle(x*n_pixeis,y*n_pixeis,n_pixeis,n_pixeis) time.sleep(0.5) else: raise IOError("File RGBMatrixConf.txt doesn't appear to exists.")
def main() : win = GraphicsWindow(WIN_SIZE, WIN_SIZE) canvas = win.canvas() canvas.setOutline("blue") numSides = getNumberSides() while numSides != 0 : canvas.clear() polygon = buildRegularPolygon(POLY_OFFSET, POLY_OFFSET, numSides, POLY_RADIUS) drawPolygon(polygon, canvas) numSides = getNumberSides()
def main(): """Gangen i spillet""" #Initialiser vindu og lerret win = GraphicsWindow(SCREEN_WIDTH,SCREEN_HEIGHT) canvas = win.canvas() #La spilleren velge spillebrett på en egen skjerm før spillet hjemmebane = initiatePreGame(win,canvas) #Spill spillet mainGame(hjemmebane,win,canvas)
def configureWindow(infile): # Extract the window size. width = int(extractNextLine(infile)) height = int(extractNextLine(infile)) # Extract the background color. color = extractNextLine(infile) color = color.strip() # Create the window and set the background color. win = GraphicsWindow(width, height) canvas = win.canvas() canvas.setBackground(color) # Return the window object. return win
from ezgraphics import GraphicsWindow win = GraphicsWindow() win.setTitle("Snømann") canvas = win.canvas() canvas.drawOval(170,20,50,50) canvas.drawOval(145,70,100,100) canvas.drawOval(125,170,150,150) win.wait()
# house.py # # Created by: R. Givens # Modified by: Will Schick # # Date: 2/27/2018 # # This program draws a collection of geometric shapes and text on # graphics canvas to create the appearance of a house. from ezgraphics import GraphicsWindow # Create the window and access the canvas. win = GraphicsWindow(320, 410) win.setTitle("This Little House") canvas = win.canvas() # Draw on the canvas. #House Base canvas.setColor(175, 25, 25) canvas.setOutline(0, 0, 0) canvas.drawRect(10, 135, 300, 300) #Door canvas.setColor(100, 0, 0) canvas.drawRect(60, 235, 80, 200) #Window canvas.setColor(0, 200, 255) canvas.setOutline(0, 0, 0) canvas.drawRect(190, 275, 80, 80) #Window Frames canvas.setColor(0, 0, 0)
# This program attempts to display the scale of the moon, sun, and earth. # 1 pixel = 2158.8 miles (diameter of moon) # distance from earth to moon = 238,900 miles # distance from earth to sun = 92,328,000 miles # # diameter of sun = 865,370 miles # diameter of earth = 7,917.5 miles # diameter of moon = 2,158.8 miles # # given a moon diameter of 1 pixel,you would need a display 42,769 pixels wide. # to show the correct scale. from ezgraphics import GraphicsWindow win = GraphicsWindow(42768.204,600) canvas = win.canvas() canvas.setColor("black") canvas.drawOval(42768.204,300,3.668,3.668) #earth canvas.drawOval(42768.204,410.663,1,1) #moon canvas.drawOval(-300,100,400.857,400.857) #sun win.wait()
# This program displays Turkish flag # Date:08/22/2017 from ezgraphics import GraphicsWindow from math import * flagWidth = int(input("Please enter the width of the flag eg. 100 : ")) flagLength = 1.5 * flagWidth flagA = 0.5 * flagWidth flagB = 0.5 * flagWidth flagC = 1 / 16 * flagWidth flagD = 0.4 * flagWidth flagE = 1 / 3 * flagWidth flagF = 1 / 4 * flagWidth win = GraphicsWindow(flagLength, flagWidth) win.setTitle("Turkish Flag") canvas = win.canvas() #canvas.title('Turkish Flag') canvas.setFill("red") canvas.drawRect(0, 0, flagLength, flagWidth) canvas.setOutline(255, 255, 255) canvas.setFill(255, 255, 255) canvas.drawOval((flagA - flagB / 2), (flagWidth / 2 - flagB / 2), flagB, flagB) canvas.setOutline("red") canvas.setFill("red") canvas.drawOval(flagA + flagC - flagD / 2, flagWidth / 2 - flagD / 2, flagD, flagD)
from ezgraphics import GraphicsWindow win = GraphicsWindow(600, 600) win.setTitle("My House") can = win.canvas() can.setFill("green") can.drawRect(0, 150, 200, 20) can.setFill("red") can.drawRect(50, 50, 100, 100) can.setFill("white") can.drawRect(60, 90, 24, 24) can.drawLine(60, 102, 85, 102) can.drawLine(72, 90, 72, 114) can.setFill("brown") can.drawRect(100, 100, 25, 50) can.drawPoly(100, 0, 50, 50, 150, 50)
def Countdown_Calculations(): #does the mafs! and plots the visuals '''time used to display bars''' time_in_seconds = final_time ###error of one minute '''Create the Window''' win = GraphicsWindow(750, 400) win.setTitle("Liam's Clock") canvas = win.canvas() canvas.setBackground(0, 0, 0) ######################################################################### ## Seconds delay## seconds_remainder = time_in_seconds - int(time_in_seconds) #print (seconds_remainder) seconds = (60 * seconds_remainder) #convert to seconds as 59 seconds is nearly a min and will not be accurate #print (int(seconds)) ## LOADING SCREEN ## canvas.setColor("green") #set colour of text canvas.drawText(340, 200, " LOADING ...") ##waits for number of seconds to ensure that it is accurate in mins and hours and days### time.sleep(int(seconds)) ################################################################################### ##### START COUNTDOWN CLOCK ####################################### '''draw titles''' canvas.setColor("white") canvas.drawText(30, 120, "Days") canvas.drawText(30, 220, "Hours") canvas.drawText(30, 320, "Minutes") '''draw remain titles''' canvas.drawText(100, 40, "TIME REMAINING: ") canvas.drawText(240, 40, "DAYS ") canvas.drawText(320, 40, "HOURS ") canvas.drawText(420, 40, "MINUTES ") while time_in_seconds > 0: #print ("remaining seconds", time_in_seconds) #print ("") #days# days = int(time_in_seconds/86400) print ("Days", days) #hours# hours = int((time_in_seconds - (days * 86400))/3600) print ("Hours", hours) #time.sleep(3) #minutes# minutes = int((time_in_seconds - ((hours * 3600) + (days * 86400)))/60) print ("Minutes", minutes) ######################################################################################### #Days# '''Create Day Graphic'''#left dis. top dis, rec_size '''Add Title''' canvas.setColor("green") #set colour canvas.drawRectangle(98, 100, 602, 50) '''add the hours''' canvas.setColor("red") #set colour canvas.drawRectangle(98, 100, (days * 86), 50) canvas.drawText(280, 40, str(days)) ########################################################################################## #Hours# '''Create Hour Graphic'''#left dis. top dis, rec_size '''Add Title''' #canvas.drawText(30, 70, "Hours") canvas.setColor("green") #set colour canvas.drawRectangle(100, 200, 600, 50) '''add the hours''' canvas.setColor("orange") #set colour canvas.drawRectangle(100, 200, (hours * 25), 50) canvas.drawText(370, 40, str(hours)) ############################################################################################## #Minutes# '''Create Minutes Graphic'''#left dis. top dis, rec_size '''Add Title''' #canvas.drawText(30, 220, "Minutes") canvas.setColor("green") #set colour canvas.drawRectangle(100, 300, 600, 50) '''add the hours''' canvas.setColor("blue") #set colour canvas.drawRectangle(100, 300, (minutes * 10), 50) canvas.drawText(480, 40, str(minutes)) '''wait for 60 seconds before looping''' time_in_seconds = time_in_seconds - 60 time.sleep(60) ############################################################################### #clear the previous text values##### '''clear time values to avoid over writting: overwrite in black''' canvas.setColor("black") #set colour canvas.drawText(280, 40, str(days)) canvas.setColor("black") #set colour canvas.drawText(370, 40, str(hours)) canvas.setColor("black") #set colour canvas.drawText(480, 40, str(minutes)) #canvas.drawText(400, 70, "TIME UP") #canvas.setColor("orange") #canvas.drawRectangle(100, 200, 600, 50) canvas.setBackground(255, 255, 255) canvas.setColor("white") #set colour canvas.drawText(340, 220, "TIME UP")
from ezgraphics import GraphicsWindow, GraphicsImage GAP = 10 NUM_PICTURES = 20 MAX_WIDTH = 720 win = GraphicsWindow(MAX_WIDTH, 700) canvas = win.canvas() pic = GraphicsImage("picture1.gif") canvas.drawImage(0, 0, pic) x = 0 for i in range(2, NUM_PICTURES + 1): previous = pic filename = "picture%d.gif" % i pic = GraphicsImage(filename) x = x + previous.width() + GAP canvas.drawImage(x, 0, pic) win.wait()
from ezgraphics import GraphicsWindow from time import sleep vindu = GraphicsWindow() lerret = vindu.canvas() x = 10 y = 10 while y < 200: lerret.clear() lerret.drawRect(x, y, 50, 50) y += 1 sleep(0.01)
x = track.x y = track.y if (not map_info[x][y].isBlocked): detect(map_info[x][y], maze, map_info) position = track path.push(position.x, position.y) track = track.parent else: break # need to complete return position if __name__ == "__main__": counter = 0 maze = setup() win = GraphicsWindow(size * 10 * 1.2, size * 10 * 1.2) canvas = win.canvas() cell_size = 10 main_F() print("repeated forward: {}".format(counter)) win.wait() win = GraphicsWindow(size * 10 * 1.2, size * 10 * 1.2) canvas = win.canvas() main_B() print("repeated backward: {}".format(counter)) win.wait()
""" Dette programmet importerer GraphicsWndow, og bruker det til aa lage et vindu med et lerret, tegne en roed sirkel og vente paa at brukeren lukker vinduet. """ from ezgraphics import GraphicsWindow vindu = GraphicsWindow(500, 500) lerret = vindu.canvas() lerret.setOutline("red") sirkel = lerret.drawOval(50, 50, 400, 400) vindu.wait()
#CIS_40 Johnny To from ezgraphics import GraphicsWindow win = GraphicsWindow(800, 500) canvas = win.canvas() canvas.setOutline("blue") canvas.setFill() canvas.setLineWidth(10) canvas.drawOval(100, 100, 200, 200) canvas.setOutline("black") canvas.drawOval(310, 100, 200, 200) canvas.setOutline("red") canvas.drawOval(520, 100, 200, 200) canvas.setOutline("yellow") canvas.drawOval(200, 200, 200, 200) canvas.setOutline("green") canvas.drawOval(410, 200, 200, 200)
from ezgraphics import GraphicsWindow fillname = ('black', 'white') window = GraphicsWindow() canvas = window.canvas() width= canvas.width() height = canvas.height() colorWhite = 0 for delta in range (0, width // 2, 40): canvas.setFill(fillname[colorWhite]) canvas.drawOval(delta , delta, width - 2 * delta, height - 2 * delta) colorWhite = not colorWhite window.wait()
A = int(input(r"Please enter the Hoist (height) of the US flag (eg: 400) :")) # dimensions of the flag flagHeight = A flagWidth = 1.9 * flagHeight flagC = flagHeight * 7 / 13 flagD = flagWidth * 2 / 5 flagE = flagC / 10 flagF = flagE flagG = flagD / 12 flagH = flagG flagL = flagHeight / 13 StarK = flagL * 4 / 5 win = GraphicsWindow(flagWidth, flagHeight) canvas = win.canvas() win.setTitle("US Flag") # the stripes are being drawn for i in range(13): canvas.setColor("white") if (i % 2) == 0: canvas.setColor(191, 10, 48) canvas.drawRect(0, i * flagL, flagWidth, flagL) # The canton part canvas.setFill(0, 40, 104) canvas.drawRect(0, 0, flagD, flagC) posOfStarsX = []
""" 03.09: Flere sirkler """ import math from ezgraphics import GraphicsWindow from ezgraphics import GraphicsCanvas win = GraphicsWindow(500, 500) window = win.canvas() for i in range(50): window.drawOval(i * 10, math.sin(i) * 40 + 200, 20, 20) win.wait()
## # This program draws two Italian flags using the geometric shape classes. # from ezgraphics import GraphicsWindow from shapes import Rectangle, Line, Group # Define constants for the flag size. FLAG_WIDTH = 150 FLAG_HEIGHT = FLAG_WIDTH * 2 // 3 PART_WIDTH = FLAG_WIDTH // 3 # Create the graphics window. win = GraphicsWindow(300, 300) canvas = win.canvas() # Build the flag as a group shape. flag = Group() part = Rectangle(0, 0, PART_WIDTH, FLAG_HEIGHT) part.setColor("green") flag.add(part) part = Rectangle(PART_WIDTH * 2, 0, PART_WIDTH, FLAG_HEIGHT) part.setColor("red") flag.add(part) flag.add(Line(PART_WIDTH, 0, PART_WIDTH * 2, 0)) flag.add(Line(PART_WIDTH, FLAG_HEIGHT, PART_WIDTH * 2, FLAG_HEIGHT)) # Draw the first flag in the upper-left area of the canvas.
quarter = changeDue // PENNIES_PER_QUARTER print("Dollar coin: %4d" % (dollarCoin)) print("Quarter coin: %4d" %(quarter)) # In class practise for EZGRAPHICS from ezgraphics import GraphicsWindow win = GraphicsWindow(400, 200) # width and height canvas = win.canvas() #drawing practise starts from here #draw on canvas canvas.setColor("red") # choosing color canvas.drawRect(0, 10, 200, 10) # x position, y position, width, height #making a green square canvas.Color("green") canvas.drawRect(0, 30, 50, 50) #putting a blue square inside green square
## # This program draws three colored rectangles on a canvas. # from ezgraphics import GraphicsWindow # Create the window and access the canvas. win = GraphicsWindow(400, 200) canvas = win.canvas() # Draw on the canvas. canvas.setColor("red") canvas.drawRect(0, 10, 200, 10) canvas.setColor("green") canvas.drawRect(0, 30, 300, 10) canvas.setColor("blue") canvas.drawRect(0, 50, 100, 10) # Wait for the user to close the window. win.wait()
A = 400 # dimensions of the flag flagHeight = A flagWidth = 1.9 * flagHeight flagC = flagHeight * 7 / 13 flagD = flagWidth * 2 / 5 flagE = flagC / 10 flagF = flagE flagG = flagD / 12 flagH = flagG flagL = flagHeight / 13 StarK = flagL * 4 / 5 us = GraphicsWindow(flagWidth, flagHeight) canvas = us.canvas() # the stripes are being drawn for i in range(13): canvas.setColor("white") if (i % 2) == 0: canvas.setColor(191, 10, 48) canvas.drawRect(0, i * flagL, flagWidth, flagL) # The canton part canvas.setFill(0, 40, 104) canvas.drawRect(0, 0, flagD, flagC) canvas.setColor("white")
from ezgraphics import GraphicsWindow win = GraphicsWindow() canvas = win.canvas() canvas.drawRect(100, 100, 50, 50) canvas.drawRect(75, 150, 100, 100) win.wait()
''' Dette programmet bruker modulen ezgraphics for å tegne sirkler i et grafisk vindu. ''' from ezgraphics import GraphicsWindow win = GraphicsWindow() win.setTitle("Kult sirkelprogram") can = win.canvas() can.setBackground(50,125,250) count = 0 x_pos = 10 stoerrelse = 50 # While løkken går 9 ganger, og tegner en sirkel for hver gang. #jeg la til listen col, med ulike verdier for fargene R,G,B for litt ekstra spice col=[255,0,0] while count < 9: can.setOutline(col[0],col[1],col[2]) can.drawOval(x_pos, 100, stoerrelse, stoerrelse) #Størrelse øker med 5 for hver gang, x_pos øker med 20 count +=1 x_pos += 20 stoerrelse += 5 #Fargene til hver sirkel endres col[0]-=25 col[1]+=25 win.wait()
# Obtain number of rings in the target. numRings = int(input("Enter # of rings in the target: ")) while numRings < MIN_NUM_RINGS or numRings > MAX_NUM_RINGS: print("Error: the number of rings must be between", MIN_NUM_RINGS, "and", MAX_NUM_RINGS) numRings = int(input("Re-enter # of rings in the target: ")) # Determine the diameter of the outermost circle. It has to be drawn first. diameter = (numRings + 1) * RING_WIDTH * 2 # Determine the size of the window based on the size of the outer circle. winSize = diameter + 2 * TARGET_OFFSET # Create the graphics window and get the canvas. win = GraphicsWindow(winSize, winSize) canvas = win.canvas() # Use a light gray background for the canvas. canvas.setBackground("light gray") # Draw the rings, alternating between black and white. x = TARGET_OFFSET y = TARGET_OFFSET for ring in range(numRings): if ring % 2 == 0: canvas.setColor("black") else: canvas.setColor("white") canvas.drawOval(x, y, diameter, diameter)
#Oppg.3.1. lage grafikkvindu win og kanvas can. from ezgraphics import GraphicsWindow win = GraphicsWindow(500, 500) can = win.canvas() #Oppg.3.2. Oppretter to variabler: teller = 0 og x_pos = 10. teller = 0 x_pos = 10 #Oppg.3.3. while-lokke, for teller<9 #while teller <9: # can.drawOval(x_pos, 100, 50, 50) # teller+=1 # x_pos+=10 #Oppg.3.4. stoerrelsen paa sirklene er avhengig av variablen stoerrelse, #som oker med 5 for hver runde i while-lokken. stoerrelse = 100 while teller < 9: can.drawOval(x_pos, 100, stoerrelse, stoerrelse) teller += 1 x_pos += 6 stoerrelse += 5