Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
def configureWindow(winSize):

    win = GraphicsWindow(winSize, winSize)
    canvas = win.canvas()
    #canvas.setFill("red")
    canvas.setBackground(0, 128, 0)
    return canvas
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
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.")
Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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")

# the 6 star row of the canton
Ejemplo n.º 10
0
"""
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()
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
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
canvas.Color("blue")
canvas.drawRect(0, 50, 25, 25)
Ejemplo n.º 13
0
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()
Ejemplo n.º 14
0
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")        
Ejemplo n.º 15
0
    Created on Mon Jun 17 15:23:20 2019
    Description: This program will output a greeting of my choice.
    Notes: This is my twenty-second python programming project. From the book Python for
            everyone 2nd edition (Wiley). You do not have permission to use this
            code for your school work. 
    Creator: Kevin Gonzalez
"""

from ezgraphics import GraphicsWindow
import math

#variable for the program
userInputWidth = int(input("Enter a width for a rectangle: "))
userInputLength = int(input("Enter a length for a rectangle: "))
diagonalOfRect = math.sqrt(userInputLength**2 + userInputWidth**2)
perimeterRect = userInputLength * 2 + userInputWidth * 2
areaRect = userInputLength * userInputWidth

#Create a new window
newWindow = GraphicsWindow(400, 200)
canvas = newWindow.canvas()

#Draw on canvas
canvas.drawText(
    20, 20, "The area of your rectangle is: " + str(areaRect) +
    "\nThe perimeter of your triangle is: " + str(perimeterRect) +
    "\nThe length of the diagonal of your rectangle is: " +
    str(diagonalOfRect))

#Wait for user to close window
newWindow.wait()
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
#Skriv et program som tar imot koordinater, høyde og bredde, og legger dem i en
#liste. Bruk innholdet i listen til å tegne en form.

from ezgraphics import GraphicsWindow

Vindu = GraphicsWindow(500, 500)
Lerret = Vindu.canvas()
Lerret.setColor("Cyan")

Liste = []

Liste.append(float(input("Skriv inn et x-koordinat: ")))
Liste.append(float(input("Skriv inn et y-koordinat: ")))
Liste.append(float(input("Skriv inn høyden: ")))
Liste.append(float(input("Skriv inn bredden: ")))
print(Liste)
Lerret.drawOval(Liste[0], Liste[1], Liste[2], Liste[3])

Vindu.wait()
moveLX = 2
moveLY = 1
moveRX = 2
moveRY = 1
moveFX = 1
moveFY = 1
detachL = False
detachR = False
detachF = False

#how long to pause between animation frames
WAIT_TIME = 0.1

#setup the graphics window and canvas
myWin = GraphicsWindow(WIN_WIDTH, WIN_HEIGHT)
myCanvas = myWin.canvas()

while F1Y < 1024:
    if L1Y > 512 and not detachL:
        #move SRB Left up
        L1Y -= moveY
        L2Y -= moveY
        L3Y -= moveY
        L4Y -= moveY
        L5Y -= moveY
        L6Y -= moveY
        L7Y -= moveY
        L8Y -= moveY
        L9Y -= moveY
        L10Y -= moveY
        myCanvas.drawPolygon(L1X, L1Y, L2X, L2Y, L3X, L3Y, L4X, L4Y, L5X, L5Y,
Ejemplo n.º 19
0
def main():
    goOn = True
    player = 1
    win = GraphicsWindow(DIE_SIZE * 8, DIE_SIZE * 8)
    canvas = win.canvas()
    #canvas.setFill("red")
    canvas.setBackground(0, 128, 0)
    #canvas.setFont(20)
    #canvas.getAvailableFonts()

    #canvas = configureWindow(DIE_SIZE * 7)
    #rollDice(canvas, DIE_SIZE)

    HOWMANY = 10

    cnt = 0
    player1Scores = []
    player2Scores = []

    while cnt < HOWMANY:

        initilizeScreen(win, canvas, cnt)
        player = 1
        #print(player)
        #clickx, clicky = win.getMouse()
        #canvas.setBackground(0, 128, 0)
        #canvas.clear()
        canvas.setColor(0, 0, 0)
        canvas.setTextFont("arial", "bold", 15)
        canvas.drawText(DIE_SIZE * 3 / 2, DIE_SIZE * 1, "Yourself")
        canvas.setTextFont("arial", "bold", 40)
        run = randint(1, 6)
        drawDie(canvas, DIE_SIZE * 3 / 2, DIE_SIZE * 4, DIE_SIZE, run)
        canvas.setBackground(0, 128, 0)
        player1Scores.append(run)
        scoreboardClean(canvas, player)
        sumPlayer1Scores = str(sum(player1Scores))
        canvas.drawText(DIE_SIZE * 3 / 2, DIE_SIZE * 2, sumPlayer1Scores)
        win.sleep(900)

        ### player 2
        player = 2
        #print(player)
        canvas.setTextFont("arial", "bold", 15)
        canvas.drawText(DIE_SIZE * 4.5, DIE_SIZE * 1, "Computer")
        canvas.setTextFont("arial", "bold", 40)
        run = randint(1, 6)
        drawDie(canvas, DIE_SIZE * 5, DIE_SIZE * 4, DIE_SIZE, run)
        player2Scores.append(run)
        scoreboardClean(canvas, player)
        sumPlayer2Scores = str(sum(player2Scores))
        canvas.drawText(DIE_SIZE * 5, DIE_SIZE * 2, sumPlayer2Scores)

        ### increment the iteratuion
        cnt = cnt + 1

        if (cnt == HOWMANY):
            reportScore(canvas, whoIsWinner(sumPlayer1Scores,
                                            sumPlayer2Scores))

            win.sleep(3000)
            #print(terminateGame(win, canvas))

            if terminateGame(win, canvas):
                #win.close()
                win.quit()
            else:
                cnt = 0
                player1Scores = []
                player2Scores = []
                canvas.clear()
Ejemplo n.º 20
0
# 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)

    diameter = diameter - 2 * RING_WIDTH
Ejemplo n.º 21
0
#Oppg.3.1-4. Bruke modulen ezGraphics.py for å tegne figurer. Har dessverre ikke fått meg pensumboka enda...
#Henter først ut GraphicsWindow fra exgraphics, der figurene kan tegnes.

from ezgraphics import GraphicsWindow

# Lage et vindu for å tegne i, 500x500 pixels.
vindu = GraphicsWindow(500, 500)

# Setter tittel på vinduet.
vindu.setTitle("Oppg. 3: Rød sirkel")

#Gir navn til vinduet for å bruke videre i programmeringen.
canvas = vindu.canvas()

#Gir sirkelen rødfarge.
canvas.setOutline("red")

#canvas.setFill("red") #kan brukes for å lage det japanske flagget.

#canvas.drawOval(x, y, width, height) brukes for å tegne sirkel.
canvas.drawOval(100, 100, 300, 300)