示例#1
0
 def draw(self):
     p = picture.Picture("avatar.gif")
     x = (self.x+0.5)*Tile.SIZE
     y = (self.y+0.5)*Tile.SIZE
     StdDraw.picture(p,x,y)
     if self.timer < 100:
         StdDraw.text(x,y,str(self.hp))
示例#2
0
def circle(n, fullN, x, y, size, turn, colorSet):
    setColor(colorSet, n, fullN)
    StdDraw.setPenRadius(0.01 * n / fullN)
    geom(1, x, y, size)
    geom(0, x, y, size / 2)
    n -= 1
    if n > 0:
        a = size**1.1
        if turn == 0:
            circle(n, fullN, x, y + (size + a), a, 1, colorSet)
            circle(n, fullN, x + (size + a), y, a, 2, colorSet)
            circle(n, fullN, x, y - (size + a), a, 3, colorSet)
            circle(n, fullN, x - (size + a), y, a, 4, colorSet)
        elif turn == 1:
            circle(n, fullN, x, y + (size + a), a, 1, colorSet)
            if n % 2 == 0:
                circle(int(n / 2), fullN, x + (size + a), y, a, 2, colorSet)
                circle(int(n / 2), fullN, x - (size + a), y, a, 4, colorSet)
        elif turn == 2:
            circle(n, fullN, x + (size + a), y, a, 2, colorSet)
            if n % 2 == 0:
                circle(int(n / 2), fullN, x, y + (size + a), a, 1, colorSet)
                circle(int(n / 2), fullN, x, y - (size + a), a, 3, colorSet)
        elif turn == 3:
            circle(n, fullN, x, y - (size + a), a, 3, colorSet)
            if n % 2 == 0:
                circle(int(n / 2), fullN, x + (size + a), y, a, 2, colorSet)
                circle(int(n / 2), fullN, x - (size + a), y, a, 4, colorSet)
        elif turn == 4:
            circle(n, fullN, x - (size + a), y, a, 4, colorSet)
            if n % 2 == 0:
                circle(int(n / 2), fullN, x, y + (size + a), a, 1, colorSet)
                circle(int(n / 2), fullN, x, y - (size + a), a, 3, colorSet)
示例#3
0
 def __init__(self, filename):
     with open(filename, 'r') as f:
         l = f.readline().split()
         self.width = int(l[0])
         self.height = int(l[1])
         l = f.readline().split()
         self.avatar = Avatar(int(l[0]), int(l[1]), int(l[2]), int(l[3]),
                              float(l[4]))
         self.tiles = [[None for i in range(self.height)]
                       for j in range(self.width)]
         for i in range(self.height - 1, -1, -1):
             l = f.readline().split()
             for j in range(0, self.width):
                 self.tiles[j][i] = Tile(l[j])
                 #print(self.tiles[j][i].name)
         self.mons = []
         for line in f:
             l = line.split()
             if len(l) == 6:
                 m = Monster(self, l[0], int(l[1]), int(l[2]), int(l[3]),
                             int(l[4]), int(l[5]))
                 t = threading.Thread(target=m.run)
                 self.mons.append(m)
                 t.start()
     f.close()
     self.lock = threading.Lock()
     StdDraw.setCanvasSize(self.width * Tile.SIZE, self.height * Tile.SIZE)
     StdDraw.setXscale(0.0, self.width * Tile.SIZE)
     StdDraw.setYscale(0.0, self.height * Tile.SIZE)
     StdDraw.setFontSize(12)
     StdDraw.setPenColor(StdDraw.RED)
示例#4
0
 def background(self, s):
     self.setUp(s)
     turn = 0.0
     StdDraw.setPenColor(StdDraw.WHITE)
     for i in range(0, 8):
         turn += 2 * math.pi / 8
         self.tree(9, 0, 0, s, turn)
示例#5
0
def anim(n, line):
    for i in range(1, n + 1):
        d = Dragon()
        d.curve(i, line)
        StdDraw.clear()
        d.draw()
        StdDraw.show(1000)
示例#6
0
 def draw(self):
     p = picture.Picture(self.name)
     x = (self.x+0.5)*Tile.SIZE
     y = (self.y+0.5)*Tile.SIZE
     if self.world.tiles[self.x][self.y].getLit():
         StdDraw.picture(p,x,y)
         if self.timer < 3:
             StdDraw.text(x,y,str(self.hp))
示例#7
0
    def draw(self, x, y):
        p = picture.Picture("blank.gif")
        if self.lit:
            p = picture.Picture(self.name)
        StdDraw.picture(p, (x + 0.5) * self.SIZE, (y + 0.5) * self.SIZE)

        ##### YOUR CODE HERE #####
        pass
示例#8
0
 def oDraw(self):
     le = len(self.list)
     for i in range(le):
         v = i / le
         #print(v)
         StdDraw.setPenColor(self.setColor(v))
         StdDraw.filledSquare(self.list[i].x + 0.5, self.list[i].y + 0.5,
                              0.5)
示例#9
0
 def dragonCurve(self, n, size, xPos, yPos, turn):
     if n < 1:
         n = 1
     for i in range(0, n):
         StdDraw.clear()
         StdDraw.setPenColor(Color(0, 0, 0))
         StdDraw.filledRectangle(-s, -s, 2 * s, 2 * s)
         StdDraw.setPenColor(Color(255, 0, 0))
         self.curve(i, size, xPos, yPos, turn, True)
         StdDraw.show(500)
示例#10
0
def runCube():
    c = Cube()
    while True:
        x = random.random()
        y = random.random()
        cols = c.randColors()
        size = random.random() / 2
        c.cube(5, x, y, size, cols)
        StdDraw.show(1)
        time.sleep(1)
示例#11
0
 def colorDraw(self,paths):
     drawing = True
     colors = [StdDraw.RED,StdDraw.ORANGE,StdDraw.YELLOW,StdDraw.GREEN,StdDraw.CYAN,StdDraw.BLUE,StdDraw.DARK_BLUE,StdDraw.MAGENTA,StdDraw.VIOLET]
     while drawing:
         for i in range(0,len(paths)):
             spin = i
             while spin >= len(colors):
                 spin -= len(colors)
             StdDraw.setPenColor(colors[spin])
             drawing = paths[i].draw()
         StdDraw.show(100)
示例#12
0
 def recursiveLines(self, n, nn, x, y, s, t):
     StdDraw.setPenRadius(0.015 * n / nn)
     xOne = x + s * math.cos(t)
     yOne = y + s * math.sin(t)
     StdDraw.line(x, y, xOne, yOne)
     n -= 1
     if n > 0:
         s -= s / (10 * (nn - n))
         tt = math.pi / 3 / n
         self.recursiveLines(n, nn, xOne, yOne, s, t - tt)
         self.recursiveLines(n, nn, xOne, yOne, s, t + tt)
示例#13
0
def customLine():
    print("Please select a start point")
    pOne = customPoint()
    print("Please select an end point")
    pTwo = customPoint()
    line = Line(pOne, pTwo)
    StdDraw.setPenColor(StdDraw.BLACK)
    line.draw(50)
    StdDraw.setPenColor(StdDraw.WHITE)
    line.draw(50)
    return line
示例#14
0
def draw(l, n):
    p = l.getStart()
    x = p.X()
    y = p.Y()
    s = l.getSize()
    t = l.getTurn()
    setPenColor()
    if n == 1:
        Leaf.leaf(x, y, s, t)
    elif n == 2:
        Tree.tree(x, y, s, t)
    StdDraw.show(10)
示例#15
0
 def draw(self, x, y):
     if self.value != None:
         StdDraw.setPenColor(StdDraw.BLACK)
         StdDraw.text(x, y, str(self.value))
     elif self.testValue != None:
         StdDraw.setPenColor(StdDraw.RED)
         StdDraw.text(x, y, str(self.testValue))
示例#16
0
def tree(n, fullN, x, y, size, turn, colorSet):
    setColor(colorSet, n, fullN)
    StdDraw.setPenRadius(0.015 * n / fullN)
    extra = [
        float(x) + size * math.cos(turn),
        float(y) + size * math.sin(turn)
    ]
    geom(2, x, y, extra)
    n -= 1
    if n > 0:
        size -= size / (10 * (fullN - n))
        tilt = (math.pi / 3) / n
        tree(n, fullN, extra[0], extra[1], size, turn - tilt, colorSet)
        tree(n, fullN, extra[0], extra[1], size, turn + tilt, colorSet)
示例#17
0
def customPoint():
    point = None
    while point == None:
        if StdDraw.mousePressed():
            point = Point(StdDraw.mouseX(), StdDraw.mouseY())
        StdDraw.show(10)
    StdDraw.setPenColor(StdDraw.BLACK)
    point.draw(50)
    StdDraw.setPenColor(StdDraw.WHITE)
    point.draw(50)
    return point
示例#18
0
 def animLine(self,x,y,s,t):
     scale = 100
     xOne = x + s*math.cos(t)
     yOne = y + s*math.sin(t)
     a = (math.sqrt(0.5)**self.fullN)/(2**(self.fullN-1))
     oldXone = self.oldX + a
     c = self.setColor()
     for i in range(1,scale):
         StdDraw.setPenColor(self.scaleColor(c,i/scale))
         scaleX = self.oldX + (x-self.oldX)*i/scale
         scaleY = y*i/scale
         scaleXone = oldXone + (xOne-oldXone)*i/scale
         scaleYone = yOne*i/scale
         self.drawLine(scaleX,scaleY,scaleXone,scaleYone)
     self.oldX += a
示例#19
0
def geom(geomType, x, y, extra):
    if geomType == 0:
        StdDraw.filledCircle(x, y, extra)
    elif geomType == 1:
        StdDraw.circle(x, y, extra)
    elif geomType == 2:
        StdDraw.line(x, y, extra[0], extra[1])
    StdDraw.show(0.001)
示例#20
0
 def drawTriangle(self, n, x, y, t, s, stage):
     if n > 0:
         xList = [
             x, x + s / 2 * math.cos(t - self.thirty),
             x + s * math.cos(t - self.right)
         ]
         yList = [
             y, y + s / 2 * math.sin(t - self.thirty),
             y + s * math.sin(t - self.right)
         ]
         self.setColor(stage)
         StdDraw.polygon(xList, yList)
         StdDraw.show(0.001)
         self.drawSquare(n, xList[1], yList[1], t - self.thirty,
                         s / 2 * self.sqrtThree, 1, stage)
         self.drawSquare(n, xList[1], yList[1], t + self.sixty, s / 2, -1,
                         stage + 1)
示例#21
0
 def background(self,n,s):
     self.setUp(s)
     StdDraw.setPenColor(Color(255,255,0))
     self.dragonCurve(n,1.0,0.0,0.0,0.0)
     StdDraw.setPenColor(Color(0,255,0))
     self.dragonCurve(n,1.0,0.0,0.0,math.pi/2)
     StdDraw.setPenColor(Color(0,0,255))
     self.dragonCurve(n,1.0,0.0,0.0,math.pi)
     StdDraw.setPenColor(Color(255,0,0))
     self.dragonCurve(n,1.0,0.0,0.0,3*math.pi/2)
示例#22
0
 def drawSquare(self, n, x, y, t, s, flip, stage):
     xList = [
         x, x + s * math.cos(t),
         x + s * self.sqrtTwo * math.cos(t - flip * self.fortyFive),
         x + s * math.cos(t - flip * self.right)
     ]
     yList = [
         y, y + s * math.sin(t),
         y + s * self.sqrtTwo * math.sin(t - flip * self.fortyFive),
         y + s * math.sin(t - flip * self.right)
     ]
     self.setColor(stage)
     StdDraw.polygon(xList, yList)
     StdDraw.show(0.001)
     if flip == 1:
         self.drawTriangle(n - 1, xList[1], yList[1], t, s, stage)
     else:
         self.drawTriangle(n - 1, xList[2], yList[2], t, s, stage)
示例#23
0
 def curve(self, n, s, x, y, t, sign):
     if n == 0:
         StdDraw.line(x, y, x + s * math.cos(t), y + s * math.sin(t))
     else:
         a = s * math.sqrt(0.5)
         if sign:
             t -= math.pi / 4
             self.curve(n - 1, a, x, y, t, True)
             x = x + a * math.cos(t)
             y = y + a * math.sin(t)
             t += math.pi / 2
             self.curve(n - 1, a, x, y, t, False)
         else:
             t += math.pi / 4
             self.curve(n - 1, a, x, y, t, True)
             x = x + a * math.cos(t)
             y = y + a * math.sin(t)
             t -= math.pi / 2
             self.curve(n - 1, a, x, y, t, False)
示例#24
0
def fern(n, fullN, x, y, size, turn, colorSet):
    setColor(colorSet, n, fullN)
    StdDraw.setPenRadius(0.01 * n / fullN)
    geom(0, x, y, size)
    n -= 1
    if n > 0:
        if turn == 0:
            a = size * 14 / 15
            fern(n, fullN, x, y + size + a, a, turn, colorSet)
            fern(n, fullN, x - 3 * size / 2, y, size / 2, 1, colorSet)
            fern(n, fullN, x + 3 * size / 2, y, size / 2, 1, colorSet)
        else:
            if x > 1.5:
                fern(n, fullN, x + size * 29 / 15,
                     y + math.sin(turn) * 2 * size, size * 14 / 15, turn + 1,
                     colorSet)
            else:
                fern(n, fullN, x - size * 29 / 15,
                     y + math.sin(turn) * 2 * size, size * 14 / 15, turn + 1,
                     colorSet)
示例#25
0
def recur(n, x, y, s, t, stage):
    xList = [
        x, x + s / math.sqrt(3) * math.cos(t + math.pi / 6),
        x + s * math.cos(t), x + s / math.sqrt(3) * math.cos(t - math.pi / 6)
    ]
    yList = [
        y, y + s / math.sqrt(3) * math.sin(t + math.pi / 6),
        y + s * math.sin(t), y + s / math.sqrt(3) * math.sin(t - math.pi / 6)
    ]
    StdDraw.filledPolygon(xList, yList)
    scale = math.sqrt(3)
    turn = math.pi / 6
    n -= 1
    if n > 0:
        if stage == 1:
            recur(n, xList[2], yList[2], 4 * s / 5, t, 1)
            recur(n, xList[1], yList[1], s / scale, t + turn, 1)
            recur(n, xList[3], yList[3], s / scale, t - turn, 1)
        else:
            recur(n, xList[2], yList[2], 1.5 * s, t, 1)
            recur(5, xList[1], yList[1], s / scale, t + turn, 1)
            recur(5, xList[3], yList[3], s / scale, t - turn, 1)
示例#26
0
 def outline(self, n, path):
     for i in range(1, n + 1):
         StdDraw.clear()
         paths = self.curve.dragonCurve(i, path, 1, [])
         self.curve.borderDraw(i, paths)
         StdDraw.show(500)
     print("Finished!")
     StdDraw.show(1000)
示例#27
0
 def colors(self, n, path):
     for i in range(1, n + 1):
         StdDraw.clear()
         paths = self.curve.dragonCurve(i, path, 1, [])
         self.curve.colorDraw(paths)
         StdDraw.show(500)
     print("Finished!")
     StdDraw.show(1000)
示例#28
0
    def __init__(self, filename):
        with open(filename, 'r') as f:
            l = f.readline().split()
            self.width = int(l[0])
            self.height = int(l[1])
            l = f.readline().split()
            self.player = Avatar(int(l[0]), int(l[1]))
            self.tiles = [[None for i in range(self.height)]
                          for j in range(self.width)]
            for i in range(self.height - 1, -1, -1):
                l = f.readline().split()
                for j in range(0, self.width):
                    self.tiles[j][i] = Tile(l[j])
                    #print(self.tiles[j][i].name)
        f.close()
        StdDraw.setCanvasSize(self.width * 16, self.height * 16)
        StdDraw.setXscale(0.0, self.width * 16)
        StdDraw.setYscale(0.0, self.height * 16)

        ##### YOUR CODE HERE #####
        pass
示例#29
0
 def drawLines(self,x,y,s,flip,scale):
     angle = math.pi/6
     xList = [x,x-s*math.sin(angle),x+s*math.sin(angle)]
     oneXlist = [x]
     twoXlist = [xList[1]]
     threeXlist = [xList[2]]
     yList = [y,y+flip*s*math.cos(angle),y+flip*s*math.cos(angle)]
     oneYlist = [y]
     twoYlist = [yList[1]]
     threeYlist = [yList[2]]
     for i in range(0,scale):
         oneXlist.append(x-(i+1)*s*math.sin(angle)/scale)
         twoXlist.append(xList[1]+(i+1)*s/scale)
         threeXlist.append(xList[2]-(i+1)*s*math.sin(angle)/scale)
         oneYlist.append(y+(i+1)*flip*s*math.cos(angle)/scale)
         twoYlist.append(y+flip*s*math.cos(angle))
         threeYlist.append(yList[2]-(i+1)*flip*s*math.cos(angle)/scale)
     for i in range(0,scale):
         StdDraw.line(oneXlist[i],oneYlist[i],twoXlist[i+1],twoYlist[i+1])
         StdDraw.line(twoXlist[i],twoYlist[i],threeXlist[i+1],threeYlist[i+1])
         StdDraw.line(threeXlist[i],threeYlist[i],oneXlist[i+1],oneYlist[i+1])
示例#30
0
 def start(self, s):
     tree.setUp(s)
     StdDraw.setPenColor(StdDraw.WHITE)
     tree.tree(9, 0, 0, s, 0)