So…
May 18, 2007 – 10:36 pmYeah, well, it’s my blog. Hi.
So, hmm, basically, I’m not really that much of a writer. I think I just started this blog because it happens to me quite often that when I search stuff on google, I find useful information on personal blogs, of all places. Solutions to coding problems (yes, I’m a coder) , interesting reviews and recommendations, and articles.
I thought that I should give back to the web, publish more code that I write, and help others with problems that I have solved. The hosting plan and domain were purchased about 2 months ago, and only now I write my first post, well, I’m a busy man XD
There’s more to come next. I don’t want to put too much effort to the first posts, as there’s a high chance that I will abandon this blog quickly, and no one will ever read them.
Anyway, I’ll post something small and quick that I had coded some days ago in 10 minutes.
Some weeks ago I’ve been contacted by an online buddy to whom I didn’t speak in 2 or 3 years. It was a period during which I was highly enthusiastic about 3d and animation, and he was one of the experts in the forum where I used to “hang”
. The short conversation with him inspired me to do some 3d modeling, and I came up with something (quite lame) for a quick modeling challenge in some forum.
So, I had a time limit, and I wanted to keep measure of time as I was modeling. The right thing to do was certainly to program a stopwatch in python using pygame ! I’ll just post the code now, and will look for a code highlighting plug-in for wordpress later.
import pygame,pygame.font from pygame.locals import * #yuck, global vars ^_^ font=None surface=None time=[0,0,0] # an array to keep the current time measurement which is being rendered start_state=[0,0,0] #the time measurement from which to start counting start_tick=0 # the number of ticks when we began counting on=False #wheter the stopwatch should be running or not def main(): global font,surface,on video_flags = DOUBLEBUF pygame.init() #initialize pygame surface = pygame.display.set_mode((200,100), video_flags) #create our main window SDL surface surface.fill((255,255,255)) #fill with white font = pygame.font.Font('INK2SCRI.TTF',60) #load up a ttf font last_tick = pygame.time.get_ticks() # initialize the tick count while 1: #do forever event = pygame.event.poll() if event.type == QUIT: break if event.type == KEYUP and event.key==32: # if the space bar was pushed if(on): # if currently running #prepare start_state for future use, save current time start_state[2] = time[2] start_state[1] = time[1] start_state[0] = time[0] else: #starting the timer, so set the tick count reference to the current tick count start_tick = pygame.time.get_ticks() on = not on #toggle on if(on): a = (pygame.time.get_ticks() - start_tick) # get the amount of ticks(miliseconds) that passed from when the stopwatch was last run time[2] = start_state[2]+ (a / 1000) % 60 #seconds time[1] = start_state[1]+((a / 1000) / 60 % 60) #minutes time[0] = start_state[0]+(a / 1000) / 3600 #hours draw() pygame.display.flip() def draw(): global surface,font #render the time, by converting each array member to a string, and concating with ':' in between time components. render in black on a white background. tempsurface=font.render(str(time[0])+':'+str(time[1])+':'+str(time[2]),1,(0,0,0),(255,255,255)) surface.fill((255,255,255)) #fill the screen with white, to erase the previous time surface.blit(tempsurface,(10,10)) # blit the temporary surface to the screen if(__name__=='__main__'): main()
Check out the screenshot:
And here’s the model that I used it for:
I’m happy to finally start this blog, hope I will manage to keep writing, and that people will actually read it some time in the future.
Ben.
2 Responses to “So…”
first!
By me on May 21, 2007
we want an update!!
By me on May 21, 2007