Example #1
0
 def __init__(self):
     GCompound.__init__(self)
     self.add(SudokuDigitSelectorSubcell(1), 0, 0)
     self.add(SudokuDigitSelectorSubcell(2), SUBCELL_WIDTH, 0)
     self.add(SudokuDigitSelectorSubcell(3), 0, SUBCELL_WIDTH)
     self.add(SudokuDigitSelectorSubcell(4), SUBCELL_WIDTH, SUBCELL_WIDTH)
     self.add(ClearCell(), SUBCELL_WIDTH, SUBCELL_WIDTH)
Example #2
0
 def __init__(self, boxes):
     GCompound.__init__(self)
     self.boxes = boxes
     assert len(boxes) == 4
     self.add(boxes[0], 0, 0)
     self.add(boxes[1], BOX_WIDTH, 0)
     self.add(boxes[2], 0, BOX_WIDTH)
     self.add(boxes[3], BOX_WIDTH, BOX_WIDTH)
Example #3
0
 def __init__(self, cells):
     GCompound.__init__(self)
     assert len(cells) == 4
     self.cells = cells
     self.add(cells[0], 0, 0)
     self.add(cells[1], CELL_WIDTH, 0)
     self.add(cells[2], 0, CELL_WIDTH)
     self.add(cells[3], CELL_WIDTH, CELL_WIDTH)
Example #4
0
def drawFlowerz(size,angle,diamondAngle): #draws flower, with size being the height of one diamond and angle  being the rotation of the flower
    f=GCompound()
    numDiamonds=360//diamondAngle
    theta=angle
    for i in range(numDiamonds):
        f.add(drawDiamond(size,theta,colors[i],diamondAngle))
        theta+=diamondAngle
    return f
Example #5
0
 def __init__(self):
     GCompound.__init__(self)
     box1 = construct_box(0,0,0,0)
     box2 = construct_box(0,0,0,0)
     box3 = construct_box(0,0,0,0)
     box4 = construct_box(0,0,0,0)
     self.board = VisualSudokuBoard([box1, box2, box3, box4])
     self.add(self.board, 0, 0)
     self.menu = MenuBar()
     self.add(self.menu, 0, GWINDOW_WIDTH)
Example #6
0
 def __init__(self, name):
     """Creates a new node with the specified name."""
     GCompound.__init__(self)
     self._name = name
     r = ArpanetNode.SIZE / 2
     oval = GOval(-r, -r, 2 * r, 2 * r)
     oval.setFilled(True)
     self.add(oval)
     self._routingTable = None
     self._active = True
     self._neighbors = set()
Example #7
0
    def create_rocket():
        """
        Function to create the compound rocket object. Including the core,
        1 fin on each side, and a nose cap. Should return the compound object.
        """
        rocket = GCompound()
        core = create_filled_rect(0, 0, ROCKET_WIDTH, ROCKET_HEIGHT, "oldlace")
        rocket.add(core, -ROCKET_WIDTH / 2, -ROCKET_HEIGHT)

        # Add your code below to add more pieces to the rocket!

        return rocket
Example #8
0
    def __init__(self, letter):
        GCompound.__init__(self)

        lamp = GOval(LAMP_RADIUS * 2, LAMP_RADIUS * 2)
        lamp.setColor(LAMP_BORDER_COLOR)
        lamp.setFillColor(LAMP_BGCOLOR)
        self.add(lamp, -LAMP_RADIUS, -LAMP_RADIUS)  # create design for lamps

        self.ch = GLabel(letter)
        self.ch.setColor(LAMP_OFF_COLOR)
        self.ch.setFont(LAMP_FONT)
        self.add(self.ch, -self.ch.getWidth() / 2, LAMP_LABEL_DY)
Example #9
0
 def __init__(self):
     GCompound.__init__(self)
     bar = GRect(GWINDOW_WIDTH, MENU_BAR_HEIGHT)
     bar.setFilled(True)
     bar.setColor(CELL_BORDER_COLOR)
     bar.setFillColor(MENU_BAR_BGCOLOR)
     self.add(bar, 0, 0)
     self.label = GLabel("Y O U D O K U")
     self.label.setFont(MENU_TITLE_FONT)
     self.label.setColor(MENU_TITLE_COLOR)
     self.add(self.label, 
              GWINDOW_WIDTH//2 - self.label.getWidth()//2, 
              MENU_BAR_HEIGHT//2 + self.label.getAscent()//2 - 5)
Example #10
0
    def __init__(self, letter):
        GCompound.__init__(self)

        key = GOval(KEY_RADIUS * 2, KEY_RADIUS * 2)
        key.setLineWidth(KEY_BORDER)
        key.setColor(KEY_BORDER_COLOR)
        key.setFillColor(KEY_BGCOLOR)
        self.add(key, -KEY_RADIUS, -KEY_RADIUS)  # create design for keys

        self.ch = GLabel(letter)
        self.ch.setColor(KEY_UP_COLOR)
        self.ch.setFont(KEY_FONT)

        self.add(self.ch, -self.ch.getWidth() / 2, KEY_LABEL_DY)
def create_object():
    """
    Creates the original DVD Logo. Code from here will be moved into
    the new class that you are creating.
    """

    width = 200
    height = 200

    obj = GCompound()

    cube = GRect(0, 0, width, height)
    cube.set_filled(True)
    cube.set_color(random_color())
    obj.add(cube)

    dvdtext = GLabel("DVD")
    dvdtext.set_font("bold 60px 'serif'")
    obj.add(dvdtext, width / 2 - dvdtext.get_width() / 2, height / 2 - 10)

    vidtext = GLabel("video")
    vidtext.set_font("bold 50px 'serif'")
    vidtext.set_color("white")
    obj.add(vidtext, width / 2 - vidtext.get_width() / 2,
            height / 2 + vidtext.get_ascent())

    return obj
Example #12
0
 def __init__(self, digit):
     GCompound.__init__(self)
     self.digit = str(digit)
     cell = GRect(0, 0, SUBCELL_WIDTH, SUBCELL_WIDTH)
     cell.setColor(CELL_BORDER_COLOR)
     cell.setFillColor(SUBCELL_FILL_COLOR)
     cell.setFilled(True)
     self.add(cell, 0, 0)
     self.label = GLabel(digit)
     self.label.setFont(SUBCELL_FONT)
     self.label.setColor(SUBCELL_TEXT_COLOR)
     self.add(self.label, 
              SUBCELL_WIDTH//2 - self.label.getWidth()//2, 
              SUBCELL_WIDTH//2 + self.label.getAscent()//2 - 3)
Example #13
0
 def __init__(self, digit):
     GCompound.__init__(self)
     if digit != 0:
         self.digit = str(digit)
     else:
         self.digit = None
     self.cell = GRect(0, 0, CELL_WIDTH, CELL_WIDTH)
     self.cell.setColor(CELL_BORDER_COLOR)
     self.cell.setFillColor(CELL_GOOD_COLOR)
     self.cell.setFilled(True)        
     self.add(self.cell, 0, 0)  
     self.label = None
     self.only_a_suggestion = True
     self.render_label()
     self.selector = None
Example #14
0
 def __init__(self, text, fn=None):
     GCompound.__init__(self)
     label = GLabel(text)
     label.set_font(self.BUTTON_FONT)
     width = max(self.BUTTON_MIN_WIDTH,
                 2 * self.BUTTON_MARGIN + label.get_width())
     frame = GRect(width, self.BUTTON_DEFAULT_HEIGHT)
     frame.set_filled(True)
     frame.set_fill_color("White")
     self.add(frame)
     self.add(label)
     self.text = text
     self.label = label
     self.frame = frame
     self.fn = fn
     self._recenter()
Example #15
0
    def __init__(self):
        '''
		The constructor creates a return button on the enigma.
		'''
        GCompound.__init__(self)
        button = createFilledRect(-RETURN_WIDTH / 2,
                                  -RETURN_HEIGHT / 2,
                                  RETURN_WIDTH,
                                  RETURN_HEIGHT,
                                  fill=RETURN_BGCOLOR,
                                  border=RETURN_BORDER_COLOR)
        button.setLineWidth(RETURN_BORDER)
        label = GLabel('RETURN')
        label.setFont(RETURN_FONT)
        label.setColor(RETURN_COLOR)
        self.add(button)
        self.add(label, -label.getWidth() / 2, RETURN_LABEL_DY)
Example #16
0
    def __init__(self, letter):
        '''
		The constructor initalizes the key for a given letter.
		'''
        GCompound.__init__(self)
        button = createFilledCircle(0,
                                    0,
                                    KEY_RADIUS,
                                    fill=KEY_BGCOLOR,
                                    border=KEY_BORDER_COLOR)
        button.setLineWidth(KEY_BORDER)
        key = GLabel(letter)
        key.setFont(KEY_FONT)
        self.key = key
        key.setColor(KEY_UP_COLOR)
        self.add(button)
        self.add(key, -key.getWidth() / 2, KEY_LABEL_DY)
Example #17
0
 def __init__(self):
    GCompound.__init__(self)
    self.digit = ""
    outer = GOval(-20, -20, 40, 40)
    outer.setFilled(True)
    outer.setFillColor("red")
    outer.setColor("red")
    self.add(outer)
    outer = GOval(-16, -16, 32, 32)
    outer.setFilled(True)
    outer.setFillColor("white")
    outer.setColor("white")
    self.add(outer)
    strikethrough = GLine(15, -15, -15, 15)
    strikethrough.setLineWidth(6)
    strikethrough.setColor("red")
    self.add(strikethrough)
    def __init__(self, letter, perm, inverse):
        GCompound.__init__(self)

        rotor = GRect(ROTOR_WIDTH, ROTOR_HEIGHT)
        rotor.setColor(ROTOR_BGCOLOR)
        rotor.setFilled(True)
        self.add(rotor, -ROTOR_WIDTH / 2,
                 -ROTOR_HEIGHT / 2)  # create design for rotors

        self.ch = GLabel(letter)
        self.ch.setColor(ROTOR_COLOR)
        self.ch.setFont(ROTOR_FONT)
        self.add(self.ch, -self.ch.getWidth() / 2, ROTOR_LABEL_DY)

        self.perm = perm
        self.inverse = inverse
        self.offset = 0
        self.rotor = rotor
Example #19
0
    def __init__(self, letter):
        ''' 
		The constructor creates a lamp for a given letter.
		'''
        GCompound.__init__(self)
        self.letter = letter
        lamp = createFilledCircle(0,
                                  0,
                                  LAMP_RADIUS,
                                  fill=LAMP_BGCOLOR,
                                  border=LAMP_BORDER_COLOR)
        lamp = GLabel(letter)
        lamp.setFont(LAMP_FONT)
        self.lamp = lamp
        self.state = False
        lamp.setColor(LAMP_OFF_COLOR)
        self.add(lamp)
        self.add(lamp, -lamp.getWidth() / 2, LAMP_LABEL_DY)
 def __init__(self, nRows, nCols, sqSize):
     """
     Creates a new Maze object with the specified number of rows and
     columns and in which each square has the specified size.  The
     return value is a single graphical object descended from GCompound
     that can be added to a GWindow.  In keeping with the conventions
     of the Portable Graphics Library, the reference point for the
     Maze object is its upper left corner.
     """
     GCompound.__init__(self)
     self._nRows = nRows
     self._nCols = nCols
     self._sqSize = sqSize
     self._addGrid(nRows, nCols, sqSize)
     self._addVerticalWalls(nRows, nCols, sqSize)
     self._addHorizontalWalls(nRows, nCols, sqSize)
     self._addBorders(nRows, nCols, sqSize)
     self._addIntersections(nRows, nCols, sqSize)
Example #21
0
    def __init__(self, permuation):
        '''
		The constructor initalizes the rotor in the base setting.
		'''
        GCompound.__init__(self)
        self.permuation = permuation
        self.inversion = invertKey(permuation)
        self.offset = 0
        rotor = createFilledRect(-ROTOR_WIDTH / 2,
                                 -ROTOR_HEIGHT / 2,
                                 ROTOR_WIDTH,
                                 ROTOR_HEIGHT,
                                 fill=ROTOR_BGCOLOR)
        setting = GLabel(ALPHABET[self.offset])
        setting.setColor(ROTOR_COLOR)
        setting.setFont(ROTOR_FONT)
        self.setting = setting
        self.add(rotor)
        self.add(setting, -setting.getWidth() / 2, ROTOR_LABEL_DY)
Example #22
0
def createSierpinskiTriangle(size, order):
    if order == 0:  #base case
        return drawTriangle(size)
    else:
        gc = GCompound()
        s = (size / (2 * sqrt(3)))
        sx = s * cos(radians(30))
        sy = s * sin(radians(30))
        gc.add(createSierpinskiTriangle(size / 2, order - 1), 0, -s)
        gc.add(createSierpinskiTriangle(size / 2, order - 1), sx, sy)
        gc.add(createSierpinskiTriangle(size / 2, order - 1), -sx, sy)
        return gc
Example #23
0
def createBall():  # Create ball
    global ball

    ball = GCompound()
    head = filledCircle(-diameter // 2, -diameter // 2, diameter, "yellow")
    ball.add(head)
    mouth = filledCircle(-diameter / 10, diameter / 8, diameter / 5, "black")
    ball.add(mouth)
    lefteye = filledCircle(-diameter / 4, -diameter / 4, diameter / 8, "blue")
    ball.add(lefteye)
    righteye = filledCircle(diameter / 8, -diameter / 4, diameter / 8, "blue")
    ball.add(righteye)
    '''
    return face 

    ball = GOval(GWINDOW_WIDTH//2 - (BALL_SIZE//2), 300, BALL_SIZE, BALL_SIZE)
    ball.setFilled(True)
    ball.setColor("black")
    '''
    gw.add(ball, GWINDOW_WIDTH / 2, GWINDOW_HEIGHT / 2)
Example #24
0
 def __init__(self, node):
     GCompound.__init__(self)
     self._node = node
     frame = GRect(ArpanetMonitor.WIDTH,
                   ArpanetMonitor.MAX_NODES * ArpanetMonitor.VSPACE)
     self.add(frame, 0, ArpanetMonitor.VSPACE)
     label = GLabel(node.getName())
     label.setFont(ArpanetMonitor.FONT)
     x = ArpanetMonitor.MARGIN
     y = label.getAscent()
     self.add(label, x, y)
     self._label = label
     self._lines = []
     for i in range(ArpanetMonitor.MAX_NODES):
         y += ArpanetMonitor.VSPACE
         label = GLabel("")
         label.setFont(ArpanetMonitor.FONT)
         self.add(label, x, y)
         self._lines.append(label)
     self.update()
Example #25
0
def createEmptySnowman(gw):
    """
    Creates an empty GCompound to use as the snowman and adds it to
    the window at the correct location. This function then returns
    the GCompound for use in later calls to addSnowmanPart.
    """
    snowman = GCompound()
    x = GWINDOW_WIDTH / 2
    y = GWINDOW_HEIGHT - SNOWMAN_BASE
    gw.add(snowman, x, y)
    return snowman
Example #26
0
    def __init__(self, rotor):
        ''' 
		The constructor initalizes the selector in the standard setting in the
		three rotor model.
		'''
        GCompound.__init__(self)
        self.offset = rotor
        self.rotor = rotor
        button = createFilledRect(-SELECTOR_WIDTH / 2,
                                  -SELECTOR_HEIGHT / 2,
                                  SELECTOR_WIDTH,
                                  SELECTOR_HEIGHT,
                                  fill=SELECTOR_BGCOLOR,
                                  border=SELECTOR_COLOR)
        button.setLineWidth(3)
        setting = GLabel(str(self.offset))
        setting.setFont(SELECTOR_FONT)
        setting.setColor(SELECTOR_COLOR)
        self.setting = setting
        self.add(button)
        self.add(setting, -setting.getWidth() / 2, SELECTOR_LABEL_DY)
Example #27
0
def createSierpinskiTriangle(size, order):
    whole = GCompound()

    def createTriangle(size, order, dx, dy):
        if order == 0:
            drawTriangle(size, dx, dy, whole)
        else:
            createTriangle(size / 2, order - 1, dx + size / 4,
                           dy - size / 4 * math.sqrt(3))
            createTriangle(size / 2, order - 1, dx, dy)
            createTriangle(size / 2, order - 1, dx + size / 2, dy)

    createTriangle(size, order, 0, 0)
    gw.add(whole, (GWINDOW_WIDTH - size) / 2,
           (GWINDOW_HEIGHT + size * math.sqrt(3) / 2) / 2)
Example #28
0
 def __init__(self, color, level, puzzle):
     """Creates a piece with the indicated color and initial level"""
     GCompound.__init__(self)
     self._level = level
     self._puzzle = puzzle
     self.setColor(color)
     frame = GRect(PIECE_WIDTH, PIECE_HEIGHT)
     frame.setFilled(True)
     frame.setColor(PIECE_COLOR)
     self.add(frame, -PIECE_WIDTH / 2, 0)
     poly = GPolygon()
     dw = PIECE_WIDTH / puzzle.getNLevels()
     w0 = (level - 1) * dw
     w1 = level * dw
     poly.addVertex(-w0 / 2, 0)
     poly.addVertex(w0 / 2, 0)
     poly.addVertex(w1 / 2, PIECE_HEIGHT)
     poly.addVertex(-w1 / 2, PIECE_HEIGHT)
     poly.setFilled(True)
     poly.setColor(color)
     self.add(poly)
     border = GRect(PIECE_WIDTH, PIECE_HEIGHT)
     border.setColor(BORDER_COLOR)
     self.add(border, -PIECE_WIDTH / 2, 0)
Example #29
0
	def createRedCross(w, h):
		cross = GCompound()
		rect_1 = GRect(-w / 2, -h / 2, LONG_SIDE, SHORT_SIDE)
		rect_1.setFilled(True)
		rect_1.setColor('red')
		cross.add(rect_1)
		rect_2 = GRect(-h / 2, -w / 2, SHORT_SIDE, LONG_SIDE)
		rect_2.setFilled(True)
		rect_2.setColor('red')
		cross.add(rect_2)
		return cross
Example #30
0
def createButton(s):# makes a button with the string s
    button=GCompound()
    buttonSize=75
    label=GLabel(s)
    label.setColor("white")
    label.setFont("8px 'Sans-Serif'")
    c=GOval(-(label.getWidth()+20)//2,-buttonSize//2,label.getWidth()+20,buttonSize)
    c.setFillColor("black")
    c.setFilled(True)
    button.add(c)
    button.add(label,-label.getWidth()//2,0)
    return button