예제 #1
0
def main():
    windowWidth = 300
    windowHeight = 300

    Color = random.choice(Colors)
    gWindow = GRC.GraphicsWindow("Box", windowWidth, windowHeight)
    interval = .25
    #gWindow.setCoords(0, 0, 100, 100)
    # text = GRC.Text(GRC.Point(150, 50), "Centered Text")
    # text.setTextColor("Blue")
    # text.setSize(5)
    # gWindow.addItem(text)
    # for fontSize in range(5,25):
    #     text.setSize(fontSize)
    #     gWindow.redraw()
    #     GRC.time.sleep(interval)
    #
    # for fontSize in range(25, 8):
    #     text.setSize(fontSize)
    #     gWindow.redraw()
    #     GRC.time.sleep(interval)

    polygon1 = GRC.Polygon(GRC.Point(10, 10), GRC.Point(125, 10),
                           GRC.Point(125, 125), GRC.Point(10, 125))
    polygon1.draw(gWindow)
    Util.pause(gWindow)
예제 #2
0
def main():
    for i in range(0, 50):
        x = random.randint(5, windowWidth - 5)
        y = random.randint(5, windowHeight - 5)
        rgb = color_rgb(255, 255, 0)
        pix = pixel(x, y, rgb)
        pixels.append(pix)
        gWindow.plotPixel(x, y, "Red")

    Util.sleep(1)
    pix1 = pixels.pop()
    pix2 = pixels.pop()
    line = GRC.Line(GRC.Point(pix1.x, pix1.y), GRC.Point(pix2.x, pix2.y))
    rndColor = random.choice(Util.Colors2)
    line.setFillColor(rndColor)
    gWindow.addItem(line)
    gWindow.redraw()
    gWindow.update()
    Util.sleep(interval)
    #print("paused")
    #Util.pause(gWindow)

    while len(pixels) > 0:
        pix1 = pix2
        pix2 = pixels.pop()
        line = GRC.Line(GRC.Point(pix1.x, pix1.y), GRC.Point(pix2.x, pix2.y))
        rndColor = random.choice(Util.Colors2)
        line.setFillColor(rndColor)
        gWindow.addItem(line)
        gWindow.redraw()
        gWindow.update()
        Util.sleep(interval)
예제 #3
0
def seconds(centerPoint, radius):

    xx = centerPoint.getX()
    yy = centerPoint.getY()

    for tick in range(1, 61, 1):

        if tick < 16:
            lineEndPoint = GRC.Point(radius + (tick * 10), tick * 10)

        if tick >= 16 and tick < 31:
            lineEndPoint = GRC.Point(300 - ((tick - 15) * 10),
                                     150 + (tick - 15) * 10)

        if tick >= 30 and tick < 46:
            lineEndPoint = GRC.Point(150 - ((tick - 30) * 10),
                                     300 - (tick - 30) * 10)

        if tick >= 46 and tick < 61:
            lineEndPoint = GRC.Point(0 + ((tick - 45) * 10),
                                     150 - (tick - 45) * 10)

        line = GRC.Line(centerPoint, lineEndPoint)
        GRC.time.sleep(interval)
        gWindow.addItem(line)
        gWindow.redraw()
예제 #4
0
def main():

    line1 = GRC.Line(GRC.Point(10, 10), GRC.Point(20, 10))
    gWindow.addItem(line1)
    gWindow.redraw()
    Util.sleep(5)
    line1.move(20, 20)

    gWindow.redraw()

    Util.pause(gWindow)
예제 #5
0
def main():
    windowWidth = 300
    windowHeight = 300

    Color = random.choice(Colors)
    gWindow = GRC.GraphicsWindow("Polygon", windowWidth, windowHeight)
    gWindow2 = GRC.GraphicsWindow("Polygon2", windowWidth, windowHeight)

    gWindow2.setCoords(0, 0, 10, 10)
    gWindow.setCoords(0, 0, 10, 10)
    t = GRC.Text(GRC.Point(5, 5), "Centered Text")
    t.draw(gWindow2)
    p = GRC.Polygon(GRC.Point(1, 1), GRC.Point(5, 3), GRC.Point(2, 7))
    p.draw(gWindow)
    pause(gWindow)
예제 #6
0
def drawBox():

    # set boarder Color of box object
    boarderColor = "Black"

    # set boarder Color of box object
    fillColor = "Yellow"

    # define a polygon object as a box
    polygon = GRC.Polygon(GRC.Point(10, 10), GRC.Point(125, 10),
                          GRC.Point(125, 125), GRC.Point(10, 125))
    polygon.setBoarderColor(boarderColor)
    polygon.setFillColor(fillColor)

    # Pass graphic window object to the box object; call draw method.
    polygon.draw(gWindow)
예제 #7
0
def pointsOnCircle(x, y, radius):
    center = GRC.Point(x, y)
    center = [x, y]
    angles = []
    for angle in range(0, 360):
        px = point_on_circle(center, angle - 90, radius)
        #  print (px)
        angles.append(px)
    # for angle in range(0, 360):
    #     print("Angle1: ", angle, angles[angle])
    return angles
def main():

    #win = GRC.GraphicsWindow("test", 500, 500)

    p1 = GRC.Point(10, 20)
    p2 = GRC.Point(10, 200)

    # myLine = GRC.Line(p1, p2)
    # myLine.draw(win)
    # calcPoints(p1,p2)
    points = get_line([10,10], [20,200])
    #print (points)
    for point in points:
        print (point)
        win.plot(point[0], round(point[1]), "Black")

    line = GRC.Line(p1,p2)
    win.addItem(line)
    win.redraw()
    win.waitForKeyPress()
예제 #9
0
def main():

    # define size of graphics windows
    windowWidth = 300
    windowHeight = 300


    # Define the graphics window.
    gWindow = GRC.GraphicsWindow("Title of window: Box", windowWidth, windowHeight)

    # set boarder Color of box
    Color = "Black"

    #define a polygon as a box
    polygon = GRC.Polygon(GRC.Point(10, 10), GRC.Point(125, 10), GRC.Point(125,125), GRC.Point(10,125))

    #display box object on graphics windows
    polygon.draw(gWindow)

    #click to close window
    gWindow.waitForClick()
예제 #10
0
def main(Colors):

    windowWidth = 300
    windowHeight = 300

    padding = 3

    Color = random.choice(Colors)
    gWindow = GRC.GraphicsWindow("Rectangles", windowWidth, windowHeight)

    sq = []
    rect = GRC.Rectangle(GRC.Point(10, 10), GRC.Point(290, 290))
    rect1 = GRC.Rectangle(GRC.Point(20, 20), GRC.Point(280, 280))
    for i in range(1, 30):
        #rect = GRC.Rectangle(GRC.Point(padding * i, padding * i), GRC.Point(windowWidth - (padding * i),  + windowHeight - (padding * i)))
        gWindow.addItem(
            GRC.Rectangle(
                GRC.Point(padding * i, padding * i),
                GRC.Point(windowWidth - (padding * i),
                          +windowHeight - (padding * i))))
        gWindow.autoflush
        gWindow.update()

    gWindow.redraw()
    gWindow.waitForKeyPress()
예제 #11
0
def drawPolygonBox():

    # set boarder Color of box object
    boarderColor = "Black"

    # set boarder Color of box object
    fillColor = "Yellow"

    # define a polygon object as a box
    box = GRC.Polygon(GRC.Point(10, 10), GRC.Point(25, 10), GRC.Point(25, 25),
                      GRC.Point(10, 25))
    box.setBoarderColor(boarderColor)
    box.setFillColor(fillColor)
    p1 = GRC.Point(10, 10)
    p2 = GRC.Point(20, 20)

    mybox = GRC.BBox(p1, p2)
    mybox.draw(gWindow)

    # Pass graphic window object to the box object; call draw method.
    box.draw(gWindow)
    box.move(100, 100)
    gWindow.waitForClick()
    # p1 = box.getCenter
    box.move(-90, -90)
    points = box.getPoints()

    # click on window to close\exit
    gWindow.waitForClick()
예제 #12
0
def point_on_circle(center, Degree, radius):
    '''
        Finding the x,y coordinates on circle, based on given angle
    '''
    from math import cos, sin, pi

    angle = (pi * 2) / 360

    x = center[0] + (radius * cos(Degree * pi / 180))
    y = center[1] + (radius * sin(Degree * pi / 180))

    point = GRC.Point(int(x), int(y))
    return point
예제 #13
0
def TextScroll():

    scrollText = GRC.Text(GRC.Point(500, 15),
                          "Scroll Demo.... ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    scrollText.setTextColor("Blue")
    scrollText.setFontSize(12)
    gWindow.addItem(scrollText)
    gWindow.update()

    for moveX in range(1, 700, 1):
        scrollText.move(-1, 0)
        gWindow.redraw()
        GRC.time.sleep(.01)

    Util.pause(gWindow)
예제 #14
0
def fifteenSeconds(centerPoint, radius):

    xx = centerPoint.getX()
    yy = centerPoint.getY()

    for tick in range(1, 16, 1):

        # line.move(GRC.Point(150,150),GRC.Point(10,1))
        #gWindow.items.remove(line)
        #gWindow.redraw()
        lineEndPoint = GRC.Point(radius + (tick * 10), tick * 10)
        line = GRC.Line(centerPoint, lineEndPoint)
        GRC.time.sleep(interval)
        gWindow.addItem(line)
        gWindow.redraw()
예제 #15
0
def main():

    circlePoints = pointsOnCircle(150, 150, 100)
    HourHandcirclePoints = pointsOnCircle(150, 150, 90)
    minuteHandcirclePoints = pointsOnCircle(150, 150, 95)
    secondHandEndPoint = circlePoints[0]

    secondHand = GRC.Line(secondHandEndPoint, clockCenter)
    gWindow.addItem(secondHand)
    gWindow.setBackground("Black")

    for tick in range(0, 360, 6):
        gWindow.plotPixel(circlePoints[tick].getX(), circlePoints[tick].getY(),
                          "Yellow")

    while (True):

        hour, minute, sec = getCurrentTime()
        if hour == 12:
            hour = 0
        hourHandEndPoint = HourHandcirclePoints[hour * 30]
        minuteHandEndPoint = minuteHandcirclePoints[minute * 6]
        secondHandEndPoint = circlePoints[sec * 6]

        hourHand = clockHand(hourHandEndPoint, 3, "red", clockCenter)
        MinuteHand = clockHand(minuteHandEndPoint, 2, "Blue", clockCenter)
        secondHand = clockHand(secondHandEndPoint, 1, "White", clockCenter)

        hourHand.draw(gWindow)
        secondHand.draw(gWindow)
        MinuteHand.draw(gWindow)

        message = GRC.Text(
            GRC.Point(150, 290),
            str(hour).zfill(2) + ":" + str(minute).zfill(2) + ":" +
            str(sec).zfill(2))
        message.setFillColor("Green")
        message.draw(gWindow)
        GRC.time.sleep(interval)

        message.undraw()
        hourHand.undraw()
        secondHand.undraw()
        MinuteHand.undraw()
예제 #16
0
def wallBounce():

    windowWidth = 300
    windowHeight = 300

    Color = random.choice(Colors)
    gWindow = GRC.GraphicsWindow("Bounce", windowWidth, windowHeight)
    p1 = 10
    p2 = 10
    size = 10
    margin = 2
    Ball = GRC.Circle(GRC.Point(p1, p2), size)
    Ball.setFillColor(Color)
    Ball.setBoarderColor(Color)
    gWindow.addItem(Ball)
    #gWindow.redraw()
    gWindow.update()
    pause(gWindow)

    doBounce(gWindow, Ball, windowHeight, margin, windowWidth, size, Color)
예제 #17
0
def drawRectanglBox():

    # set boarder Color of box object
    boarderColor = "Black"

    # set boarder Color of box object
    fillColor = "Yellow"

    # define a polygon object as a box
    box = GRC.Rectangle(GRC.Point(0, 0), GRC.Point(25, 25))
    box.setBoarderColor(boarderColor)
    box.setFillColor(fillColor)
    p1 = GRC.Point(10, 10)
    p2 = GRC.Point(20, 20)

    #mybox = GRC.BBox(p1,p2)
    #mybox.draw(gWindow)

    # Pass graphic window object to the box object; call draw method.
    box.draw(gWindow)
    box.jumpTo(GRC.Point(270, 0))
    gWindow.waitForClick()

    status = True
    while status:
        mp = gWindow.checkForClick()
        if mp != None:
            box.jumpTo(mp)
            #print (mp)

    box.move(0, 50)
    #xx = box.getCenter().x
    #yy = box.getCenter().y
    p1 = box.p1
    p2 = box.p2

    xx = box.p1.x
    yy = box.p1.y

    #print (xx,yy,p1,p2)
    gWindow.waitForClick()

    #box.p2 = GRC.Point(p2.x+10,p2.y+10)
    print(box.p1.x, box.p1.y, box.p1, box.p2)

    box.jumpTo(GRC.Point(0, 100))

    # click on window to close\exit
    gWindow.waitForClick()
예제 #18
0
def wallBounce():
    windowWidth = 500
    windowHeight = 268

    Color = random.choice(Colors)
    gWindow = GRC.GraphicsWindow("Bounce", windowWidth, windowHeight)
    background1.draw(gWindow)
    p1 = 110
    p2 = 21
    size = 5
    margin = 15
    Ball = GRC.Circle(GRC.Point(p1, p2), size)

    Ball.setFillColor(Color)
    Ball.setBoarderColor("White")
    gWindow.addItem(Ball)
    gWindow.redraw()
    gWindow.update()
    GRC.time.sleep(1)
    # pause(gWindow)

    doBounce(gWindow, Ball, windowHeight, margin, windowWidth, size, Color)
예제 #19
0
def demo():

    import random, os, sys, inspect, pickle
    from Library import GRCGraphics as GRC

    windowWidth = 300
    windowHeight = 25
    interval = 1
    Color = random.choice(GRC.COLORS)
    gWindow = GRC.GraphicsWindow("Text Demo", windowWidth, windowHeight)

    scrollText = GRC.Text(GRC.Point(500, 15), "Scroll Demo.... ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    scrollText.setTextColor("Blue")
    scrollText.setFontSize(12)
    gWindow.addItem(scrollText)
    gWindow.update()

    for moveX in range(1,700,1):
        scrollText.move(-1,0)
        gWindow.redraw()
        GRC.time.sleep(.01)

    Util.pause(gWindow)
예제 #20
0
def main():

    p1 = 250
    p2 = 250
    size = 10

    c1 = GRC.Circle(GRC.Point(p1, p2), size)
    c2 = GRC.Circle(GRC.Point(p1, p2), size)
    c3 = GRC.Circle(GRC.Point(p1, p2), size)
    c4 = GRC.Circle(GRC.Point(p1, p2), size)

    c1.setFillColor("BLACK")
    c2.setFillColor("RED")
    c3.setFillColor("GREEN")
    c4.setFillColor("White")

    win.addItem(c1)
    win.addItem(c2)
    win.addItem(c3)
    win.addItem(c4)
    win.redraw()
    #pause(win)

    # win.redraw()
    # win.getMouse()

    c4.setFillColor("blue")
    for i in range(1, 22):
        c1.move(-i, -i)
        c2.move(-i, i)
        c3.move(i, -i)
        c4.move(i, i)

        win.redraw()
        #win.getMouse()
        GRC.time.sleep(.05)

    myP1 = c1.getCenter()
    myP2 = c2.getCenter()
    myP3 = c3.getCenter()
    myP4 = c4.getCenter()

    drawLine(myP1, myP2)
    drawLine(myP2, myP4)
    drawLine(myP4, myP3)
    drawLine(myP3, myP1)
    drawLine(myP3, myP2)
    drawLine(myP4, myP1)

    # myLine1 = GRC.Line (myP1,myP2)
    # win.addItem(myLine1)
    # GRC.time.sleep(interval)
    # win.redraw()
    # print("myLine1")

    #myLine2 = GRC.Line(myP2, myP4)
    #win.addItem(myLine2)
    #GRC.time.sleep(interval)
    #win.redraw()
    #print("myLine2")

    # myLine3 = GRC.Line(myP4, myP3)
    # win.addItem(myLine3)
    # GRC.time.sleep(interval)
    # win.redraw()
    # print("myLine3")

    # myLine4 = GRC.Line(myP3, myP1)
    # win.addItem(myLine4)
    # GRC.time.sleep(interval)
    # win.redraw()
    # print("myLine4")

    # myLine5 = GRC.Line(myP3, myP2)
    # win.addItem(myLine5)
    # GRC.time.sleep(interval)
    # win.redraw()
    # print("myLine5")

    # myLine6 = GRC.Line(myP4, myP1)
    # win.addItem(myLine6)
    # GRC.time.sleep(interval)
    # win.redraw()
    # print("myLine6")

    #c.draw(win)
    #c1.draw(win)
    #c2.draw(win)

    win.waitForClick()

    c2.move(150, 50)
    pause(win)

    c2.move(1, 1)
    pause(win)

    c2.move(150, 70)
    pause(win)

    c2.move(150, 80)
    pause(win)

    c2.radius = 30
    pause(win)
    win.close()  # Close window when done
예제 #21
0
from ctypes import windll
from tkinter import *
import random, os, sys, inspect, pickle
sys.path.append (os.path.dirname(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))))
from Library import GRCGraphics as GRC

background2 = GRC.Image(GRC.Point(251, 134), "..\\Content\\randomPixelsbackground3.png")


root = Tk()

def click(event):
    dc = windll.user32.GetDC(0)
    rgb = windll.gdi32.GetPixel(dc,event.x_root,event.y_root)
    r = rgb & 0xff
    g = (rgb >> 8) & 0xff
    b = (rgb >> 16) & 0xff
    print (r,g,b)

for i in ['red', 'green', 'blue', 'black', 'white']:
    Label(root, width=30, background=i).pack()

root.bind('<Button-1>', click)

root.mainloop()
예제 #22
0
    os.path.dirname(
        os.path.dirname(
            os.path.abspath(inspect.getfile(inspect.currentframe())))))
import nrnoble as Util
from Library import GRCGraphics as GRC

windowWidth = 502
windowHeight = 268
interval = .1
Color = random.choice(Util.Colors)
gWindow1 = GRC.GraphicsWindow("Image Window-1", windowWidth, windowHeight)
#gWindow2 = GRC.GraphicsWindow("Image Window-2", windowWidth, windowHeight)

# background1 = GRC.Image(GRC.Point(251, 134), "E:\\Data\\Github\\GRC1\\Content\\bwdock.png")
# background2 = GRC.Image(GRC.Point(251, 134), ".\\Content\\blackbackground.png")
background2 = GRC.Image(GRC.Point(251, 134),
                        "..\\Content\\randomPixelsbackground3.png")
#background2 = GRC.Image(GRC.Point(251, 134), "E:\\Data\\Github\\GRC1\\Content\\randomPixelsbackground3.png")


def main():

    # background1.draw(gWindow1)
    background2.draw(gWindow1)
    # gWindow1.redraw()
    # gWindow2.redraw()
    pixels = []

    # for y in range(0,windowHeight -  3):
    #     for x in range (0,windowWidth):
    #         red, green, blue = background1.getPixel(x,y)
예제 #23
0
import random

from Library import GRCGraphics as GRC
from Library.Examples import nrnoble as Util

windowWidth = 502
windowHeight = 268
interval = .1
Color = random.choice(Util.Colors)
gWindow1 = GRC.GraphicsWindow("Image Window-1", windowWidth, windowHeight)
gWindow2 = GRC.GraphicsWindow("Image Window-2", windowWidth, windowHeight)

#background1 = GRC.Image(GRC.Point(251, 134), "E:\\Data\\Github\\GRC1\\Content\\bwdock.png")
# background1 = GRC.Image(GRC.Point(251, 134), "E:\\Data\\Github\\GRC1\\Content\\icecave.png")
background2 = GRC.Image(GRC.Point(251, 134), ".\\Content\\blackbackground.png")


def main():

    filepath = '.\\Content\\randomColors.pkle'

    #background1.draw(gWindow1)
    background2.draw(gWindow2)
    # gWindow1.redraw()
    # gWindow2.redraw()
    pixels = []

    for y in range(0, windowHeight - 3):
        for x in range(0, windowWidth):
            # red, green, blue = background1.getPixel(x,y)
            red = random.randint(0, 255)
예제 #24
0
import random
import time

from Library import GRCGraphics as GRC
from Library.Examples import nrnoble as Util

windowWidth = 300
windowHeight = 300
interval = 1
Color = random.choice(Util.Colors)
gWindow = GRC.GraphicsWindow("Clock", windowWidth, windowHeight)
clockCenter = GRC.Point(150, 150)

#lineStartPoint = []
#points = []


def main():

    circlePoints = pointsOnCircle(150, 150, 100)
    HourHandcirclePoints = pointsOnCircle(150, 150, 90)
    minuteHandcirclePoints = pointsOnCircle(150, 150, 95)
    secondHandEndPoint = circlePoints[0]

    secondHand = GRC.Line(secondHandEndPoint, clockCenter)
    gWindow.addItem(secondHand)
    gWindow.setBackground("Black")

    for tick in range(0, 360, 6):
        gWindow.plotPixel(circlePoints[tick].getX(), circlePoints[tick].getY(),
                          "Yellow")