def __init__(self, start_loc, size, speed, rot_speed, dir, depth, screen_size): self.loc = start_loc self.size = size self.radius = math.sqrt(3) * self.size / 3 # the radius of the circle the snowflake is inscribed in self._velocity = (0.0, 0.0) self._rot_speed = rot_speed self._dir = dir self.theta = 0 self.depth = depth self._velocity = [math.sin(self.theta) * self._dir, speed] self.wind = [0, 0] self._damping = 0.0001 # damping factor so wind dies down self.debug = False self._stroke_color = (0, 0, 0, 200) self._screen_size = screen_size blue = random.randrange(20) # how blue the snowflakes should be self._fill_color = (255 - blue, 255 - blue, 255, 240) points = self.generate_snowflake() self.surface = pygame.Surface((self.radius * 2, self.radius * 2), pygame.SRCALPHA, 32).convert_alpha() gfxdraw.aapolygon(self.surface, points, self._stroke_color) # border gfxdraw.filled_polygon(self.surface, points, self._fill_color) # fill gfxdraw.polygon(self.surface, points, self._stroke_color) # fill
def draw_cell(cell): font_size = 16 virus_sizes = {100:1, 106:2, 113:3, 119:4, 125:5, 131:6, 136:7} cx,cy = world_to_win_pt(cell.pos,c.player.center) try: mov_ang = cell.movement_angle p2 = cell.pos + Vec( math.cos(mov_ang + mechanics.eject_delta*math.pi/180), math.sin(mov_ang + mechanics.eject_delta*math.pi/180) ) * (cell.size+700) p3 = cell.pos + Vec( math.cos(mov_ang - mechanics.eject_delta*math.pi/180), math.sin(mov_ang - mechanics.eject_delta*math.pi/180) ) * (cell.size+700) cx2,cy2 = world_to_win_pt(p2,c.player.center) cx3,cy3 = world_to_win_pt(p3,c.player.center) except (AttributeError, TypeError): cx2,cy2=cx,cy cx3,cy3=cx,cy radius = world_to_win_length(cell.size) if cell.is_virus: color = (0,255,0) color2 = (100,255,0) polygon = generate_virus(int(cell.size*0.3), 10*zoom, radius, (cx, cy)) polygon2 = generate_virus(int(cell.size*0.3), 10*zoom, radius-10, (cx, cy)) gfxdraw.filled_polygon(screen, polygon, color2) gfxdraw.polygon(screen, polygon, (0,0,0)) gfxdraw.aapolygon(screen, polygon, (0,0,0)) gfxdraw.filled_polygon(screen, polygon2, color) gfxdraw.aapolygon(screen, polygon2, color) draw_text((cx, cy), "%s / 7" % virus_sizes.get(cell.size, "?"), (64,0,0), font_size*2, False, True) draw_text((cx, cy + radius + 10), str(cell.cid), (0,0,0), font_size, False, True) else: color=(int(cell.color[0]*255), int(cell.color[1]*255), int(cell.color[2]*255)) if not (cell.is_ejected_mass or cell.is_food): gfxdraw.aapolygon(screen, [(cx,cy),(cx2,cy2),(cx3,cy3),(cx,cy)] ,(255,127,127)) gfxdraw.filled_circle(screen, cx, cy, radius, color) gfxdraw.aacircle(screen, cx, cy, radius, (0,0,0)) gfxdraw.aacircle(screen, cx, cy, int(radius/2), (255,255,255)) gfxdraw.circle(screen, cx, cy, int(radius/2), (255,255,255)) draw_text((cx, cy + radius + 10), cell.name, (0, 0, 0), font_size, False, True) draw_text((cx, cy + radius + 10 + font_size), str(cell.cid), (0,0,0), font_size, False, True) # surface = draw_text(cell.name, (0, 0, 0), font_size) # screen.blit(surface, (cx - (surface.get_width()/2), cy + radius + 5)) draw_text((cx, cy), str(int(cell.mass))+"/"+str(int(cell.size)), (255, 255, 255), font_size, False, True) # surface = draw_text(str(int(cell.mass)), (255, 255, 255), font_size) # screen.blit(surface, (cx - (surface.get_width()/2), cy - (surface.get_height()/2))) else: gfxdraw.aacircle(screen, cx, cy, radius, color) gfxdraw.filled_circle(screen, cx, cy, radius, color)
def draw_polygon(polygon, color, filled=False, global_coords=True): if len(polygon) > 2: if global_coords: polygon = list(map(lambda x: world_to_win_pt(x, c.player.center), polygon)) if filled: gfxdraw.filled_polygon(screen, polygon, color) else: gfxdraw.polygon(screen, polygon, color) gfxdraw.aapolygon(screen, polygon, color)
def renderGame(surface): if self.physic_world.debug: color = self.physic_world.DEBUG_COLOR for b in self.physic_world.world: x, y = b.position for fixture in b: vertices = [(vx + x, vy + y) for vx, vy in fixture.shape.vertices] polygon(surface, vertices, color) displayFlip() return self.sprite_factory.draw(surface, Window().bgd)
def drawPolygon(origin, numpoints, points, color, filled): global gfxSurface points1 = [] noDraw = False for i in points: points1.append(getPoint(transformCoords(origin, i))) if getPoint(transformCoords(origin, i))[2] == 0: noDraw = True if filled: if not noDraw: gfxdraw.filled_polygon(gfxSurface, points1, color) if not filled: if not noDraw: gfxdraw.polygon(gfxSurface, points1, color)
def polygon(self, points, color): """複数の頂点からなる多角形を描画します. Parameters ---------- points : array-like 頂点の座標を格納した2次元配列. 配列の2次元目の要素数は2で, 少なくとも3点以上の座標を設定する必要があります. color : tuple of int 描画に使用される色を指定します. """ return gfx.polygon(self.pg.screen, points, color)
def surface_with_node(surface, node, angle, offset_in, current_resize_offset, widthscalar, heightscalar): transformedlists = transformtopointlists(node.plantshapelist, node.shiftchance, angle, widthscalar, heightscalar) mainloffset = None mainltranslated = None def currentoffset(): return (offset_in[0] + current_resize_offset[0], offset_in[1] + current_resize_offset[1]) def surface_offset(pointlist_bounds): return Rect(currentoffset()[0]-node.anchor[0]+pointlist_bounds[0], currentoffset()[1]-node.anchor[1]+pointlist_bounds[1], pointlist_bounds.width, pointlist_bounds.height) # go through all the plantshapes and their corresponding transformed lists for i in range(len(transformedlists)): currentlist = transformedlists[i] bounds = getlistbounds(currentlist) # make the surface shape_surface = Surface((bounds.width, bounds.height), SRCALPHA) # translate points into this surface shiftedlist = offsetpointlist(currentlist, (-bounds[0], -bounds[1])) # draw the plant shape onto the new surface plantshape = node.plantshapelist[i] if plantshape.fillcolor != None: gfxdraw.filled_polygon(shape_surface, shiftedlist, plantshape.fillcolor) if plantshape.outlinecolor != None: gfxdraw.polygon(shape_surface, shiftedlist, plantshape.outlinecolor) # apply the texture if any for ptexture in plantshape.textures: addtexture(shape_surface, ptexture) # now check if resizing is needed newsurfacerect = surface.get_rect().union(surface_offset(bounds)) if not newsurfacerect == surface.get_rect(): new_surface = Surface((newsurfacerect.width, newsurfacerect.height), SRCALPHA) new_surface.blit(surface, (-newsurfacerect.x, -newsurfacerect.y)) current_resize_offset = (current_resize_offset[0]-newsurfacerect.x, current_resize_offset[1]-newsurfacerect.y) surface = new_surface devprint("Resized surface to " + str(new_surface.get_width()) + " by " + str(new_surface.get_height())) surface.blit(shape_surface, surface_offset(bounds)) # also save the first list for other nodes to go off of if i == 0: # save the offset of l without the resizing mainloffset = surface_offset(bounds) # also remove the current resize offset mainloffset = (mainloffset[0] - current_resize_offset[0], mainloffset[1]-current_resize_offset[1]) mainltranslated = shiftedlist return surface, mainltranslated, mainloffset, current_resize_offset
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] rectarc = 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, rectarc, 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_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 pantalla_refresh(sf): global pts,mpts global xbw,xdev global fq,fqc,bw global modelabel,bwlabel,fqlabel1,fqlabel2 global ftqc, numx global maxfill_enable, maxpts_enable, refreshfq global azoom, base global fft_sf,top_sf global sq,xsq,asq,smval,smvaladj,possq,sqstate global frame, count global menusf, stereosf a = FFTANCHO/2 # media pantalla pleft = fqlabel1.get_size()[0]/2 + fqlabel2.get_size()[0]/2 fft_sf.fill(BGCOLOR) # Borra BW Más rapido que reescribir. # PINTA ESCALA for x in range(12): # Escala FFT y = int(FFTALTO - (x*(FFTALTO/12))*azoom) + base if y > 0 : pgd.hline(fft_sf,0,FFTANCHO,y,ESCCOLOR) lb = ftdev1.render(str((12-x)*-10), 0, ESCCOLOR,BGCOLOR) # pinta db text fft_sf.blit(lb, (0,y-10)) # Pinta db label # Pinta BW if nobaile: txdev = FFTANCHO/2; else: txdev = xdev txbw = 2*xbw tcodo = txdev - txbw/2 if not nobaile or (nobaile and (frame % 10) > 4 ): # parapedea dev si introscan if tmode != "FM W" and tmode != "FM ST": # WFM no tiene ancho de banda if tmode == "USB": txbw /= 2 tcodo = txdev elif tmode == "LSB": txbw /= 2 tcodo = txdev - txbw fft_sf.fill(BWCOLOR2,(tcodo,BWY,txbw,FFTALTO-BWY),0) # Pinta BW pgd.rectangle(fft_sf,(tcodo,BWY,txbw,FFTALTO-BWY),BWCOLOR) pgd.vline(fft_sf,int(txdev),0,FFTALTO,DEVCOLOR) # Pinta linea dev # PINTA MAX if maxpts_enable: # Pintta puntos de max mpts += [(FFTANCHO,FFTALTO),(0,FFTALTO)] pgd.polygon(fft_sf,mpts,MAXCOLOR) # PINTA FILL if fftfill_enable: # Pintta FFT relleno (Más rápido que el fill) for x in pts: pgd.vline(fft_sf,x[0],x[1],FFTALTO,FILLCOLOR) # PINTA FFT pgd.polygon(fft_sf,pts,FGCOLOR) # pinta FFT # PINTA DETECT if detect_enable : # Pinta detector picos for x in dtc : pgd.circle(fft_sf,x[0],x[1],10,DETECTCOLOR) # PINTA DEV text if not nobaile or (nobaile and (frame % 10) > 4): if tmode != "FM W" and tmode != "FM ST": fft_sf.blit(bwlabel, (txdev-bwlabel.get_size()[0]/2,BWY+2)) # Pinta bw label fft_sf.blit(fqlabel1, (txdev-pleft,BWY-22)) # Pinta dev label fft_sf.blit(fqlabel2, (txdev-pleft+fqlabel1.get_size()[0]+4,BWY-20)) fft_sf.blit(modelabel,(txdev-modelabel.get_size()[0]/2,BWY-40)) # Pinta mode label # pinta Sqelch tc = SQCOLOR if not sqstate: tc = (0,200,0) # Si está levantado pinta verde pgd.hline(fft_sf,0,FFTANCHO,xsq+base, tc) fsq = ftdev2.render(' SQ '+str(sq)+ ' ', 0, DEVCOLORHZ,(100,25,25)) fft_sf.blit(fsq, (FFTANCHO-fsq.get_size()[0],xsq-10+base)) # Pinta bw label possq = (FFTANCHO-fsq.get_size()[0]+25,xsq-12+base+12) # Guardo posicion para el botón #pgd.circle(fft_sf,possq[0],possq[1],50,(200,200,200)) #asq = tsq # pinta smeter pgd.box(top_sf,(smx+13,25,sml-28,9),(0,0,0)) pgd.box(top_sf,(smx+13,27,smval*smvaladj,6),(255,50,50)) # PINTA CIFRAS DE FREQ SI HAN CAMBIADO if refreshfq: sp = 4 size = 24 numx = [] # Repinta el indicador de frecuencia txt = format(fqc,'010d') txt = txt[:-9]+'.'+txt[-9:-6]+'.'+txt[-6:-3]+','+txt[-3:] lon = len(txt) anc = 0 for x in range(lon): if txt[x] in ['.',','] : col = BGCOLOR anc = size / 2 else : col = BGFQCCOLOR anc = size px = (TOPANCHO/2) - (lon+sp)*size/2 + (x*(size+sp)) # Calcula posición fqclabel = ftqc.render(txt[x], 1, FQCCOLOR, col) # pinta fqc text top_sf.blit(fqclabel,(px,0)) # blit if txt[x] not in ['.',','] : numx += [px] # Almacena la coordenada del numero # PARPADEA BOTON ROJO IF REC if rec: if frame == FPS/2: pgd.filled_circle(top_sf, smx+sml+TOPALTO/2, TOPALTO/2, TOPALTO/4, BGCOLOR) #Borra botón rojo izquierda smeter if frame == 1: pgd.filled_circle(top_sf, smx+sml+TOPALTO/2, TOPALTO/2, TOPALTO/4, tc) #Pinta botón del color del smeter # Pinta STEREO si STEREO if REAL and tmode == "FM ST": if (sdr.probe_st.level() > 0.5 ): top_sf.blit(stereosf,(250,8)) else: pgd.box(top_sf,(250,0,40,TOPALTO),BGCOLOR) # Pinta BIRDIES for i in birds: fft_sf.blit(fbd, (i+((birdsize-16)/2),FFTALTO-16)) # PINTA MENU IF ANY if mn : mn.refresca() # Flipea/Vuelca la pantalla pg.display.flip() refreshfq = False frame = (frame % FPS) +1 count += 1
def draw_polygon_normal(screen, p, color): gfx.polygon(screen, p, color)