pastebin - collaborative debugging tool
python.kpaste.net RSS


Untitled
Posted by Anonymous on Mon 30th Jul 2018 11:44
raw | new post

  1. #pizero console gfx stub
  2.  
  3. import os
  4. import pygame
  5. import time
  6. import random
  7.  
  8. class pyscope :
  9.     screen = None;
  10.     sizeX=0
  11.     sizeY=0
  12.     font= None
  13.     def __init__(self):
  14.         "Ininitializes a new pygame screen using the framebuffer"
  15.         # Based on "Python GUI in Linux frame buffer"
  16.         # http://www.karoltomala.com/blog/?p=679
  17.         disp_no = os.getenv("DISPLAY")
  18.         if disp_no:
  19.             print "I'm running under X display = {0}".format(disp_no)
  20.        
  21.         # Check which frame buffer drivers are available
  22.         # Start with fbcon since directfb hangs with composite output
  23.         drivers = ['fbcon', 'directfb', 'svgalib']
  24.         found = False
  25.         for driver in drivers:
  26.             # Make sure that SDL_VIDEODRIVER is set
  27.             if not os.getenv('SDL_VIDEODRIVER'):
  28.                 os.putenv('SDL_VIDEODRIVER', driver)
  29.             try:
  30.                 pygame.display.init()
  31.             except pygame.error:
  32.                 print 'Driver: {0} failed.'.format(driver)
  33.                 continue
  34.             found = True
  35.             break
  36.    
  37.         if not found:
  38.             raise Exception('No suitable video driver found!')
  39.        
  40.         size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
  41.         self.sizeX = pygame.display.Info().current_w
  42.         self.sizeY = pygame.display.Info().current_h
  43.         print "Framebuffer size: %d x %d == %d x %d " % (size[0], size[1],self.sizeX,self.sizeY)
  44.         self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
  45.         # Clear the screen to start
  46.         self.screen.fill((0, 0, 0))        
  47.         # Initialise font support
  48.         pygame.font.init()
  49.         # Render the screen
  50.         pygame.display.update()
  51.         self.font=pygame.font.Font(None,30)
  52.        
  53.     def __del__(self):
  54.         "Destructor to make sure pygame shuts down, etc."
  55.  
  56.     def test(self):
  57.         # Fill the screen with red (255, 0, 0)
  58.         red = (255, 0, 0)
  59.         self.screen.fill(red)
  60.         # Update the display
  61.         pygame.display.update()
  62.  
  63.     def drawTest(self,count):
  64.         #pygame.draw.rect(self.screen, borderColor, (8,28,504,324), 2)
  65.         colorRed=(255,0,0)
  66.         pygame.draw.line(self.screen, lineColor, (count, 30), (count, 350))
  67.         pygame.draw.circle(self.screen,colorRed,(100,100),20)    
  68.         #self.message_to_screen("test",(0,255,0))
  69.         self.texts(count)
  70.        
  71.     def texts(self,score):
  72.         scoretext=self.font.render("Score:"+str(score), 1,(255,255,255))
  73.         self.screen.blit(scoretext, (500, 457))
  74.        
  75.     def message_to_screen(self,msg,color):
  76.         myfont = pygame.font.SysFont(None,72)
  77.         textSurface = myfont.render('Hello world',False, (color))
  78.         pygame.Surface.blit(textSurface,(100,100))#screen_test[display_width/2,display_height/2])
  79.  
  80.     def drawGraticule(self):
  81.         "Renders an empty graticule"
  82.         # The graticule is divided into 10 columns x 8 rows
  83.         # Each cell is 50x40 pixels large, with 5 subdivisions per
  84.         # cell, meaning 10x8 pixels each.  Subdivision lines are
  85.         # displayed on the central X and Y axis
  86.         # Active area = 10,30 to 510,350 (500x320 pixels)
  87.         borderColor = (255, 255, 255)
  88.         lineColor = (64, 64, 64)
  89.         subDividerColor = (128, 128, 128)
  90.         # Outer border: 2 pixels wide
  91.         pygame.draw.rect(self.screen, borderColor, (8,8,self.sizeX-8,self.sizeY-8), 4)
  92.         # Horizontal lines (40 pixels apart)
  93.         pygame.draw.line(self.screen, lineColor, (8,8), (self.sizeX-8,self.sizeY-8) )
  94.         #print("ssx="+str(self.sizeX))
  95.         #print("ssy="+str(self.sizeY))
  96.  
  97.         for i in range(0,self.sizeY,self.sizeY/10):
  98.             y = i #70+i*40
  99.             pygame.draw.line(self.screen, lineColor, (0, y), (self.sizeX, y))
  100.             #print("i="+str(i))
  101.         # Vertical lines (50 pixels apart)
  102.         for i in range(0, self.sizeX, self.sizeX/10):
  103.             x = i #60+i*50
  104.             pygame.draw.line(self.screen, lineColor, (x, 0), (x,self.sizeY))
  105.  
  106.         # Vertical sub-divisions (8 pixels apart)
  107.         for i in range(1, 40):
  108.             y = 30+i*8
  109.             pygame.draw.line(self.screen, subDividerColor, (258, y), (262, y))
  110.         # Horizontal sub-divisions (10 pixels apart)
  111.         for i in range(1, 50):
  112.             x = 10+i*10
  113.             pygame.draw.line(self.screen, subDividerColor, (x, 188), (x, 192))
  114.  
  115.  
  116.  
  117. # Create an instance of the PyScope class
  118. scope = pyscope()
  119.  
  120. count=0
  121.  
  122. while True:
  123.     pygame.display.update()
  124.     time.sleep(0.033)#1/30)
  125.     scope.screen.fill((0,0,0))
  126.     scope.drawGraticule()
  127.     #scope.test()
  128.     count=count+10
  129.     if (count > 1000): count=1
  130.    
  131.     lineColor = (64, 64, 64)
  132.     borderColor = (255, 255, 255)
  133.     #pygame.drawTest(count)
  134.     scope.drawTest(count)

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at