- #pizero console gfx stub
- import os
- import pygame
- import time
- import random
- class pyscope :
- screen = None;
- sizeX=0
- sizeY=0
- font= None
- def __init__(self):
- "Ininitializes a new pygame screen using the framebuffer"
- # Based on "Python GUI in Linux frame buffer"
- # http://www.karoltomala.com/blog/?p=679
- disp_no = os.getenv("DISPLAY")
- if disp_no:
- print "I'm running under X display = {0}".format(disp_no)
- # Check which frame buffer drivers are available
- # Start with fbcon since directfb hangs with composite output
- drivers = ['fbcon', 'directfb', 'svgalib']
- found = False
- for driver in drivers:
- # Make sure that SDL_VIDEODRIVER is set
- if not os.getenv('SDL_VIDEODRIVER'):
- os.putenv('SDL_VIDEODRIVER', driver)
- try:
- pygame.display.init()
- except pygame.error:
- print 'Driver: {0} failed.'.format(driver)
- continue
- found = True
- break
- if not found:
- raise Exception('No suitable video driver found!')
- size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
- self.sizeX = pygame.display.Info().current_w
- self.sizeY = pygame.display.Info().current_h
- print "Framebuffer size: %d x %d == %d x %d " % (size[0], size[1],self.sizeX,self.sizeY)
- self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
- # Clear the screen to start
- self.screen.fill((0, 0, 0))
- # Initialise font support
- pygame.font.init()
- # Render the screen
- pygame.display.update()
- self.font=pygame.font.Font(None,30)
- def __del__(self):
- "Destructor to make sure pygame shuts down, etc."
- def test(self):
- # Fill the screen with red (255, 0, 0)
- red = (255, 0, 0)
- self.screen.fill(red)
- # Update the display
- pygame.display.update()
- def drawTest(self,count):
- #pygame.draw.rect(self.screen, borderColor, (8,28,504,324), 2)
- colorRed=(255,0,0)
- pygame.draw.line(self.screen, lineColor, (count, 30), (count, 350))
- pygame.draw.circle(self.screen,colorRed,(100,100),20)
- #self.message_to_screen("test",(0,255,0))
- self.texts(count)
- def texts(self,score):
- scoretext=self.font.render("Score:"+str(score), 1,(255,255,255))
- self.screen.blit(scoretext, (500, 457))
- def message_to_screen(self,msg,color):
- myfont = pygame.font.SysFont(None,72)
- textSurface = myfont.render('Hello world',False, (color))
- pygame.Surface.blit(textSurface,(100,100))#screen_test[display_width/2,display_height/2])
- def drawGraticule(self):
- "Renders an empty graticule"
- # The graticule is divided into 10 columns x 8 rows
- # Each cell is 50x40 pixels large, with 5 subdivisions per
- # cell, meaning 10x8 pixels each. Subdivision lines are
- # displayed on the central X and Y axis
- # Active area = 10,30 to 510,350 (500x320 pixels)
- borderColor = (255, 255, 255)
- lineColor = (64, 64, 64)
- subDividerColor = (128, 128, 128)
- # Outer border: 2 pixels wide
- pygame.draw.rect(self.screen, borderColor, (8,8,self.sizeX-8,self.sizeY-8), 4)
- # Horizontal lines (40 pixels apart)
- pygame.draw.line(self.screen, lineColor, (8,8), (self.sizeX-8,self.sizeY-8) )
- #print("ssx="+str(self.sizeX))
- #print("ssy="+str(self.sizeY))
- for i in range(0,self.sizeY,self.sizeY/10):
- y = i #70+i*40
- pygame.draw.line(self.screen, lineColor, (0, y), (self.sizeX, y))
- #print("i="+str(i))
- # Vertical lines (50 pixels apart)
- for i in range(0, self.sizeX, self.sizeX/10):
- x = i #60+i*50
- pygame.draw.line(self.screen, lineColor, (x, 0), (x,self.sizeY))
- # Vertical sub-divisions (8 pixels apart)
- for i in range(1, 40):
- y = 30+i*8
- pygame.draw.line(self.screen, subDividerColor, (258, y), (262, y))
- # Horizontal sub-divisions (10 pixels apart)
- for i in range(1, 50):
- x = 10+i*10
- pygame.draw.line(self.screen, subDividerColor, (x, 188), (x, 192))
- # Create an instance of the PyScope class
- scope = pyscope()
- count=0
- while True:
- pygame.display.update()
- time.sleep(0.033)#1/30)
- scope.screen.fill((0,0,0))
- scope.drawGraticule()
- #scope.test()
- count=count+10
- if (count > 1000): count=1
- lineColor = (64, 64, 64)
- borderColor = (255, 255, 255)
- #pygame.drawTest(count)
- scope.drawTest(count)
Untitled
Posted by Anonymous on Mon 30th Jul 2018 11:44
raw | new post
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.