Example #1
0
def draw_lines(window, x, y, radius, lines):
    """This function uses gfxdraw to draw the initial circle in white and
    the previously computed lines in red.

    """
    gfxdraw.circle(window, x, y, radius, Color(255, 255, 255,255))
    for p1, p2, color in lines:
        gfxdraw.line(window, p1[0], p1[1], p2[0], p2[1], color)
Example #2
0
def draw_lines(window, x, y, radius, lines):
    """This function uses gfxdraw to draw the initial circle in white and
    the previously computed lines in red.

    """
    gfxdraw.circle(window, x, y, radius, Color(255, 255, 255,255))
    for p1, p2 in lines:
        gfxdraw.line(window, p1[0], p1[1], p2[0], p2[1], Color(255, 0, 0,255))
Example #3
0
 def drawButtons(self):
     buttonR = int(self.buttonWidth / 2)
     gfxdraw.filled_circle(self.surface,
                           self.getX() + self.width - buttonR,
                           self.getY() + buttonR, buttonR, self.color)
     gfxdraw.circle(self.surface,
                    self.getX() + self.width - buttonR - self.buttonWidth,
                    self.getY() + buttonR, buttonR, self.color)
Example #4
0
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)
Example #5
0
 def drawRings(self, window, numRings, center, color):
     radius = 2
     numRings = numRings*2
     gfxdraw.pixel(window, center[0], center[1], color)
     while numRings > 0:
         numRings -= 1
         radius += 1
         if numRings%2:
             gfxdraw.circle(window, center[0],center[1], radius, color)
Example #6
0
def draw_circle(pos, r, color, filled=False, global_coords=True):
    if global_coords:
        pos =  world_to_win_pt(pos, c.player.center)
        r = world_to_win_length(r)
    
    if filled:
        gfxdraw.filled_circle(screen, pos[0], pos[1], r, color)
    else:
        gfxdraw.circle(screen, pos[0], pos[1], r, color)
    gfxdraw.aacircle(screen, pos[0], pos[1], r, color)
Example #7
0
 def __init__(self, geometry=(640, 480), Delta_t=30, r=15):
     self.geometry = geometry
     self.Delta_t = Delta_t
     self.radio = r
     self.coordenada = (0, 0)
     self.puntos = []
     pygame.init()
     self.Pantalla = display.set_mode(self.geometry)
     self.Pantalla.fill(black)
     pygame.display.set_caption('CNC', 'cnc')
     gfxdraw.circle(self.Pantalla, self.coordenada[0], self.coordenada[1],
                    self.radio, red)
     pygame.display.flip()
Example #8
0
 def render(self):
     screen = display.get_surface()
     # Drawing circles
     if self.hover or self.hover2:
         color = (96, 128, 255, 128)
         if self.dragging or self.dragging2:
             color = (255, 128, 96, 128)
         if self.hover:
             gfxdraw.circle(screen, self.x + self.app.context.offset_x,
                            self.y + self.app.context.offset_y,
                            self.vertex_range, color)
         if self.hover2:
             gfxdraw.circle(screen, self.x2 + self.app.context.offset_x,
                            self.y2 + self.app.context.offset_y,
                            self.vertex_range, color)
Example #9
0
 def drawScrollIndicator(self, x, y, maxWidth, height, groupCount):
     if (groupCount == 0):
         groupCount = 1
     position = (height) * ((0.5 + self.scrollPosition) / groupCount)
     if (self.fillScrollIndicator):
         gfxdraw.filled_circle(
             self.surface,
             x + maxWidth + int(self.scrollIndicatorWidth / 2) + 1,
             y + int(position),
             int(self.scrollIndicatorWidth / 2) - 2, self.color)
     else:
         gfxdraw.circle(
             self.surface,
             x + maxWidth + int(self.scrollIndicatorWidth / 2) + 1,
             y + int(position),
             int(self.scrollIndicatorWidth / 2) - 2, self.color)
def airbrush(mpos, lregistry):
    global toolDelay
    # Rate limiting
    if ptime.time() - toolDelay > 0.00100003:
        toolDelay = ptime.time()
        numPoints = randint(0, 10)
        pointList = []
        while len(pointList) < numPoints:
            x = randint(mpos[0] - lregistry["toolThickness"] // 2,
                        mpos[0] + lregistry["toolThickness"] // 2)
            y = randint(mpos[1] - lregistry["toolThickness"] // 2,
                        mpos[1] + lregistry["toolThickness"] // 2)
            if ((x - mpos[0])**2 +
                (y - mpos[1])**2)**0.5 < lregistry["toolThickness"] / 2:
                pointList.append((x, y))
        for point in pointList:
            gfxdraw.circle(canvasSurface, point[0], point[1], 1,
                           lregistry["toolColour"])
Example #11
0
    def mueve(self, posicion=(0, 0), marcar=False):
        if posicion[0] < 0 | posicion[1] < 0 | posicion[
                0] > self.geometry[0] - 1 | posicion[1] > self.geometry[1] - 1:
            return
        else:
            if posicion[0] < self.coordenada[0]:
                Delta_X = -1
            else:
                Delta_X = 1
            if posicion[1] < self.coordenada[1]:
                Delta_Y = -1
            else:
                Delta_Y = 1
            for x in range(self.coordenada[0], posicion[0] + Delta_X, Delta_X):
                gfxdraw.circle(self.Pantalla, self.coordenada[0],
                               self.coordenada[1], self.radio, black)
                self.dibujar()
                pygame.time.delay(self.Delta_t)
                print(x, self.coordenada[1])
                self.coordenada = (x, self.coordenada[1])
                gfxdraw.circle(self.Pantalla, self.coordenada[0],
                               self.coordenada[1], self.radio, red)
                self.dibujar()
                pygame.time.delay(self.Delta_t)

            for y in range(self.coordenada[1], posicion[1] + Delta_Y, Delta_Y):
                gfxdraw.circle(self.Pantalla, self.coordenada[0],
                               self.coordenada[1], self.radio, black)
                self.dibujar()
                pygame.time.delay(self.Delta_t)
                print(self.coordenada[0], y)
                self.coordenada = (self.coordenada[0], y)
                gfxdraw.circle(self.Pantalla, self.coordenada[0],
                               self.coordenada[1], self.radio, red)
                self.dibujar()
                pygame.time.delay(self.Delta_t)

            if marcar:
                self.marcar()
            gfxdraw.circle(self.Pantalla, self.coordenada[0],
                           self.coordenada[1], self.radio, red)
            pygame.display.flip()
            return
def eratosthene(window, max_value):
    """Implementing the sieve of Eratosthenes:
    https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes. Whenever a
    multiple of a potential prime is crossed, draw a circle whose
    center depends on the multiple and whose radius depends on the
    prime number.

    """
    int_list = range(2, max_value + 1)
    primes = set(int_list)
    y = window_height / 2

    for n in int_list:
        if n in primes:
            i = 2 * n
            gfxdraw.circle(window, multiplier * n, y, (multiplier * n) / divisor, 
                           Color(129, 129, 129, 255))
            while i <= max_value:
                gfxdraw.circle(window, multiplier * i, y, (multiplier * n) / divisor, 
                               Color(129, 129, 129, 255))
                if i in primes:
                    primes.remove(i)
                i += n
Example #13
0
    def circle(self, x, y, r, color):
        """円を描画します.

        Parameters
        ----------
        x : int
            円の中心のx座標.
        y : int
            円の中心のy座標.
        r : int
            描画される円の半径.
        color : tuple of int
            描画に使用される色を指定します.

        """

        return gfx.circle(self.pg.screen, x, y, r, color)
Example #14
0
def draw(screen):
    color = (255, 255, 255)

    mx, my = mousepos
    gfxdraw.circle(screen, mx, my, 10, color)

    if rocket.active:
        x, y = rocket.position
        gfxdraw.circle(screen, int(x), int(y), 5, color)

    if explosion.active:
        x, y = explosion.position
        r = explosion.radius * explosion.t
        gfxdraw.circle(screen, int(x), int(y), int(r), color)
Example #15
0
def pygame_init():
    pygame.init()

    size = 1280, 720
    black = 0, 0, 0

    screen = pygame.display.set_mode(size)
    prior_draws = []

    iterations = 0

    while True:
        if iterations > 10_000:
            prior_draws.clear()
        (draw_entity, data) = yield

        #  rendering
        if draw_entity == DrawEntity.POINT:
            x, y = data.x, data.y
            sx = (x + 100) * 5
            sy = (y + 100) * 5
            draw_fn = lambda xx, yy: lambda: gfxdraw.circle(
                screen, xx, yy, 2, (255, 255, 255))
            prior_draws.append(draw_fn(sx, sy))

        # input
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

        # idle time
        screen.fill(black)
        for fn in prior_draws:
            fn()
        pygame.display.flip()
        iterations += 1
Example #16
0
	def show(self):
		gfx.circle(self.screen,self.x,self.y,20,blue)
Example #17
0
def circle(x, y, r, color=(255, 255, 255)):
    gfx.circle(screen, int(x), int(y), int(r), color)
Example #18
0
 def draw(self, window):
     if (self.radius < self.energy):
         gfxdraw.circle(window, self.x, self.y, self.radius, self.color)
         self.radius += self.speed
     else:
         self.onCompleted(self)
Example #19
0
def draw(screen):
    color = (255, 255, 255)
    for robot in robots:
        x, y = robot.position
        gfxdraw.circle(screen, int(x), int(y), 5, color)
Example #20
0
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