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()
Example #2
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()
Example #3
0
# 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
    x = x + RING_WIDTH
    y = y + RING_WIDTH

# Draw the bull's eye in red.
canvas.setColor("red")
canvas.drawOval(x, y, diameter, diameter)

win.wait()
Example #4
0
"""
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()
Example #5
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()
Example #6
0
    for j in range(1, 7):
        #canvas.drawOval(flagG+(j-1)*2*flagH,flagE+i*2*flagF,2*StarK,2*StarK)
        #posOfStars.append([round(flagG+(j-1)*2*flagH), round(flagE+i*2*flagF)])
        posOfStarsX.append(round(flagG + (j - 1) * 2 * flagH))
        posOfStarsY.append(round(flagE + i * 2 * flagF))
# the 5 star row of the canton
for i in range(4):
    for k in range(1, 6):
        #canvas.drawOval(flagG+(2*k-1)*flagH,flagE+(2*i+1)*flagF,2*StarK,2*StarK)
        #posOfStars.append([round(flagG+(2*k-1)*flagH),round(flagE+(2*i+1)*flagF)])
        posOfStarsX.append(round(flagG + (2 * k - 1) * flagH))
        posOfStarsY.append(round(flagE + (2 * i + 1) * flagF))

### drawing stars
RHO = 180 / pi
radiusOfCircle = StarK / 2
canvas.setColor("white")
for j in range(len(posOfStarsX)):
    x = []
    y = []
    for i in range(5):
        teta = float((i * 72 + 270) / RHO)
        x1 = round(posOfStarsX[j] + radiusOfCircle * cos(teta))
        y1 = round(posOfStarsY[j] + radiusOfCircle * sin(teta))
        x.append(x1)
        y.append(y1)
    canvas.drawPolygon(x[0], y[0], x[2], y[2], x[4], y[4], x[1], y[1], x[3],
                       y[3], x[0], y[0])

us.wait()
Example #7
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()
    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()