Exemple #1
0
#CLOCK_CENTER		= SerialTFT.Color.user_blue
#CLOCK_NUMBERS		= SerialTFT.Color.user_green
#CLOCK_DIGITAL		= SerialTFT.Color.user_blue
#CLOCK_HOUR_HAND	= SerialTFT.Color.user_cyan
#CLOCK_MINUTE_HAND 	= SerialTFT.Color.user_cyan
#CLOCK_SECOND_HAND 	= SerialTFT.Color.user_red
# -- END COLOR SETUP --

# Clear Screen
tft.screen_rotation(SerialTFT.Rotation.landscape)
tft.bg_color(CLOCK_BACKGROUND)
tft.clear_screen()

# Draw the numbers 12, 6, 3 and 9 around the clock in green
tft.font_size(SerialTFT.Font.small)
tft.fg_color(CLOCK_NUMBERS)

tft.goto_pixel(SerialTFT.Screen.width_half-5,5)
tft.write('12')

tft.goto_pixel(SerialTFT.Screen.width_half-3,SerialTFT.Screen.height-13)
tft.write('6')

tft.goto_pixel(SerialTFT.Screen.width_half+50,SerialTFT.Screen.height_half-3)
tft.write('3')

tft.goto_pixel(SerialTFT.Screen.width_half-54,SerialTFT.Screen.height_half-3)
tft.write('9')

# Draw clock outline
tft.fg_color(CLOCK_OUTLINE)
Exemple #2
0
class Simulation:
    def __init__(self, num_stars, max_depth):
 
        self.tft = SerialTFT("/dev/ttyAMA0", 9600, True, False)

        self.start_col = 0
        self.max_col = 7
        self.max_size = 2

        # This colour setup is best if you have firmware support

        # -- COLOR SETUP --
        if(MY_FIRMWARE_IS_MODIFIED):
            self.tft.set_color_hex(8,"#000000")
            self.tft.set_color_hex(9,"#333333")
            self.tft.set_color_hex(10,"#555555")
            self.tft.set_color_hex(11,"#777777")
            self.tft.set_color_hex(12,"#999999")
            self.tft.set_color_hex(13,"#BBBBBB")
            self.tft.set_color_hex(14,"#DDDDDD")
            self.tft.set_color_hex(15,"#FFFFFF")
            self.start_col = 8
            self.max_col = 15
            self.max_size = 2
        # -- END COLOR SETUP ---

        # Clear Screen
        self.tft.screen_rotation(SerialTFT.Rotation.landscape)
        self.tft.bg_color(SerialTFT.Color.black)
        self.tft.fg_color(SerialTFT.Color.white)
        self.tft.clear_screen()

        self.num_stars = num_stars
        self.max_depth = max_depth
 
        self.init_stars()
 
    def init_stars(self):
        """ Create the starfield """
        self.stars = []
        for i in range(self.num_stars):
            # A star is represented as a list with this format: [X,Y,Z]
            star = [randrange(-15,15), randrange(-15,15), randrange(1, self.max_depth)]
            self.stars.append(star)
 
    def move_and_draw_stars(self):
        """ Move and draw the stars """
        origin_x = self.tft.Screen.width / 2
        origin_y = self.tft.Screen.height / 2
 
        for star in self.stars:


            # Erase old position of star
            
            k = 128.0 / star[2]
            x = int(star[0] * k + origin_x)
            y = int(star[1] * k + origin_y)

            if 0 <= x < self.tft.Screen.width and 0 <= y < self.tft.Screen.height:
                size = int((1 - float(star[2]) / self.max_depth) * self.max_size) + 1
                if(MY_FIRMWARE_IS_MODIFIED):
                    self.tft.draw_pixel(x,y,0)
                    #self.tft.draw_box(x,y,size,size,0)
                else:
                    self.tft.fg_color(0)
                    self.tft.draw_rect(x,y,size,size)
            


            # The Z component is decreased on each frame.
            # Decease this number for a smoother, slower starfield
            star[2] -= 0.40
 
            # If the star has past the screen (I mean Z<=0) then we
            # reposition it far away from the screen (Z=max_depth)
            # with random X and Y coordinates.
            if star[2] <= 0:
                star[0] = randrange(-15,15)
                star[1] = randrange(-15,15)
                star[2] = self.max_depth
 
            # Convert the 3D coordinates to 2D using perspective projection.
            k = 128.0 / star[2]
            x = int(star[0] * k + origin_x)
            y = int(star[1] * k + origin_y)
 
            # Draw the star (if it is visible in the screen).
            # We calculate the size such that distant stars are smaller than
            # closer stars. Similarly, we make sure that distant stars are
            # darker than closer stars. This is done using Linear Interpolation.
            if 0 <= x < self.tft.Screen.width and 0 <= y < self.tft.Screen.height:
                size = int((1 - float(star[2]) / self.max_depth) * self.max_size) + 1
                shade = self.start_col + int((1 - float(star[2]) / self.max_depth) * 7) + 3

                if(shade > self.max_col):
                    shade = self.start_col

                if(MY_FIRMWARE_IS_MODIFIED):
                    self.tft.draw_pixel(x,y,shade)
                    #self.tft.draw_box(x,y,size,size,shade)
                else:
                    self.tft.fg_color(shade)
                    self.tft.draw_rect(x,y,size,size)

 
    def run(self):
        while 1:
            self.move_and_draw_stars()
    print "Oops! Unknown error."
    supporter_count = "Err3"

# initialize and clear the screen
tft.screen_rotation(SerialTFT.Rotation.landscape)
tft.bg_color(SerialTFT.Color.black)
tft.clear_screen()

# draw logos
tft.draw_bitmap("0icon.bmp", 0, SerialTFT.Screen.height_half - 27)
tft.draw_bitmap("0icon.bmp", SerialTFT.Screen.width - 32, SerialTFT.Screen.height_half - 27)

# write organization title
tft.font_size(SerialTFT.Font.small)
tft.bg_color(SerialTFT.Color.black)
tft.fg_color(SerialTFT.Color.yellow)
tft.goto_pixel(SerialTFT.Screen.width_half - 51, 5)
tft.write("Abgeordnetenwatch")
tft.goto_pixel(SerialTFT.Screen.width_half - 33, 15)
tft.write("hat aktuell")

# write huge number of supporters
tft.font_size(SerialTFT.Font.large)
tft.fg_color(SerialTFT.Color.red)
tft.goto_pixel(SerialTFT.Screen.width_half - 32, SerialTFT.Screen.height_half - 22)
tft.write(supporter_count)

# write supporter subline
tft.font_size(SerialTFT.Font.small)
tft.fg_color(SerialTFT.Color.yellow)
tft.goto_pixel(SerialTFT.Screen.width_half - 51, SerialTFT.Screen.height_half + 13)
Exemple #4
0
tft.screen_rotation(SerialTFT.Rotation.landscape)
tft.bg_color(SerialTFT.Color.black)
tft.clear_screen()

colors = [
	SerialTFT.Color.blue,
	SerialTFT.Color.red,
	SerialTFT.Color.green,
	SerialTFT.Color.cyan,
	SerialTFT.Color.magenta,
	SerialTFT.Color.yellow,
	SerialTFT.Color.white
]

tft.font_size(SerialTFT.Font.small)
tft.fg_color(SerialTFT.Color.white)
print('Drawing text')
tft.write_line('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu turpis enim, at luctus quam. Mauris augue augue, blandit quis dictum in, accumsan eget odio. In id laoreet massa.')
tft.font_size(SerialTFT.Font.medium)
tft.write_line('Starting load tests')
tft.font_size(SerialTFT.Font.large)
tft.write_line('Soooon')
time.sleep(5)

print('Testing pixel draw rate')
result = []
circle_count = 0
last_sec = time.localtime().tm_sec
total_count = 0
while len(result) < 10:
	for color in colors: