欢 迎 光 临
's BLog
这就是我
最新公告
站点日历
最新日志
最新回复
最新留言
 日志搜索

友情链接
其他信息
·研究python时自己写的一个时钟DEMO 2of4     -|liurm 发表于 2007/5/15 9:27:00

---------原创,引用请注明出处liurm.mypm.net-----------------

 

2 classClock.py 这是时钟的类,处理时针、分针、秒针的刷屏更新

#
#the class of clock

import pygame,os,time
from pygame.locals import *
import pyfunction

class MyClock(pygame.sprite.Sprite):
    """draw a clock on the screen. it can spin the fingers.
    """
    def __init__(self):
        #call Sprite intializer
        pygame.sprite.Sprite.__init__(self)

        #load Images:hour min sec
        self.oriImageHour, self.rectHour = pyfunction.loadImage('hour.bmp', -1)
        self.imageHour = self.oriImageHour
        self.oriImageMin, self.rectMin = pyfunction.loadImage('minute.bmp', -1)
        self.imageMin = self.oriImageMin
        self.oriImageSec, self.rectSec = pyfunction.loadImage('second.bmp', -1)
        self.imageSec = self.oriImageSec

        #screen position
        screen = pygame.display.get_surface()
        self.area = screen.get_rect()
        background = pygame.Surface(screen.get_size())
        self.width = background.get_width()
        self.height = background.get_height()
        if self.width > self.height :
            self.handlength = self.height
        else:
            self.handlength = self.width
        self.center = (self.width/2, self.height/2)
 
    def updateHour(self):  self._tickhour()
    def updateMin(self):  self._tickmin()
    def updateSec(self):  self._ticksec()

    def _transImage(self,hand,digi,scale):
        rotozoom = pygame.transform.rotozoom
        self.image = rotozoom(hand, digi, scale)
        self.rect = self.image.get_rect(center=self.center)
       
    def _tickhour(self):
        "tick tick hour"
        hour = time.localtime().tm_hour\
               + time.localtime().tm_min / 60.0 # must be 60.0, if 60, devide=0
        rotozoom = pygame.transform.rotozoom
        self._transImage(self.oriImageHour, -30 * hour, self.handlength * .0005 )

    def _tickmin(self):
        "tick tick minute"
        min = time.localtime().tm_min
        rotozoom = pygame.transform.rotozoom
        self._transImage(self.oriImageMin, -6 * min, self.handlength * .0006)
       
    def _ticksec(self):
        "tick tick second"
        sec = time.localtime().tm_sec
        rotozoom = pygame.transform.rotozoom
        self._transImage(self.oriImageSec, -6 * sec, self.handlength * .004)
       

 

[阅读全文 | 回复(0) | 引用通告 | 编辑 | 收藏该日志]

发表评论:

    昵称:
    密码:
    主页:
    标题: