Exemplo n.º 1
0
import math
print("Hello!")
#Constant & variable define
name = input("Name?:")
width = int(input("Width of the Window:"))
height = int(input("height of the Window:"))
radius = int(input("Radius of the Circle:"))
borderColor = input("Border Color? :")
borderThickness = int(input("Border Thickness? (by pixel):"))
textX = round(0.01*width)
textY = round(0.01*height)
Circ = "Circumference:"+str((2*math.pi*radius))
Area = "Area:"+str((math.pi*(radius**2)))
#print info
print ("TEXTX:",textX)
print ("TEXTY:",textY)
print("Circumference:",(2*math.pi*radius))
print("Area:",(math.pi*(radius**2)))
#Construct Graphic
win = GraphicsWindow (width,height)
canvas = win.canvas()
canvas.drawText(textX,textY,name+"\n"+Circ+"\n"+Area)
canvas.setOutline(borderColor)
canvas.setFill()
canvas.setLineWidth(borderThickness)
startx = (width/2)-radius
starty = (height/2)-radius
canvas.drawOval(startx,starty,2*radius,2*radius)
print("Graphic Completed")
win.wait()
Exemplo n.º 2
0
##
# Draws and determines if two circles intersect. The parameters of both
# circles are obtained from the user.

from ezgraphics import GraphicsWindow
from math import sqrt
from sys import exit

# Define constant variables
MIN_RADIUS = 5
WIN_WIDTH = 500
WIN_HEIGHT = 500

# Create the graphics window and get the canvas.
win = GraphicsWindow(WIN_WIDTH, WIN_HEIGHT)
canvas = win.canvas()

# Obtain the parameters of the first circle.
print("Enter parameters for the first circle: ")
x0 = int(input(" x-coord:"))
y0 = int(input(" y-coord:"))
if x0 < 0 or x0 >= WIN_WIDTH or y0 < 0 or y0 > WIN_HEIGHT:
    exit(
        "Error: the center of the circle must be within the area of the window. "
    )

r0 = int(input(" radius: "))
if r0 <= MIN_RADIUS:
    exit("Error: the radius must be >", MIN_RADIUS)

# Draw the first circle
Exemplo n.º 3
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:
                global counter
                global canvas
                # ler do stdin
                # print ("ler do stdin")
                
                win = GraphicsWindow()
                win.setTitle("RGB Matrix")
                canvas = win.canvas()
                canvas.setWidth(n_cells_per_side*n_pixeis)
                canvas.setHeight(n_cells_per_side*n_pixeis)
                counter = False

                array = []
                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(0,0,0)
                    array.append(canvas.drawRectangle(x*n_pixeis,y*n_pixeis,n_pixeis,n_pixeis))
                
                for line in sys.stdin:
                    cells = arg_as_list(line)
                    if (len(cells) == (n_cells_per_side*n_cells_per_side)):
                        
                        # 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

                            color = "#%02X%02X%02X" % (cells[i][0], cells[i][1], cells[i][2])

                            canvas._tkcanvas.itemconfig(array[i], fill=color, outline=color)

                            #canvas.setColor(cells[i][0],cells[i][1],cells[i][2])
                            #canvas.drawRectangle(x*n_pixeis,y*n_pixeis,n_pixeis,n_pixeis)
                            
                        canvas._tkcanvas.update_idletasks()
                    #time.sleep(0.5)
                    else:
                        print("Error", len(cells), n_cells_per_side * n_cells_per_side)
        else:
            raise IOError("File RGBMatrixConf.txt doesn't appear to exists.")
Exemplo n.º 4
0
# Created by: Will Schick
#
# Date: 2/27/2018
#
# This program asks for the size of the window and draws a target and bulls eye to accommodate

from ezgraphics import GraphicsWindow

#UserInput
print("---" * 5)
canvasSize = int(input("Target Size?: "))

#Constants & Variables

# Create the window and access the canvas.
win = GraphicsWindow(canvasSize, canvasSize)
canvas = win.canvas()
win.setTitle("Bull's-Eye")

# Draw on the canvas.
#Canvas Color
canvas.setColor("grey")
canvas.drawRect(0, 0, canvasSize, canvasSize)

#First Ring
canvas.setColor("black")
canvas.drawOval(0, 0, canvasSize, canvasSize)

#Second Ring
canvas.setColor("white")
canvas.drawOval(canvasSize * .1, canvasSize * .1, canvasSize * .80,
Exemplo n.º 5
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)
Exemplo n.º 6
0
from ezgraphics import GraphicsWindow

Vindu = GraphicsWindow(200, 200)
Lerret = Vindu.canvas()

Lerret.setColor("red")
Lerret.drawOval(0, 0, 200, 200)

Vindu.wait()
Exemplo n.º 7
0
    @author: Kevin Gonzalez
"""

from ezgraphics import GraphicsWindow

#variables for the program
userInputOne = int(input("Enter the first number "))
userInputTwo = int(input("Enter the second number "))
sumOfNums = userInputOne + userInputTwo
differenceOfNums = userInputOne - userInputTwo
productOfNums = userInputOne * userInputTwo
averageOfNums = float(userInputOne + userInputTwo / 2)
distanceOfNums = abs(userInputOne - userInputTwo)
maximumOfNums = max(userInputOne, userInputTwo)
minimumOfNums = min(userInputOne, userInputTwo)

#creates a new window
win = GraphicsWindow(400, 200)
canvas = win.canvas()

#Draws on canvas
canvas.drawText(
    20, 30, "The sum: " + str(sumOfNums) + "\nThe difference: " +
    str(differenceOfNums) + "\nThe product: " + str(productOfNums) +
    "\nThe average: " + str(averageOfNums) + "\nThe distance: " +
    str(distanceOfNums) + "\nThe maximum: " + str(maximumOfNums) +
    "\nThe minimum of the numbers: " + str(minimumOfNums))

#Waits for the user to exit the window
win.wait()
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 writing: 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")
Exemplo n.º 9
0
# olympicRings.py
#
# Created by: Will Schick
#
# Date: 2/27/2018
#
# This program draws the olympic rings in a graphics window

from ezgraphics import GraphicsWindow

# Create the window and access the canvas.
win = GraphicsWindow(340, 160)
canvas = win.canvas()
win.setTitle("Olympic Rings!")

# Draw on the canvas.
#Blue Ring
canvas.setOutline("blue")
canvas.drawOval(0, 0, 100, 100)

#Yellow Ring
canvas.setOutline("yellow")
canvas.drawOval(60, 60, 100, 100)

#Black Ring
canvas.setOutline("black")
canvas.drawOval(120, 0, 100, 100)

#Green Ring
canvas.setOutline("green")
canvas.drawOval(180, 60, 100, 100)
Exemplo n.º 10
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()
Exemplo n.º 11
0
# -*- coding: utf-8 -*-
## P4.43
"""
Created on Wed Jun  6 16:43:14 2018

@author: qhu
"""

from ezgraphics import GraphicsWindow

window = GraphicsWindow(800, 600)
canvas = window.canvas()

x_int = 400
y_int = 300
old_x = x_int
old_y = y_int
cur_x = x_int
cur_y = y_int
increment = 10

for i in range(1, 20, 1):
    cur_x = cur_x + (-1)**(i + 1) * increment * i
    canvas.drawLine(old_x, old_y, cur_x, cur_y)
    old_x = cur_x

    cur_y = cur_y + (-1)**(i + 1) * increment * i
    canvas.drawLine(old_x, old_y, cur_x, cur_y)
    old_y = cur_y

window.wait()
Exemplo n.º 12
0
import math
from ezgraphics import GraphicsWindow

gw_width = float(input("Enter the width: "))
gw_height = float(input("Enter the height: "))

circle_radius = float(input("Enter the radius: "))

border_color = input("Enter the circle border color: ")
inside_color = input("Enter the circle inside color: ")

win = GraphicsWindow(gw_width, gw_height)

canvas = win.canvas()

canvas.setOutline(border_color)
canvas.setFill(inside_color)

ww = circle_radius * 2
hh = circle_radius * 2

xx = (gw_width / 2) - circle_radius
yy = (gw_width / 2) - circle_radius

canvas.drawOval(xx, yy, ww, hh)
win.wait()
Exemplo n.º 13
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()
Exemplo n.º 14
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)
Exemplo n.º 15
0
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)

pic2 = GraphicsImage("picture2.gif")
x = pic.width() + GAP
canvas.drawImage(x, 0, pic2)

pic3 = GraphicsImage("picture3.gif")
x = x + pic2.width() + GAP
canvas.drawImage(x, 0, pic3)

win.wait()
Exemplo n.º 16
0
# I denne oppgaven skal du importere en ​modul​ for å
# gjøre en enkel grafikkoppgave. Modulendu skal hente
# heter EzGraphics og er gratis som en del av pensumboken
# Python for Everyone. Følg disse stegene:

# 1.Les side 63-69 i Python for Everyone om hvordan du
# kan importere modulen og tegne figurer.

# 2.Last ned ezgraphics-2.1.tar.gz herfra.

# 3.Bruk pip i terminalen for å installere ezgraphics på
# ifi-brukeren din slik:pip install ​ezgraphics-2.1.tar.gz

# 4.I ​sirkel.py​, importer ​ezgraphics.py​ og bruk informasjonen
# fra pensumboka for å tegne en rød sirkel.

from ezgraphics import GraphicsWindow

#Lag vindu og få tilgang til canvasen
win = GraphicsWindow(500, 500)
canvas = win.canvas()

#Tegn på canvasen
canvas.setColor('red')
canvas.drawOval(120, 120, 240, 240)

#Vent på at brukeren stenger vinduet
win.wait()
Exemplo n.º 17
0
from ezgraphics import GraphicsWindow

# Create the Window and access the canvas
win = GraphicsWindow()
canvas = win.canvas()

# Draw in the canvas
canvas.setFill(255, 0, 0)
canvas.drawRect(0, canvas.height() // 4, canvas.width(), canvas.height() // 2)

canvas.setOutline(255, 255, 255)

canvas.drawText(10, canvas.height() // 4 + 10, "Hello World")
win.wait()
Exemplo n.º 18
0
def configureWindow(winSize):
    win = GraphicsWindow(winSize, winSize)
    canvas = win.canvas()
    canvas.setBackground(0, 128, 0)
    return canvas