示例#1
0
    def run(self):
        radius = 70
        (xoff, yoff) = (self.dim[0] / 2, self.dim[1] / 2)
        (xscale, yscale) = (1, 0.5)
        while True:
            if self.iter > 2 * math.pi:
                self.iter = 0
            self.iter += 0.01

            (x1, y1) = (math.cos(self.iter) * xscale, math.sin(self.iter) * yscale)
            (x2, y2) = (math.cos(self.iter + math.pi / 2) * xscale, math.sin(self.iter + math.pi / 2) * yscale)
            (x3, y3) = (int(-x1 * radius + xoff), int(-y1 * radius + yoff))
            (x4, y4) = (int(-x2 * radius + xoff), int(-y2 * radius + yoff))
            (x1, y1) = (int(x1 * radius + xoff), int(y1 * radius + yoff))
            (x2, y2) = (int(x2 * radius + xoff), int(y2 * radius + yoff))

            # self.lock.acquire()
            self.surface.fill(black)

            draw.lines(self.surface, green, True, [(x1, y1), (x2, y2), (x3, y3), (x4, y4)], 3)
            draw.lines(self.surface, green, True, [(x1, y1 - radius), (x2, y2 - radius), (x3, y3 - radius), (x4, y4 - radius)], 3)
            draw.line(self.surface, green, (x1, y1), (x1, y1 - radius), 3)
            draw.line(self.surface, green, (x2, y2), (x2, y2 - radius), 3)
            draw.line(self.surface, green, (x3, y3), (x3, y3 - radius), 3)
            draw.line(self.surface, green, (x4, y4), (x4, y4 - radius), 3)

            vdot = rotate_vector((0, 0.6), self.iter)
            draw.circle(self.surface, green, (int(vdot[0] * radius * xscale + xoff), int(vdot[1] * radius * yscale + yoff - radius)), 5)

            # self.clock.lock.acquire()
            self.surface.blit(self.clock.surface, (self.dim[0] - self.clock.get_dimensions()[0] - 10, 0))
            # self.clock.lock.release()

            # self.lock.release()
            time.sleep(0.005)
示例#2
0
def tieFighter (pos, screen, color, height=40):
    x, y = pos
    width = height/8
    draw.rect(screen, color, (x, y, width, height))
    draw.rect(screen, color, (x+height-width, y, width, height))
    draw.rect(screen, color, (x, y+(height-width)/2, height, width))
    draw.circle(screen, color, (x+height/2, y+height/2), height/4)
示例#3
0
文件: bspline.py 项目: homata/pycurve
def main():
    rect = Rect((0, 0), SCREEN_SIZE)
    surface = Surface(SCREEN_SIZE)
    pxarray = PixelArray(surface)
    P = [(0, 100), (100, 0), (200, 0), (300, 100), (400, 200), (500, 200),
         (600, 100), (400, 400), (700, 50), (800, 200)]
    n = len(P) - 1 # n = len(P) - 1; (P[0], ... P[n])
    k = 3          # degree of curve
    m = n + k + 1  # property of b-splines: m = n + k + 1
    _t = 1 / (m - k * 2) # t between clamped ends will be evenly spaced
    # clamp ends and get the t between them
    t = k * [0] + [t_ * _t for t_ in xrange(m - (k * 2) + 1)] + [1] * k

    S = Bspline(P, t, k)
    # insert a knot (just to demonstrate the algorithm is working)
    S.insert(0.9)

    step_size = 1 / STEP_N
    for i in xrange(STEP_N):
        t_ = i * step_size
        try: x, y = S(t_)
        # if curve not defined here (t_ is out of domain): skip
        except AssertionError: continue
        x, y = int(x), int(y)
        pxarray[x][y] = (255, 0, 0)
    del pxarray

    for p in zip(S.X, S.Y): draw.circle(surface, (0, 255, 0), p, 3, 0)
    SCREEN.blit(surface, (0, 0))

    while 1:
        for ev in event.get():
            if ev.type == KEYDOWN:
                if ev.key == K_q: exit()
        display.update()
示例#4
0
def draw_points(poly, surface, color=None, width=None):
    polygon = orient_multipoint(poly)
    c = polygon.centroid.coords[0]
    p = poly.position
    dx, dy = [p[i] - c[i] for i in range(2)]

    if color is None:
        color = (0,255,0)
    if width is None:
        width = 1

    maxd = (0,None,None)
    for i in range(len(polygon.geoms)):
        p = polygon.geoms[i]
        draw.circle(surface, color,
                    defloat(scale(offset((p.x,p.y), dx, dy))),
                    3*width)
        for j in range(i+1, len(polygon.geoms)):
            q = polygon.geoms[j]
            d = p.distance(q)
            if d > maxd[0]:
                maxd = (d, p, q)
    if maxd[0] > 0:
        p, q = maxd[1], maxd[2]
        draw.line(surface, color,
                  defloat(scale(offset((p.x,p.y), dx, dy))),
                  defloat(scale(offset((q.x,q.y), dx, dy))), width)
示例#5
0
 def draw(self, surface, offset):
     adjusted_center = (int(self.center[0] + offset[0]), int(self.center[1] + offset[1]))
     real_colour = [self.colour[i] + self.colour_change[i] * self.age for i in range(3)]
     
     # Typecast to an int to stop float warning
     radius = int(self.radius + self.radius_change * self.age)
     draw.circle(surface, bound_colour(real_colour), adjusted_center, radius, min(2, radius))
示例#6
0
def draw_tie(surf, color, pos, size=40):
    x, y = pos
    width = size/8
    draw.rect(surf, color, (x,y,width,size)) #first vertical line
    draw.rect(surf, color, (x+size-width,y,width,size)) #second vertical line
    draw.rect(surf, color, (x,y+(size-width)/2,size,width)) #middle horizontal
    draw.circle(surf, color, (x+size/2,y+size/2), size/4) #circle
def draw_tie(surf, pos, color=RED):
    "draw a tie fighter at location"
    x,y = pos
    draw.rect(surf, color, (x, y, 5, 40))
    draw.rect(surf, color, (x+35, y, 5, 40))
    draw.rect(surf, color, (x, y+17, 40, 5))
    draw.circle(surf, color, (x+20, y+20), 10)
示例#8
0
def test_filled_circles(test_surf):
    """Draw several filled circles"""
    for cent_x, color in ((100, (0, 0, 255, 255)), (400, (0, 255, 255, 255)), (600, (255, 0, 255, 255))):
        cent_y = 10
        for radius in range(10, 100, 10):
            cent_y += radius + 1
            draw.circle(test_surf, color, (cent_x, cent_y), radius)
示例#9
0
def draw_tie(surf, color, pos, size=40):
    x, y = pos
    width = size/8
    draw.rect(surf, color, (x,y,width,size))
    draw.rect(surf, color, (x+size-width,y,width,size))
    draw.rect(surf, color, (x,y+(size-width*5),size,width))
    draw.circle(surf, color, (x+size/2,y+size/2),size/4)
示例#10
0
def runGUI():
    pygame.display.set_mode((800,600))
    pygame.display.set_caption("Neuro Junk 2012/13")
    screen = pygame.display.get_surface()
    
    while True:
        input(pygame.event.get())
        
        screen.fill((0,0,0))
        circle(screen, (255,255,255), (0,0), radius, 1)
        line(screen, (255,255,255), point1, point2, 1)
        
        polygon(screen, (255,255,255), outer_line, 2)
        polygon(screen, (255,255,255), inner_line,2)
        
        if intersectCircle(point1, point2, radius):
            rect(screen, (0,255,0), Rect(600, 200, 100, 100), 0)
        
        inn = changeField(inner_line, car)
        out = changeField(outer_line, car)
        csect = curSection(inn, out)
        
        polygon(screen, (0,0,255), out, 2)
        polygon(screen, (0,0,255), inn, 2)
        
        rect(screen, (255,255,255), Rect(car.x-2, car.y-2, 4, 4), 0)
        
        if csect is not None:
            line(screen, (0,255,0), csect.inner_start, csect.inner_end, 1)
            line(screen, (0,255,0), csect.outer_start, csect.outer_end, 1)
        
        pygame.display.update()
示例#11
0
def drawGeom(geom):
	if type(geom) is ode.GeomBox:
		x, y, _ = geom.getPosition()
		a, b, _ = geom.getLengths()
		r = geom.getRotation()
		costheta = r[0]; sintheta = r[1]
		p1 = to_screen_pnt(x + a/2 * costheta + b/2 * sintheta, y - a/2 * sintheta + b/2 * costheta)
		p2 = to_screen_pnt(x + a/2 * costheta - b/2 * sintheta, y - a/2 * sintheta - b/2 * costheta)
		p3 = to_screen_pnt(x - a/2 * costheta - b/2 * sintheta, y + a/2 * sintheta - b/2 * costheta)
		p4 = to_screen_pnt(x - a/2 * costheta + b/2 * sintheta, y + a/2 * sintheta + b/2 * costheta)
		draw.lines(screen, actual_color(getattr(geom, 'color', blue)), True, [p1, p2, p3, p4])
	elif type(geom) is ode.GeomSphere:
		x, y, _ = geom.getPosition()
		r = geom.getRadius()
		rotmat = geom.getRotation()
		costheta = rotmat[0]; sintheta = rotmat[1]
		px, py = to_screen_pnt(x, y)
		pr = to_screen_len(r)
		draw.circle(screen, actual_color(getattr(geom, 'color', blue)), (int(px), int(py)), int(pr), 1)
		drawLine((x,y), (x + costheta * r, y - sintheta * r), getattr(geom, 'color', blue))
	elif type(geom) is ode.GeomCapsule:
		x, y, _ = geom.getPosition()
		pass
	elif isinstance(geom, ode.SpaceBase):
		for i in geom:
			drawGeom(i)
	else:
		assert False
示例#12
0
def test_hollow_circles(test_surf):
    """Draw several circles of different thicknesses and sizes"""
    for thickness in range(1, 7):
        cent_x = 100 + thickness * 50
        cent_y = 10
        for radius in range(10, 200, 10):
            cent_y += radius + 1
            draw.circle(test_surf, (255, 255, 255, 255), (cent_x, cent_y), radius, thickness)
示例#13
0
def drawTie(surf, color, pos, size=80):
    x, y = pos
    width = size / 8
    # Drawing Tie Fighter here
    draw.rect(surf, color, (x, y, width, size))
    draw.rect(surf, color, (x + size - width, y, width, size))
    draw.rect(surf, color, (x, y + (size - width) / 2, size, width))
    draw.circle(surf, color, (x + size / 2, y + size / 2), size / 4)
示例#14
0
def red_bike(surf, pos, color=(255, 0, 0), size=40):
    x, y = pos

    width = size / 8

    draw.circle(surf, color, (x, y, width, size))
    draw.rect(surf, color, (x + (size - width), y, width, size))
    draw.circle(surf, color, (x + size / 2, y + size / 2), size / 4)
示例#15
0
 def _show_detection(self):
     if hasattr(self.status, 'detected_by'):
         radius = 0
         for obj in self.status.detected_by:
             if obj.selected:
                 radius += 6
                 pos = (self.rect.width // 2, self.rect.height // 2)
                 circle(self.image, obj._debug_color, pos, radius, 3)
示例#16
0
文件: mob.py 项目: MacLeek/mh
def head(surface, mod, pos):
    # adjust for body size
    radius = ((mod["bodySize"] + 1) * 4) + 10

    color = skinColor(mod)

    draw.circle(surface, (0,0,0), pos, radius)
    draw.circle(surface, color, pos, int(radius * .90))
    return Rect(pos[0] - radius, pos[1] - radius, radius * 2, radius * 2)
示例#17
0
文件: ball.py 项目: kimthuy/pingpong
 def draw(self):
     # light = self._LIGHT
     # for px, py, r in self.trail[::-1]:
     #     pygame.draw.circle(self.surface,
     #                        (light,0,0),
     #                        list(map(Utils.round_int,[px,py])),
     #                        r)
     #     light += self._LIGHT
     draw.circle(self.surface, self._COLOR, list(map(Utils.round_int, self.pos)), self.radius)
示例#18
0
def drawTieFighter(surf, pos, size = 40, col=(100,100,100)):
    width = size / 8

    x,y = pos
    
    draw.rect(screen, col, (x+0, y+0, width, size))
    draw.rect(screen, col, (x+size - width, y, width, size))
    draw.rect(screen, col, (x, y + (size - width)/2, size,width))
    draw.circle(screen, col, (x + size/2, y+ size / 2), size/4)
示例#19
0
文件: inter.py 项目: chqiwang/gobang
def draw_chess(screen, gobang):
    board = gobang.board
    cols, rows = board.shape
    chess_radius = grid_size / 2 - 2
    for c in xrange(cols):
        for r in xrange(rows):
            v = board[(c,r)]
            if v in chess_colors:
                draw.circle(screen, chess_colors[v], to_pixel_pos((c, r)), chess_radius)
示例#20
0
	def display(self, surface):

		myfont = font.Font(None, 2*self.display_weight)
		label = myfont.render(self.label, 1, Config.vertex_label_color)

		d_pos = ( int(self.x) + (Config.frameWidth/2), int(self.y) + (Config.frameHeight/2) )
		circle(surface, self.color, d_pos, self.display_weight, self.width)

		surface.blit(label, (d_pos[0]+self.display_weight+5,d_pos[1]))
示例#21
0
def draw_tie(surf, pos, color=(255,0,0), size=40):
    "Draws a tie fighter"
    x,y = pos
    
    width = size/8

    draw.rect(surf, color, (x, y, width, size))
    draw.rect(surf, color, (x+(size-width), y, width, size))
    draw.rect(surf, color, (x, y+(size-width)/2, size, width))
    draw.circle(surf, color, (x+size/2, y+size/2), size/4)
示例#22
0
文件: me.py 项目: bluepeppers/me
 def draw(self, surface):
     pos = self.spiral.screen.adjust_to_viewport(self.cart())
     if not self.screen.collidepoint(pos):
         return
     pos = map(int, pos)
     if self.unhittable:
         color = (100, 100, 100)
     else:
         color = self.spiral.screen.gc("avatar", self.color)
     draw.circle(surface, color, pos, 10, 1 if self.hit else 0)
示例#23
0
文件: players.py 项目: 3201101/3I025
 def build_Turtle_list_images(self,w,h):
     """ cree 360 images de tortues (une par degre)"""
     imglist = [pygame.Surface((w,h)).convert() for a in range(360)]
     for a,img in zip(range(360),imglist):
         img.set_colorkey( (0,0,0) )
         img.fill((0,0,0))
         circle(img, glo.WHITE, (w/2,h/2), self.taille_geometrique/2 - self.penwidth,self.penwidth)
         polygons.draw_arrow(img,w/2,h/2,a * pi/180,r=self.taille_geometrique-14,clr=glo.WHITE)
         #pygame.gfxdraw.aacircle(self.image, w/2,h/2, self.taille_geometrique/2 - self.penwidth,glo.WHITE)
     return imglist
示例#24
0
文件: infobar.py 项目: haitike/pyRTS
 def update(self, seconds):
     self.paintmap()
     draw.rect(self.image, (255,255,255), (round(-game_data.camera[0] * self.factorx,0),
                                                  round(-game_data.camera[1] * self.factory,0),
                                                  round(game_data.width * self.factorx, 0),
                                                  round((game_data.height - game_data.infobar_height) * self.factory, 0)),1)
     for unit in groups.unitgroup:
         pos = unit.trueX, unit.trueY
         draw.circle(self.image, unit.owner.color, (int(pos[0] * self.factorx),
                                               int(pos[1] * self.factory)), unit.size )
示例#25
0
def draw_tie(surf, tie):
    "Draws a tie fighter"
    color = 255,0,0
    x,y,dx,dy,size = tie
    
    width = size/8

    draw.rect(surf, color, (x, y, width, size))
    draw.rect(surf, color, (x+(size-width), y, width, size))
    draw.rect(surf, color, (x, y+(size-width)/2, size, width))
    draw.circle(surf, color, (x+size/2, y+size/2), size/4)
示例#26
0
def draw_tie(surf, pos, color=(randrange(100,256), randrange(100,256), randrange(100,256)), size=40):
    "Draws a tie fighter"
    x,y = pos
    
    wall = size/8
    x0,x1 = x - (size/2), x + (size/2)
    y0,y1 = y - (size/2), y + (size/2)

    draw.rect(surf, color, (x0, y0, wall, size))
    draw.rect(surf, color, (x1-wall, y0, wall, size))
    draw.rect(surf, color, (x0, y-(wall/2), size, wall))
    draw.circle(surf, color, (x, y), size/4)
示例#27
0
 def __init__(self):
     super(Bullet, self).__init__()
     self.r = config.bulletR
     self.m = config.bulletM
     self.shape = ShapeCircle(self.r)
     self.t = 0
     self.length = 0
     self.I = 0
     self.damage = 0
     # image
     self.image = Surface(Size).convert_alpha()
     self.image.fill((0, 0, 0, 0))
     self.rect = Rect((0, 0), Size)
     draw.circle(self.image, (0, 0, 0, 0xff), self.rect.center, self.r)
示例#28
0
 def draw(self):
     dr.circle(screen, self.color, self.pos, self.size)
示例#29
0
文件: cv8.py 项目: hruskaz/python
from pygame import display, draw, time, event
import random
import pygame
import sys

screen = display.set_mode([800,600])
clock = time.Clock()
circles = []
random.seed()

while True:
	screen.fill([0,0,0])
	action = event.poll()
	if action.type == pygame.KEYDOWN:
		sys.exit()
	for i in range(len(circles)-1):
		lst = list(circles[i])
		lst[3] += 1
		circles[i] = tuple(lst)
		draw.circle(circles[i][0],circles[i][1],circles[i][2],circles[i][3],circles[i][4])
	
	reusedCircles = []
	for i in range(len(circles)):
		if circles[i][3] <= 80:
			reusedCircles.append(circles[i])
	circles = reusedCircles
	
	if len(circles) <= 20:
		circles.append((screen, [255,255,255], [random.randint(0,800),random.randint(0,600)],0,1))	
	display.flip()
	clock.tick(60)
            done = True

        if is_red: color2 = (0, 0, 255)
        else: color2 = (255, 0, 0)

        if is_red: color = (255, 0, 0)
        else: color = (0, 0, 255)

        screen.fill((0, 0, 0))

        if xp <= r: xp = r
        if yp <= r: yp = r
        if xp >= col_right: xp = col_right
        if yp >= col_bott: yp = col_bott

        draw.circle(screen, color, (xp, yp), r)

        draw.circle(screen, color2, (xf, yf), r)

        timerString = timerFont.render(gameTimer.render(), True,
                                       (255, 255, 255))
        screen.blit(timerString, (0, 0))

        display.flip()
        clock.tick(60)

    while done:
        for e in event.get():
            if e.type == QUIT:
                quit()
                exit()
示例#31
0
def draw_tie(surf, color, pos):
    x,y = pos
    draw.rect(surf, color, (x,y,5,40))
    draw.rect(surf, color, (x+35,y,5,40))
    draw.rect(surf, color, (x,y+17,40,5))
    draw.circle(surf, color, (x+20,y+20), 10)
示例#32
0
    def render(self):
        global game, fadeout
        if self.hp > 0:
            # Наклон картинки
            self.angle = angle_calc(self.x, self.y, self.aim[0], self.aim[1])

            self.image_active = rotate(self.images[self.state], self.angle)

            # Обработка нажатия клавиш
            if self.up:
                if self.dy - self.Acceleration > -self.Move:
                    self.dy -= self.Acceleration
                else:
                    self.dy = -self.Move
            if self.down:
                if self.dy + self.Acceleration < self.Move:
                    self.dy += self.Acceleration
                else:
                    self.dy = self.Move
            if self.left:
                if self.dx - self.Acceleration > -self.Move:
                    self.dx -= self.Acceleration
                else:
                    self.dx = -self.Move
            if self.right:
                if self.dx + self.Acceleration < self.Move:
                    self.dx += self.Acceleration
                else:
                    self.dx = self.Move

            if self.click:
                if not self.rect.collidepoint(self.aim):
                    if ((self.shoot_delay0 >= weapons[self.weapon]['rate']) and (self.rapidfire0 == 0)) or \
                            ((self.shoot_delay0 >= weapons[self.weapon]['rate'] // 2) and (self.rapidfire0 != 0)):
                        if self.bullet_count0 < weapons[self.weapon]['bull_c']:

                            self.shoot_delay0 = 0
                            self.bullet_count0 += 1
                            self.state = 'active'

                            # Создание пули
                            if self.weapon == 'flamethrower':
                                Player.bullet.append(
                                    Bullet(
                                        self.x, self.y, self.weapon,
                                        self.fire_bullet,
                                        uniform(self.angle - 30,
                                                self.angle + 30)))
                            elif self.weapon == 'shotgun':
                                Player.bullet.extend(
                                    Bullet(
                                        self.x, self.y, self.weapon,
                                        self.fire_bullet,
                                        uniform(self.angle - 10, self.angle +
                                                10)) for n in range(2))
                            elif self.weapon == 'ak47':
                                Player.bullet.append(
                                    Bullet(
                                        self.x, self.y, self.weapon,
                                        self.fire_bullet,
                                        uniform(self.angle - 8,
                                                self.angle + 8)))
                            elif self.weapon == 'm249':
                                Player.bullet.append(
                                    Bullet(
                                        self.x, self.y, self.weapon,
                                        self.fire_bullet,
                                        uniform(self.angle - 15,
                                                self.angle + 15)))
                            elif self.weapon in ['gun', 'rifle', 'launcher']:
                                Player.bullet.append(
                                    Bullet(self.x, self.y, self.weapon,
                                           self.fire_bullet, self.angle))

                            # Звук выстрела
                            weapons[self.weapon]['sound'].play()

                            # Эффекы при выстреле
                            if self.weapon != 'flamethrower':
                                Player.effects.append(
                                    Effect(self.x, self.y, self.angle, 5,
                                           'fire'))
            if self.shoot_delay0 + 1 <= weapons[self.weapon]['rate']:
                self.shoot_delay0 += 1

        # Перезарядка
        if weapons[self.weapon]['bull_c'] <= self.bullet_count0:
            self.reload0 += 1

        if self.reload0 == 1:
            if self.weapon != 'launcher':
                weapons[self.weapon]['sound_r'].play()

        if self.reload0 >= weapons[self.weapon]['reload']:
            self.reload0 = self.bullet_count0 = 0

        # Скорострельный режим
        if self.rapidfire0 > 0:
            self.rapidfire0 += 1
        if self.rapidfire0 >= self.rapidfire:
            self.rapidfire0 = 0

        # Торможение
        if (self.up is False) and (self.down is False):
            if self.dy - self.Break > 0:
                self.dy -= self.Break
            elif self.dy + self.Break < 0:
                self.dy += self.Break
            else:
                self.dy = 0
        if (self.left is False) and (self.right is False):
            if self.dx - self.Break > 0:
                self.dx -= self.Break
            elif self.dx + self.Break < 0:
                self.dx += self.Break
            else:
                self.dx = 0

        # Бронежилет
        if self.armor > 0:
            circle(Player.screen, (48, 163, 244),
                   Player.camera.get_pos(self.x, self.y, True), 25,
                   int(self.armor / 20 + 1))

        # Отображение картинки
        Player.screen.blit(
            self.image_active,
            Player.camera.get_pos(self.x - self.image_active.get_width() // 2,
                                  self.y -
                                  self.image_active.get_height() // 2))

        # Границы мира
        if (self.x <= self.image_active.get_width() // 2) and (self.dx < 0):
            self.dx = 0
            self.x = self.image_active.get_width() // 2
        if (self.x + self.image_active.get_width() // 2 >=
                F_SIZE[0]) and (self.dx > 0):
            self.dx = 0
            self.x = F_SIZE[0] - self.image_active.get_width() // 2
        if (self.y <= self.image_active.get_height() // 2) and (self.dy < 0):
            self.dy = 0
            self.y = self.image_active.get_height() // 2
        if (self.y + self.image_active.get_height() // 2 >=
                F_SIZE[1]) and (self.dy > 0):
            self.dy = 0
            self.y = F_SIZE[1] - self.image_active.get_height() // 2

        # Жизни героя
        if self.hp <= 0:
            self.hp = 0
            if self.weapon != 'launcher':
                weapons[self.weapon]['sound_r'].stop()
            fadeout.set_alpha(fadeout.get_alpha() + 1)
            self.up = self.down = self.right = self.left = self.click = False

        if self.hurt:
            self.hurt_delay0 += 1
        if self.hurt_delay0 > 0:
            self.hurt_delay0 += 1
        if self.hurt_delay0 >= self.hurt_delay:
            self.hurt = False
            self.hurt_delay0 = 0

        # Перемещение
        self.x += self.dx
        self.y += self.dy

        # Столкновение
        self.rect.centerx = self.x
        self.collision(self.dx, 0)

        self.rect.centery = self.y
        self.collision(0, self.dy)
 def recolorBase(self,value:float):
     edge = Color(int(min(255 * (2 - 2 * value), 255)), int(min(255 * value * 2, 255)), 0)
     self.surface.fill(edge)
     draw.rect(self.surface, Color(0, 0, 0),
               Rect(self.sizeX / 10, self.sizeY / 10, self.sizeX * 0.8, self.sizeY * 0.8))
     draw.circle(self.surface, Color(0, 0, 80), (self.sizeX / 2, self.sizeX / 2), (self.sizeX * 0.4))
示例#34
0
def DrawBubbles(Bubbles):
    for bubble in Bubbles:
        draw.circle(screen, bubble.colour, bubble.center, bubble.radius, 1)
        if bubble.radius < 50:
            bubble.expand()
示例#35
0
def draw(a, screen):
    """Draws an object on the screen
    """
    circle(screen, a.colour,
           (norm_pos(a.x) + width / 2, norm_pos(a.y) + height / 2),
           norm_rad(a.radius), 0)
示例#36
0
 def __init__(self, parent_obj, location, radius, load_img=False):
     super().__init__(parent_obj, location, radius * 2, radius * 2,
                      load_img)
     self.radius = radius
     draw.circle(self.surface, Color("#2931b3"), [self.radius, self.radius],
                 self.radius)
示例#37
0
 def show(self, surface):
     for ray in self.rays:
         ray.show(surface)
     draw.circle(surface, self.color, self.pos/4, 6)
示例#38
0
from random import randint

import pygame
from pygame import display, draw, time, event


class circle:
    def __init__(self):
        self.color = [randint(0, 255), randint(0, 255), randint(0, 255)]
        self.center = [randint(0, 800), randint(0, 600)]
        self.radius = 1
        self.maxr = randint(20, 100)


screen = display.set_mode([800, 600])
clock = time.Clock()
drops = []
while True:
    screen.fill([0, 0, 0])
    for d in drops[:]:
        draw.circle(screen, d.color, d.center, d.radius, 1)
        d.radius += 1
        if d.radius >= d.maxr: drops.remove(d)
    drops.append(circle())
    display.flip()
    clock.tick(60)
    if event.poll().type == pygame.KEYDOWN: break
示例#39
0
 def draw(self, screen):
     draw.circle(screen, self.color, [int(self.x), int(self.y)],
                 int(width / len(particles) / 2))
示例#40
0
def circle(x, y, radius, color, width=0):
    """Zeichnet einen Kreis.

        X und y sind der Mittelpunkt"""
    pydraw.circle(DISPLAY, color, (x, y), radius, width)
示例#41
0
文件: dialog.py 项目: 602p/spacegame
 def _draw_close_over(self, image, size):
     image.fill(self._settings["col_border"])
     draw.circle(image, (234, 14, 50), (size[0] / 2, size[1] / 2), 8)
     draw.line(image, (0, 0, 1), (5, 5), (11, 11), 5)
     draw.line(image, (0, 0, 1), (5, 11), (11, 5), 5)
示例#42
0
    def _draw(self, deco: List[Tuple[int, str, Any]],
              surface: 'pygame.Surface') -> None:
        """
        Draw.

        :param deco: Decoration list
        :param surface: Pygame surface
        :return: None
        """
        if len(deco) == 0:
            return
        rect = self._obj.get_rect()

        for d in deco:
            dtype, decoid, data = d
            if not self._decor_enabled[decoid]:
                continue

            if dtype == DECORATION_POLYGON:
                points, color, filled, width, gfx, kwargs = data
                points = self._update_pos_list(rect, decoid, points, **kwargs)
                if gfx:
                    if filled:
                        gfxdraw.filled_polygon(surface, points, color)
                    else:
                        gfxdraw.polygon(surface, points, color)
                else:
                    pydraw.polygon(surface, color, points, width)

            elif dtype == DECORATION_CIRCLE:
                points, r, color, filled, width, gfx, kwargs = data
                points = self._update_pos_list(rect, decoid, points, **kwargs)
                x, y = points[0]
                if filled:
                    if gfx:
                        gfxdraw.filled_circle(surface, x, y, r, color)
                    else:
                        pydraw.circle(surface, color, (x, y), r)
                else:
                    pydraw.circle(surface, color, (x, y), r, width)

            elif dtype == DECORATION_SURFACE or dtype == DECORATION_BASEIMAGE or dtype == DECORATION_TEXT:
                pos, surf, centered, kwargs = data
                if isinstance(surf, pygame_menu.BaseImage):
                    surf = surf.get_surface(new=False)
                pos = self._update_pos_list(rect, decoid, pos, **kwargs)[0]
                surfrect = surf.get_rect()
                surfrect.x += pos[0]
                surfrect.y += pos[1]
                if centered:
                    surfrect.x -= surfrect.width / 2
                    surfrect.y -= surfrect.height / 2
                surface.blit(surf, surfrect)

            elif dtype == DECORATION_ELLIPSE:
                pos, rx, ry, color, filled, kwargs = data
                pos = self._update_pos_list(rect, decoid, pos, **kwargs)[0]
                if filled:
                    gfxdraw.filled_ellipse(surface, pos[0], pos[1], rx, ry,
                                           color)
                else:
                    gfxdraw.ellipse(surface, pos[0], pos[1], rx, ry, color)

            elif dtype == DECORATION_CALLABLE:
                data(surface, self._obj)

            elif dtype == DECORATION_CALLABLE_NO_ARGS:
                data()

            elif dtype == DECORATION_TEXTURE_POLYGON:
                pos, texture, tx, ty, kwargs = data
                pos = self._update_pos_list(rect, decoid, pos, **kwargs)
                if isinstance(texture, pygame_menu.BaseImage):
                    texture = texture.get_surface()
                gfxdraw.textured_polygon(surface, pos, texture, tx, ty)

            elif dtype == DECORATION_ARC:
                points, r, ia, fa, color, width, gfx, kwargs = data
                points = self._update_pos_list(rect, decoid, points, **kwargs)
                x, y = points[0]
                rect_arc = pygame.Rect(x - r, y - r, x + 2 * r, y + 2 * r)
                if gfx:
                    gfxdraw.arc(surface, x, y, r, ia, fa, color)
                else:
                    pydraw.arc(surface, color, rect_arc, ia / (2 * pi),
                               fa / (2 * pi), width)

            elif dtype == DECORATION_PIE:
                points, r, ia, fa, color, kwargs = data
                points = self._update_pos_list(rect, decoid, points, **kwargs)
                x, y = points[0]
                gfxdraw.pie(surface, x, y, r, ia, fa, color)

            elif dtype == DECORATION_BEZIER:
                points, color, steps, kwargs = data
                points = self._update_pos_list(rect, decoid, points, **kwargs)
                gfxdraw.bezier(surface, points, steps, color)

            elif dtype == DECORATION_FILL:
                surface.fill(data, rect)

            elif dtype == DECORATION_RECT:
                drect: 'pygame.Rect'
                pos, drect, color, width, kwargs = data
                pos = self._update_pos_list(rect, decoid, pos, **kwargs)[0]
                drect = drect.copy()
                drect.x += pos[0]
                drect.y += pos[1]
                pygame.draw.rect(surface, color, drect, width)

            elif dtype == DECORATION_PIXEL:
                pos, color, kwargs = data
                pos = self._update_pos_list(rect, decoid, pos, **kwargs)[0]
                gfxdraw.pixel(surface, pos[0], pos[1], color)

            elif dtype == DECORATION_LINE:
                pos, color, width, kwargs = data
                pos = self._update_pos_list(rect, decoid, pos, **kwargs)
                pydraw.line(surface, color, pos[0], pos[1], width)

            else:
                raise ValueError('unknown decoration type')
 def draw(self, surface):
     draw.circle(surface, Colors.white, self.pos.int_tuple(), Projectile.max_radius)
示例#44
0
for s in range(iterations):
    '''  
    A single movement/action/update...
    '''
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
             pygame.quit(); sys.exit();
    
    takeAction()

    for i in range(0, grid_h):
        for j in range(0, grid_w):

            x,y = j*pixWid+offset, i*pixWid+offset
            circle(gui, (190,190,190), (x,y), rad, 0)
            
            q = state[i][j].quality  # [up-q, right-q, down-q, left-q]
            
            line(gui,color(q[0]),True,((x-ll,y-rad),(x-ll,y-pixWid+rad)),ll*2)
            line(gui,color(q[1]),True,((x+rad,y-ll),(x+pixWid-rad,y-ll)),ll*2)
            line(gui,color(q[2]),True,((x+ll,y+rad),(x+ll,y+pixWid-rad)),ll*2)
            line(gui,color(q[3]),True,((x-rad,y+ll),(x-pixWid+rad,y+ll)),ll*2)
            
    pygame.display.update()


# highlight the best route
moveDelay = 0.25
row, col, movNum = 0, 0, 0
示例#45
0
    finalize_button.update(elapsed, mouse.get_pos(), any(mouse.get_pressed()))
    unfinalize_button.update(elapsed, mouse.get_pos(),
                             any(mouse.get_pressed()))
    reset_land_button.update(elapsed, mouse.get_pos(),
                             any(mouse.get_pressed()))

    screen.fill((0, 0, 0))

    viewport.draw(screen)

    create_landmass_button.draw(screen)
    finalize_button.draw(screen)
    unfinalize_button.draw(screen)
    reset_land_button.draw(screen)

    if is_creating_landmass:
        draw.circle(screen, (255, 0, 0), mouse.get_pos(), 5)
    elif is_setting_landmass_distance:
        converted_origin = viewport.deconvert_mouse_pos(land_mass_origin)
        mouse_pos = mouse.get_pos()
        distance = ((mouse_pos[0] - converted_origin[0])**2 +
                    (mouse_pos[1] - converted_origin[1])**2)**0.5
        draw.circle(screen, (255, 0, 0), converted_origin, 5)
        draw.circle(screen, (255, 0, 0), converted_origin,
                    max(5, int(distance)), 2)

    display.flip()

display.quit()
font.quit()
示例#46
0
 def draw(self, shape_name=None):
     super().draw(shape_name=shape_name)
     if self.selected:
         radius = round((BLOCK_SPACING() / 2) * self.scale * 1.5)
         circle(gui.SCREEN, Color('red'), self.rect.center, radius, 1)
示例#47
0
 def render(self):
     # .. draw a dot
     draw.circle(screen, WHITE, self.position, self.size, 0)
示例#48
0
COLORS = [RED, BLUE, YELLOW, GREEN, MAGENTA, CYAN]


class Ball():
    def __init__(self, color, x, y, r, speed_x, speed_y, lifes):

        self.x = x


self.y = y
self.r = r
self.color = color
self.lifes = lifes
self.speed_x = speed_x
self.speed_y = speed_y
d.circle(screen, self.color, (self.x, self.y), self.r)


def move(self):
    d.circle(screen, BLACK, (self.x, self.y), self.r)


self.x += self.speed_x
self.y += self.speed_y
d.circle(screen, self.color, (self.x, self.y), self.r)


def change_color(self, color):
    self.color = color

示例#49
0
def move(self):
    d.circle(screen, BLACK, (self.x, self.y), self.r)
示例#50
0
def remove_ball(self):
    d.circle(screen, BLACK, (self.x, self.y), self.r)
示例#51
0
import pygame
import pygame.draw as d

pygame.init()

FPS = 30
screen = pygame.display.set_mode((400, 400))

d.rect(screen, (255, 255, 255), (0, 0, 400, 400))
d.circle(screen, (255, 255, 0), (200, 175), 100)
d.circle(screen, (0, 0, 0), (200, 175), 101, 1)
d.line(screen, (0, 0, 0), (95, 80), (180, 140), 10)
d.line(screen, (0, 0, 0), (220, 140), (300, 105), 10)
d.circle(screen, (255, 0, 0), (150, 150), 20)
d.circle(screen, (0, 0, 0), (150, 150), 21, 1)
d.circle(screen, (255, 0, 0), (250, 150), 15)
d.circle(screen, (0, 0, 0), (250, 150), 16, 1)
d.circle(screen, (0, 0, 0), (150, 150), 10)
d.circle(screen, (0, 0, 0), (250, 150), 8)
d.rect(screen, (0, 0, 0), (145, 220, 110, 25))

pygame.display.update()
clock = pygame.time.Clock()
finished = False

while not finished:
    clock.tick(FPS)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            finished = True
示例#52
0
	def draw(self):
		(w, h) = self.screen.get_size()

		circle(self.screen, (255, 0, 0), (w // 2, h // 2), self.radius)
示例#53
0
 def draw(self) -> None:
     """
     Draw the ball
     """
     draw.circle(self._window, self._color, (self._x_pos, self._y_pos),
                 BALL_RADIUS)
示例#54
0
文件: dialog.py 项目: 602p/spacegame
 def _draw_close_off(self, image, size):
     image.fill(self._settings["col_border"])
     draw.circle(image, (140, 6, 15), (size[0] / 2, size[1] / 2), 8)
     draw.line(image, (0, 0, 1), (5, 5), (11, 11), 3)
     draw.line(image, (0, 0, 1), (5, 11), (11, 5), 3)
 def render(self):
     draw.circle(self.screen, (0, 0, 0), (int(self.xPos), int(self.yPos)),
                 self.rad, 0)
示例#56
0
while not close_game:

    # Event handling
    for e in pygame.event.get():

        # Quit event handling
        if e.type == pygame.QUIT:
            pygame.quit()
            break

        # Key press event handling
        if e.type == pygame.KEYDOWN:
            if e.key == pygame.K_ESCAPE:
                pygame.quit()
                break

        # Mouse moved event handling
        if e.type == pygame.MOUSEMOTION:
            pos = e.pos

    # Clearing screen
    screen.fill((0, 0, 0))

    # Rendering
    # draw.rect(screen, (255, 0 ,0), [pos[0]-5, pos[1]-5, 10, 10])
    draw.circle(screen, (255, 0, 0), pos, 10)

    # Update screen
    display.update()
示例#57
0
def draw2(a, screen):
    """Draws an object in the middle of the screen
    """
    circle(screen, a.colour, (width / 2, height / 2), a.radius, 0)
示例#58
-1
 def draw(self, screen):
     draw.circle(
         screen,
         (0, 0, 0),
         (int(self.x), int(self.y)),
         self.rad
     )
示例#59
-1
    def drawUpdatedMinimap(self, world, player, rays, coords):
        scale = self.minimap_scale
        player_coords = ((player.coords+1) * scale).rounded().toInt().toTuple()
        player_direction = player.direction * scale
        player_direction = (player_direction + player_coords).rounded().toInt().toTuple()
        minimap = self.minimap_surface.copy()
        draw.circle(
            minimap,
            player.map_color,
            player_coords,
            round(player.size*scale)
        )
        for ray in rays:
            draw.line(
                minimap,
                (0,255,0),
                player_coords,
                ((ray['coords'][0]+1)*scale, (ray['coords'][1]+1)*scale)
        )
        draw.line(
            minimap,
            player.map_color,
            player_coords,
            player_direction
        )

        self.screen.blit(minimap, coords)
示例#60
-1
文件: gc2d.py 项目: whiord/untangle3d
    def _draw(self):
        intersected = set()
        objs = self.objects
        for e1 in self.edges:
            for e2 in self.edges:
                if e1 != e2 and e1 not in intersected:
                    s1 = gd2.Segment(objs[e1[0]], objs[e1[1]])
                    s2 = gd2.Segment(objs[e2[0]], objs[e2[1]])
                    if gd2.intersect_seg(s1, s2, self.config.accuracy):
                        intersected.add(e1)
                        intersected.add(e2)

        for edge in self.edges:
            p1 = self.objects[edge[0]]
            p2 = self.objects[edge[1]]

            color = self.config.line.color
            if edge in intersected:
                color = self.config.line.bad_color
            if self.grub_id is not None:
                if edge[0] == self.grub_id or edge[1] == self.grub_id:
                    color = self.config.line.active_color

            pd.line(self.display, color, (p1.x, p1.y), (p2.x, p2.y), self.config.line.width)
            #pd.aaline(self.display, color, (p1.x, p1.y), (p2.x, p2.y), True)

        for id, point in self.objects.items():
            color = self.config.circle.color
            if id == self.grub_id:
                color = self.config.circle.active_color
            pd.circle(self.display, color, (int(round(point.x)), int(round(point.y))), int(round(point.radius)))
            #pgfx.aacircle(self.display, int(round(point.x)), int(round(point.y)), int(round(point.radius)), color)

        self._render_info("tangled: {}/{}".format(len(intersected), len(self.edges)))