Ejemplo n.º 1
0
 def display(self, screen):
     if self.typen == 'c':
         gfx.aaellipse(screen, self.x, self.y, self.size, self.sizeb, self.colour)
         gfx.aacircle(screen, self.x, self.y, 2, (0,0,0))
     elif self.typen == 'r':
         gfx.rectangle(screen, pg.Rect(self.x-self.size/2, self.y-self.sizeb/2, self.size, self.sizeb), self.colour)
         gfx.aacircle(screen, self.x, self.y, 2, (0,0,0))
Ejemplo n.º 2
0
    def draw(self):
        self.bg = DISPLAY.subsurface(self).copy()
        clipxy = DISPLAY.get_clip()
        DISPLAY.set_clip(self)
        gfxdraw.box(DISPLAY,self,BGCOLOR)
        x,y = self.itemsrect.topleft
        if self.index != None and not (1 << self.index)&self._exc:
            gfxdraw.box(DISPLAY,self.hlRect,BGHIGHTLIGHT)
            gfxdraw.rectangle(DISPLAY,self.hlRect,BORDER_HL)
        x += self.lineheight/3
        for idx,item in enumerate(self.itemslist):
            isExc = (1 << idx)&self._exc
            isStr = isinstance(item,str)
            text = FONT.render(item if isStr else item.label,1,FGLOWLIGHT if isExc else FGCOLOR)
            if not isStr:
                self.arrowRect.topright = self.itemsrect.right-self.lineheight/3,y
                DISPLAY.blit(FONT.render(Arrow,1,FGLOWLIGHT if isExc else FGCOLOR),self.arrowRect)
            r = DISPLAY.blit(text,(x,y))
            y += self.lineheight

        gfxdraw.vline(DISPLAY,self.left,self.top,self.bottom-1,BORDER_LEFT)
        gfxdraw.hline(DISPLAY,self.left,self.right-1,self.top,BORDER_LEFT)
        gfxdraw.vline(DISPLAY,self.right-1,self.top+1,self.bottom-1,BORDER_RIGHT)
        gfxdraw.hline(DISPLAY,self.left+1,self.right-1,self.bottom-1,BORDER_RIGHT)
        DISPLAY.set_clip(clipxy)
        return self
Ejemplo n.º 3
0
    def paint(self, s):
        # Background
        draw.rect(s, (255, 100, 100) if self.mouse_on and self.color == (255, 0, 0) else self.color, self.get_hitbox())

        # Overlay if focused
        if self.focused:
            gfx.rectangle(s, self.get_hitbox(), (0, 255, 0))
Ejemplo n.º 4
0
 def draw_r(self):
     if (self.beveled):
         drawRoundRect(self.surface, self.getX(), self.getY(), self.width,
                       self.height, self.bevelSize, self.color)
     else:
         gfxdraw.rectangle(
             self.surface,
             (self.getX(), self.getY(), self.getX() + self.getWidth(),
              self.getY() + self.getHeight()), self.color)
     if not self.titleRendered:
         if (self.font.size(self.title)[0] > self.maxTitleWidth):
             title = self.title
             offset = len(title)
             while (self.font.size(title + "...")[0] > self.maxTitleWidth):
                 if (offset == 1):
                     title = ""
                     break
                 offset -= 1
                 title = title[:offset]
             if (title):
                 self.titleRendered = self.font.render(
                     title + "...", self.antialias, self.color)
             else:
                 self.titleRendered = self.font.render(
                     "", self.antialias, self.color)
         else:
             self.titleRendered = self.font.render(self.title,
                                                   self.antialias,
                                                   self.color)
     self.surface.blit(
         self.titleRendered,
         (self.getX() + self.bevelSize, self.getY() + self.bevelSize))
     self.drawButtons()
Ejemplo n.º 5
0
def drawInventory():
    global invSurface
    invSurface.fill((255, 255, 255))
    for a in range(6):
        for b in range(5):
            gfxdraw.rectangle(invSurface, (22 * a, 22 * b, 24, 24), (0, 0, 0))
            drawInvTool(22 * a + 1, 22 * b + 1, a, b)
Ejemplo n.º 6
0
 def render(self):
     super(WindowLayer, self).render()
     screen = display.get_surface()
     gfxdraw.box(screen, (self.x + 1, self.y + 1, self.x2 - 1, self.y2 - 1),
                 self.bgcolor)
     gfxdraw.rectangle(screen, (self.x, self.y, self.x2, self.y2),
                       self.fgcolor)
Ejemplo n.º 7
0
 def drag_sprite_draw(self, start_x, start_y, curr_x, curr_y):
     if (dragSpriteStyle == "rectangle"):
         gfxdraw.rectangle(self.surface, (start_x, start_y, curr_x, curr_y),
                           self.color)
     else:
         gfxdraw.line(self.surface, start_x, start_y, curr_x, curr_y,
                      self.color)
Ejemplo n.º 8
0
 def drag_sprite_erase(self, start_x, start_y, curr_x, curr_y):
     if (dragSpriteStyle == "rectangle"):
         gfxdraw.rectangle(self.surface, (start_x, start_y, curr_x, curr_y),
                           self.bgcolor)
     else:
         gfxdraw.line(self.surface, start_x, start_y, curr_x, curr_y,
                      self.bgcolor)
     self.updateWindowCascade(False)
Ejemplo n.º 9
0
	def drawselectionbox(self,screen):
		if self.mainplayer.oldmousepos:
			m=pygame.mouse.get_pos()
			x=self.mainplayer.oldmousepos[0]
			y=self.mainplayer.oldmousepos[1]
			w=m[0]-x
			h=m[1]-y
			gfxdraw.rectangle(screen,pygame.Rect(x,y,w,h),selectedcolor)
Ejemplo n.º 10
0
def drawToolBar(slot):
    global toolSurface
    toolSurface.fill((255, 255, 255))
    for a in range(10):
        col = (0, 0, 0)
        gfxdraw.rectangle(toolSurface, (22 * a, 0, 24, 24), col)
        drawTool(22 * a + 1, 1, files.getInventoryItem(a))
    gfxdraw.rectangle(toolSurface, (22 * slot, 0, 24, 24), (255, 0, 0))
Ejemplo n.º 11
0
 def __staticImages__(self):
     gfx.rectangle(self.imageBase, self.imgRect, TextBox.COLOR)
     self.imageMouseOver.fill(TextBox.COLORO)
     gfx.rectangle(self.imageMouseOver, self.imgRect, TextBox.COLOR)
     if self.text:
         staticTextImage, r = TextBox.FONT.render(self.text, TextBox.COLOR)
         self.imageBase.blit(staticTextImage, self.textTopLeft)
         self.imageMouseOver.blit(staticTextImage, self.textTopLeft)
Ejemplo n.º 12
0
 def __init__(self, w, h, x, y, fn):
     super().__init__(w, h)
     gfx.rectangle(self.bg, self.bg.get_rect(), GameOverMsg.BOXCOLOR)
     self.add_status_box('msg', "You win!!!", w//2, h//3)
     but_width = (w * 2) // 3
     self.add_button("MAIN MENU", pg.Rect((w - but_width)//2, h // 2, but_width, h//3), fn)
     self.w, self.h = w, h
     self.x, self.y = x, y
Ejemplo n.º 13
0
 def __init__(self, w, h, menuFn):
     super().__init__(w, h)
     gfx.rectangle(self.bg, self.bg.get_rect(), GameOverMsg.BOXCOLOR)
     self.addStatusBox('msg', "", w // 2, h // 3)
     butW = (w * 2) // 3
     self.addButton("MAIN MENU",
                    pg.Rect((w - butW) // 2, h // 2, butW, h // 3), menuFn)
     self.w, self.h = w, h
     self.x, self.y = 0, 0
Ejemplo n.º 14
0
 def __staticImages__(self):
     self.imageBase = pg.Surface((self.rect.width, self.rect.height))
     gfx.rectangle(self.imageBase, self.imgRect, TextBox.COLOR)
     self.imageMouseOver.fill(TextBox.COLOR_MOUSE_OVER)
     gfx.rectangle(self.imageMouseOver, self.imgRect, TextBox.COLOR)
     if self.text:
         static_text_image, r = TextBox.FONT.render(self.text,
                                                    TextBox.COLOR)
         self.imageBase.blit(static_text_image, self.textTopLeft)
         self.imageMouseOver.blit(static_text_image, self.textTopLeft)
Ejemplo n.º 15
0
 def __typingImages__(self):
     self.imageMousePress.fill((0, 0, 0))
     gfx.rectangle(self.imageMousePress, self.imgRect, TextBox.COLORP)
     if self.text:
         textImage, r = TextBox.FONT.render(self.text, TextBox.COLORP)
         self.textTopLeft = ((self.rect.width - textImage.get_width()) // 2,
                             (self.rect.height - textImage.get_height()) //
                             2)
         self.imageMousePress.blit(textImage, self.textTopLeft)
     self.image = self.imageMousePress
Ejemplo n.º 16
0
 def draw_r(self):
     if (self.beveled):
         drawRoundRect(self.surface, self.getX(), self.getY(), self.width,
                       self.height, self.borderWidth, self.color)
     else:
         gfxdraw.rectangle(
             self.surface,
             (self.getX(), self.getY(), self.getX() + self.getWidth(),
              self.getY() + self.getHeight()), self.color)
     for child in self.children:
         child.draw()
Ejemplo n.º 17
0
 def draw(self, screen):
     """
     """
     if not (self.hollow):
         gfxdraw.box(screen, (int(self.getX()), self.getY(), self.getWidth(), self.getHeight()),
                     self.background_color)
     if (self.border):
         gfxdraw.rectangle(screen, (int(self.getX()), self.getY(), self.getWidth(), self.getHeight()),
                           self.border_color)
     if (self.image is not None):
         screen.blit(self.image)
     elif (self.obj is not None):
         self.obj.draw(screen)
Ejemplo n.º 18
0
def draw_box(rect, color, filled=False, global_coords=True):
    if global_coords:
        t = (
            world_to_win_pt(rect[0][0], c.player.center),
            world_to_win_pt(rect[0][1], c.player.center)
        )
        w = (
            world_to_win_length(rect[1][0]),
            world_to_win_length(rect[1][1])
        )
        rect = (t, w)
    
    if filled:
        screen.fill(color, rect)
    else:
        gfxdraw.rectangle(screen, rect, color)
Ejemplo n.º 19
0
    def draw(self):
        super(Timings, self).draw()

        tot = 0
        for val in Data.timings[1:]:
            tot += val
        pixperms = float(self.w) / (tot + 1)
        x = self.x

        for val, ratio, label in zip(Data.timings[1:], Data.ratios[1:], Data.timingsLabels[1:]):
            w = ratio * self.w
            rect = pygame.Rect(x, self.y, w, self.h)
            gfxdraw.rectangle(self.surface, rect, white)
            ren = font.render(label + " " + str(val) + "us per call " + str(int(ratio*100)) + "%", True, white)
            ren = pygame.transform.rotate(ren, -90.)
            self.surface.blit(ren, (rect.left, self.y + 20))
            x += w
Ejemplo n.º 20
0
    def mkgui_tile(self, loc, only_clear=False):
        """ Redraw the gui tile or just clear the tile.

            only_clear: use to clear 'unmovable' tiles; if False, clear and then redraw tile
        """
        loc = self.resolve_loc(loc)
        ts = self.tilesize
        if self.circle:
            gfxdraw.filled_circle(self.sfc, loc[0], loc[1], iround(ts/2), white)
            if not only_clear:
                gfxdraw.aacircle(self.sfc, loc[0], loc[1], iround(ts/2-4), gray)
        else:
            r = center_square(loc, ts)
            draw.rect(self.sfc, white, r, 0)
            if not only_clear:
                gfxdraw.rectangle(self.sfc, r, gray)
        self.scr.blit(self.sfc, (0,0))
Ejemplo n.º 21
0
    def rectangle(self, **kwargs):
        c = get_first_from_dict(kwargs, 'c', 'col', 'colour')
        pos = get_from_dict(kwargs, 'pos')
        size = get_from_dict(kwargs, 'size')
        scaled = get_from_dict(kwargs, 'scaled', default=False)

        if None in (c, pos, size):
            raise ValueError('Must provide colour, position and size')

        c = Colour(c)
        pos = Vector2(pos)
        size = Vector2(size)

        if not scaled:
            pos *= self.size
            size *= self.size

        draw.rectangle(self.display, (*(pos.tuple(int)), *(size.tuple(int))),
                       c)
Ejemplo n.º 22
0
    def rectangle(self, rect, color):
        """長方形を描画します.

        Parameters
        ----------
        rect : pygame.Rect or tuple of float
            長方形を示すpygame.Rectオブジェクトもしくは座標を格納したタプル.
            タプルは(x_min, y_min, width, height)の順番で値を格納する.
        color : tuple of int
            描画に使用される色を指定します.

        """

        return gfx.rectangle(self.pg.screen, rect, color)
Ejemplo n.º 23
0
 def __createImages__(self):
     text_image, r = Button.FONT.render(self.text, Button.COLOR)
     text_top_left = ((self.rect.width - text_image.get_width()) // 2,
                      (self.rect.height - text_image.get_height()) // 2)
     img_rect = self.image.get_rect()
     gfx.rectangle(self.imageBase, img_rect, Button.COLOR)
     self.imageBase.blit(text_image, text_top_left)
     self.imageMouseOver.fill(Button.COLOR_MOUSE_OVER)
     gfx.rectangle(self.imageMouseOver, img_rect, Button.COLOR)
     self.imageMouseOver.blit(text_image, text_top_left)
     self.imageMousePress.fill(Button.COLOR_PRESS)
     gfx.rectangle(self.imageMousePress, img_rect, Button.COLOR)
     self.imageMousePress.blit(text_image, text_top_left)
Ejemplo n.º 24
0
 def __createImages__(self):
     textImage, r = Button.FONT.render(self.text, Button.COLOR)
     textTopLeft = ((self.rect.width - textImage.get_width()) // 2,
                    (self.rect.height - textImage.get_height()) // 2)
     imgRect = self.image.get_rect()
     gfx.rectangle(self.imageBase, imgRect, Button.COLOR)
     self.imageBase.blit(textImage, textTopLeft)
     self.imageMouseOver.fill(Button.COLORO)
     gfx.rectangle(self.imageMouseOver, imgRect, Button.COLOR)
     self.imageMouseOver.blit(textImage, textTopLeft)
     self.imageMousePress.fill(Button.COLORP)
     gfx.rectangle(self.imageMousePress, imgRect, Button.COLOR)
     self.imageMousePress.blit(textImage, textTopLeft)
Ejemplo n.º 25
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
Ejemplo n.º 26
0
    # handle quit
    if event.type == pygame.QUIT:
      done = True

    # cycle the color of our rectangle if space bar is hit
    if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
      cycleColor()

  # keep frame rate to 60 fps
  clock.tick(60)

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

  # change x,y based on key presses
  pressed = pygame.key.get_pressed()
  if pressed[pygame.K_UP]: y -= 3
  if pressed[pygame.K_DOWN]: y += 3
  if pressed[pygame.K_LEFT]: x -= 3
  if pressed[pygame.K_RIGHT]: x += 3


  # draw our rectangle
  gfx.rectangle(screen,pygame.Rect(x,y,100,150),color)

  # update display
  pygame.display.flip()



Ejemplo n.º 27
0
	def _draw(self):
		screen = self.screen
		self.draw_count += 1

		if self.draw_count == 1:
			self.first_draw = time.clock()

		self.playboard.draw(screen)		

		# Score text
		text = self.score_font.render(' Score: %d ' % self.score, True, 
			THECOLORS["white"], THECOLORS["black"])		
		screen.blit(text, (10,0))
		
		# Level text
		text = self.score_font.render(' Level: %d ' % self.level, True, 
			THECOLORS["white"], THECOLORS["black"])		
		screen.blit(text, (self.width-text.get_width()-5,0))
		
		# Level progress box
		rect = pygame.Rect(20, 3+text.get_height(), self.width-40, 20)						
		rectangle(screen, rect, THECOLORS["white"])
		
		# Level progress indicator (fill)
		filled = (float(self.level_score)/self.level_score_goal)*(self.width-40)
		white_rect = pygame.Rect(20, 3+text.get_height(), filled, 20)
		black_rect = pygame.Rect(20+filled, 3+text.get_height(), self.width-40-filled, 20)
		screen.fill(THECOLORS["white"], white_rect)
		screen.fill(THECOLORS["black"], black_rect)
		rectangle(screen, rect, THECOLORS["white"])
							
		# Game over label when required
		if self.is_game_over:
			text = self.score_font.render(' GAME OVER ', True, THECOLORS["yellow"], THECOLORS["red"])		
			screen.blit(text, ((screen.get_width()/2) - (text.get_width()/2), self.header_height + 20))

			#high score table
			i = 0
			ypos = self.header_height + 10 + text.get_height() + 30
			for score in self._high_scores:
				if i == self.score_pos:
					fg_color = THECOLORS["black"]
					bg_color = THECOLORS["white"]
				else:
					fg_color = THECOLORS["white"]
					bg_color = THECOLORS["black"]
				text = self.score_font.render('  %6s - Level %2s (%s)  ' % (score[0], score[1], score[2]), True
					, fg_color, bg_color)
				screen.blit(text, ((screen.get_width()/2) - (text.get_width()/2), ypos))
				ypos += text.get_height()+10
				i += 1
			ypos += 20
			self.start_button.setCords((screen.get_width()/2) - (self.start_button.rect.width/2), ypos)
			screen.blit(self.start_button.image, self.start_button.rect)
							
		if self.is_level_complete:
			text = self.completed_font.render(' LEVEL COMPLETED ', True, THECOLORS["blue"], THECOLORS["yellow"])		
			screen.blit(text, ((screen.get_width()/2) - (text.get_width()/2), self.height/2-text.get_height()/2))
			
		pygame.display.flip()
		
		if DEBUG and self.draw_count == 100:
			print "Playboard draw CPU time=", time.clock()-self.first_draw
			self.draw_count = 0
Ejemplo n.º 28
0
import pygame
from pygame import gfxdraw
import random
from math import sqrt
from math import pi

pygame.init()
pygame.display.set_caption('Calculating the Value of Pi')
screen_width = 400
screen_height = 400
win = pygame.display.set_mode((screen_width, screen_height))
red = (238, 59, 59)
green = (127, 255, 0)
blue = (0, 255, 255)
gfxdraw.rectangle(win, (-200, -200, screen_width, screen_height), red)
r = 200
circle_count = 0
total = 0
actual_pi = pi
best_pi = 0
cal_true = ""

run = True
while run:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
    for i in range(1000):
        x = random.randrange(-200, 200)
        y = random.randrange(-200, 200)
        d = sqrt((x ** 2) + (y ** 2))
Ejemplo n.º 29
0
import pygame
Ejemplo n.º 30
0
	def draw(self, screen):			
		my_surface, tmp_surface = self.my_surface, self.tmp_surface
		if self.needs_static_redraw:
			self.my_surface = my_surface = self.background.copy()
			
			# Draw the current piece background
			if self.get_last_pos():
				(c, r) = self.get_last_pos()
				pos = (c*self.piece_w, r*self.piece_h)
				box(my_surface, pos+(self.piece_w, self.piece_h), THECOLORS["blue"])
			
			# Draw the complete board
			for c in range(self.columns):
				for r in range(self.rows):
					piece_id = self.get_piece((c, r))
					if piece_id != 0:									
						pos = (c*self.piece_w, r*self.piece_h)
						rectangle(my_surface, pos+(self.piece_w, self.piece_h), 
							THECOLORS["white"] )
						if (c, r) in self._play_path[:-1]:
							continue
						text_color =  THECOLORS["white"]
						text = self.font.render(str(piece_id), True, text_color)	
						xpos = (c*self.piece_w) + (self.piece_w/2) - (text.get_width()/2)
						ypos = (r*self.piece_h) + (self.piece_h/2) - (text.get_height()/2)
						my_surface.blit(text, (xpos, ypos))
						
			# Turn those on play path gray
			for i in range(len(self._play_path)-1):
				c, r = self._play_path[i]
				piece_id = self.get_piece(self._play_path[i])
				pos = (c*self.piece_w+1, r*self.piece_h+1)
				box(my_surface, pos+(self.piece_w-1, self.piece_h-1), 
					PLAYED_BACKGROUND_COLOR )	
				if (c, r)  == self.start_pos:
					text_color = THECOLORS["green"]		
				else:
					text_color = PLAYED_COLOR
				text = self.font.render(str(piece_id), True, text_color)	
				xpos = (c*self.piece_w) + (self.piece_w/2) - (text.get_width()/2)
				ypos = (r*self.piece_h) + (self.piece_h/2) - (text.get_height()/2)				
				my_surface.blit(text, (xpos, ypos))				

			# Paint goals
			for c, r in self.goals:
				piece_id = self.get_piece((c, r))
				pos = (c*self.piece_w+1, r*self.piece_h+1)
				#box(my_surface, pos+(self.piece_w-1, self.piece_h-1), 
				#	THECOLORS["green"] )			
				#if (c, r) in self.touched_goals:
				#	box(my_surface, pos+(self.piece_w-1, self.piece_h-1), 
				#		THECOLORS["green"] )				
					
				text = self.font.render(str(piece_id), True, THECOLORS["yellow"])	
				xpos = (c*self.piece_w) + (self.piece_w/2) - (text.get_width()/2)
				ypos = (r*self.piece_h) + (self.piece_h/2) - (text.get_height()/2)				
				my_surface.blit(text, (xpos, ypos))				
								
			
			self.needs_static_redraw = False
		tmp_surface.blit(my_surface, (0,0))
		
		
		screen.blit(tmp_surface, (self.h_border, self.header_height))
Ejemplo n.º 31
0
 def rect(self, pos, size, color):
     """Draws a rectangle."""
     gfxdraw.rectangle(self.screen, (*pos, *size), color)
Ejemplo n.º 32
0
	def solve_png(self , tfuser, readfile):
	
		
		x = 0
		y = 0
		white = (64, 64, 64)
		w = 480
		h = 480
		self.startx = -1
		self.starty = -1
		self.endx = -1
		self.endy = -1
		
		if readfile.all_coordinates == True :
				
			self.block_screen_1 = False ## select smaller map
			self.block_screen_2 = False ## select start and stop
			self.startx = readfile.startx
			self.starty = readfile.starty
			self.endx = readfile.endx
			self.endy = readfile.endy
		
		self.guiwidth = readfile.width
		self.guiheight = readfile.height
		
		surface = pg.image.load(self.mapname)
		icon = pg.image.load(self.iconname)

		pg.display.set_icon(icon)
		
		## initialize control components ##
		gray = (16,16,16)
		red =(255,0,0)
		green = (0,255,0)
		blue = (0,0,255)
		blocksize = (w /readfile.width) -2
		if blocksize <= 2 : blocksize = 4
		
		self.controldim =( blocksize +2) * 2  
		if self.controldim < 16 : self.controldim = 16
		#print blocksize , self.controldim
		
		self.boxborder = 5
		self.boxwidth = 3 * self.controldim # 48
		self.boxheight = self.controldim # 16
		self.box = pg.Surface((self.boxwidth + (self.boxborder * 2), 
			self.boxheight + (self.boxborder * 2)))
		self.box.fill(gray)
		boxred = pg.Surface((self.controldim,self.controldim))
		boxred.fill(red)
		boxgreen = pg.Surface((self.controldim,self.controldim))
		boxgreen.fill(green)
		boxblue = pg.Surface((self.controldim,self.controldim))
		boxblue.fill(blue)
		self.box.blit(boxgreen, (0 + self.boxborder,0 + self.boxborder))
		self.box.blit(boxred, (self.controldim + self.boxborder,0 + self.boxborder))
		self.box.blit(boxblue, (self.controldim * 2 + self.boxborder, 0 + self.boxborder))
		self.mousex = 0
		self.mousey = 0
		self.boundtop = h - (self.box.get_height() - self.boxborder)
		self.boundbottom = h - self.boxborder
		self.boundgreenleft = w - (self.box.get_width() -  self.boxborder)
		self.boundgreenright = w - (self.box.get_width() -  self.boxborder) + self.controldim #16
		self.boundredleft = w - (self.box.get_width() -  self.boxborder) + self.controldim #16
		self.boundredright = w - (self.box.get_width() -  self.boxborder) + self.controldim * 2 #32
		self.boundblueleft = w - (self.box.get_width() -  self.boxborder) + self.controldim * 2 #32
		self.boundblueright = w - (self.box.get_width() -  self.boxborder) + self.controldim * 3 #48
		
		
		self.startblock = pg.Surface((blocksize,blocksize))
		self.startblock.fill(green)
		self.endblock = pg.Surface((blocksize,blocksize))
		self.endblock.fill(red)
		self.pathblock = pg.Surface((blocksize,blocksize))
		self.pathblock.fill(blue)
		self.blockoffset = 0#blocksize / 2 
		
		## fixscale not used ##
		self.fixscale = ( float  ( w - (int ( w/ readfile.width  ) * readfile.width ))/w ) + 1
		
		## all walls ##
		self.wallbox = pg.Surface( (math.ceil((w/readfile.width)* self.fixscale), 
			math.ceil((h/readfile.height) * self.fixscale )))
		self.wallbox.fill((0,0,0))
		
		
		## display first screen ##
		screensurf = surface
		screen = pg.display.set_mode((w, h))
		pg.display.set_caption(self.maptitle, self.maptitle)
		screen.fill((white))
		
		## skip if all coordinates are specified at command line ##
		if self.block_screen_1 == True:
			self.quit = 0
			running = 1
			while running:

				for event in pg.event.get():
					if event.type == pg.QUIT:
						running = 0
						self.quit = 1	
					if event.type == pg.KEYUP:
						self.action_detect = True
						if event.key == pg.K_RETURN:
							running = 0
						if event.key == pg.K_UP:
							y -= 5
							if y < 0 : 
								y = 0
						if event.key == pg.K_DOWN:
							y += 5
							if y + readfile.height > screen.get_height() : 
								y = screen.get_height() - readfile.height 
							
						if event.key == pg.K_LEFT:
							x -= 5
							if x < 0 : 
								x = 0
						if event.key == pg.K_RIGHT:
							x += 5
							if x + readfile.width > screen.get_width() : 
								x = screen.get_width() - readfile.width 
											
				self.gui_instructions( screen, 1, event, w, h)
				
				screensurf = surface.copy()
				screen.fill(white)
				screen.blit(screensurf,(0,0))
				pgd.rectangle(screen, ((x,y),(readfile.width,readfile.height)), (255,0,0))
				if not self.blit_instructions : pg.display.flip()
			
		## display second screen ##
		screen.fill((white))
		self.smallsurf = pg.Surface((readfile.width, readfile.height))
		bwsurf = pg.Surface((readfile.width, readfile.height))
		self.smallsurf.blit(surface,(0,0),((x,y), (readfile.width, readfile.height)))
		
		
		pg.transform.threshold(bwsurf, self.smallsurf,
			(0,0,0,0),(20,20,20,0), (255,255,255,0), 1)	
		
		screensurf = pg.Surface((w,h))
		screensurf.fill((255,255,255))
		screen.fill((255,255,255))
		
		## convert to array representation ##
		self.sa = [0] * readfile.width * readfile.height
		self.maze = [0] * readfile.width * readfile.height
		pxarray = pygame.PixelArray(self.smallsurf)
		for yy in range (0, readfile.width):
			for xx in range (0, readfile.height):
				p =  pxarray[xx,yy]

				if p == 0 : p = self.mz.WALL
				else : p = 0
				self.sa[(yy * readfile.width) + xx] = p
				
				g = 0
				if p != 0 : g = self.mz.WALL
				else : g = 0
				self.maze[(yy * readfile.width) + xx] = g
				
				if p == self.mz.WALL:
					#self.mz.wallout.append((yy * readfile.width) + xx)
					
					## print walls to screen ! ##
					xxx = float(xx * ( self.fixscale)) 
					yyy = float(yy * ( self.fixscale)) 
					screensurf.blit(self.wallbox, 
						(float(xxx * float (w  / readfile.width))   ,
						float(yyy * float (h  / readfile.height))   ))
		
		self.gui_state = 0
		
		self.PLACE_START = 1
		self.PLACE_END = 2
		self.FIND_PATH = 3
		self.HOLD_START = 4
		self.HOLD_END = 5
		
		self.action_detect = False
		
		## skip if all coordinates are specified at command line ##
		if self.block_screen_2 == True :
			self.running = 1
			while self.running == 1 and self.quit == 0:
			
				for event in pg.event.get():
					if event.type == pg.QUIT:
						self.running = 0
						self.quit = 1	
			
				screen.fill((white))
				screen.blit(screensurf,(0,0))
				self.gui_controls(screen, event, w,h)
				self.gui_instructions(screen, 2, event, w, h )
				if not self.blit_instructions : pg.display.flip()
			
			print "-startx", self.startx
			print "-starty", self.starty
			print "-stopx", self.endx
			print "-stopy", self.endy
		
	
		
		self.mz.endx = self.endx
		self.mz.endy = self.endy
		
		self.mz.startx = self.startx
		self.mz.starty = self.starty
		
		if self.quit != 1:
			## run cpu calculation ## tfuser !!
			tfuser.set_maze(self.maze)
			tfuser.set_startx(self.startx)
			tfuser.set_starty(self.starty)
			tfuser.set_stopx(self.endx)
			tfuser.set_stopy(self.endy)
			tfuser.set_width(readfile.width)
			tfuser.set_height(readfile.height)
			tfuser.set_wall_height(readfile.get_wall_height())
			#d.set_maze_printout_wall_height(s.get_randomized_floors() + 2)
			
			starttime = time.clock()
			tfuser.eval()
			
			
			endtime = time.clock()
			print  endtime - starttime , 'time on processor'
			tfuser.follow_path(tfuser.output)
		
		## print screen with solution ##
		self.running = 1
		while self.running == 1 and self.quit == 0:
			
			for event in pg.event.get():
				if event.type == pg.QUIT:
					self.running = 0
					self.quit = 1	
			
				if event.type == pg.KEYUP:
					if event.key == pg.K_RETURN:
						self.running = 0
			
				if event.type == pg.MOUSEBUTTONDOWN:
			
					left , middle, right = pg.mouse.get_pressed() 
					if left == True:
						self.running = 0
			
			screen.fill((white))
			screen.blit(screensurf,(0,0))
			for i in tfuser.found :
				xx = i - ( readfile.get_width() * (int(i / readfile.get_width() )))
				yy = int(i / readfile.get_width())
			
				xxx = float(xx * ( self.fixscale)) 
				yyy = float(yy * ( self.fixscale)) 
				
				screen.blit(self.pathblock,
					(float(xxx * float(screen.get_width() / readfile.width)) + self.blockoffset,
					float(yyy * float(screen.get_width() / readfile.width)) + self.blockoffset))
				screen.blit(self.startblock,
					(self.startx * (screen.get_width() / readfile.width) * self.fixscale, 
					self.starty * (screen.get_width() / readfile.width) * self.fixscale))
				screen.blit(self.endblock,
					(self.endx * (screen.get_width() / readfile.width) * self.fixscale,
					self.endy * (screen.get_width() / readfile.width) * self.fixscale))
			pg.display.flip()