May 2012
M T W T F S S
« Jul «-»  
 123456
78910111213
14151617181920
21222324252627
28293031  

Leaving Chris World?

Why not bring back a souvenir?

Archives

Roulette Text

How fitting that these all appear in a folder I frequent nowadays called
Playing with Blender Python. I should rename it to something more boring.. *cough er I mean professional like. Or maybe call it Mastering Blender Python because that is what I really seek to do by continuing to hone my skills in this arena.

I should really be figuring out if I can call Blender functions from
the the running GameEngine but instead I'll take a moment to explain
just one of the projects I was working on.

Naming these things can be a bit tricky. For the longest time I had
the vision in my head but no nomenclature to peg to it. It hit me that
I was waiting for the next to roll into place. And so forth I dubbed
it Roulette Text.

You would have to see a movie of it in action but basically
you can imagine making a slot on a slot machine for every letter
in a message and them rolling random letters until your message
appears.

Shamefully my code is in pretty bad shape.
(And since class objects die after every frame Call I can't
use a class the way they are suppose to be used) I had to peg
some savedata and restore functions. (A kludge) by any
standard. And it's not very user friendly.
Unless, you yourself ARE the python interpreter but hey.
It's a work in progress and I offer it up into the web for
those whom can read it to have a laugh or two.

 
"""
Roulette Text Basis
July 3, 2008
by Chris B Stones
 
All the way from the mother country known as scratch.
here it is the basis for the Roulette Text effect.
The function I use to randomize the text before I
throw it into Blender.
 
"""
 
import Blender
from Blender import *
 
import ExtensionLIB
from ExtensionLIB import *
 
import random
from random import randint
import time
from time import sleep
 
import os
 
# ('A',duration,done) ('C',45,true)
# cname each instance of an object needs a name for the data
# it iwll save to the Registry (MUST be UNIQUE)
# a dictionary of saved class ob instances would be a good idea
print "Reg Keys ==================="
print Registry.Keys()
print "======= end of reg keys ===="
 
class rText:
	def __init__(self,cname,msg,duration):
		self.cname = cname
		if self.cname in Registry.Keys():
			#this object is already being run
			self.restore()
			return
		self.duration = duration #int frame_count
		self.count = 0 # from 0 to duration is the animatino
		self.payload= []
		for c in msg:
			self.payload.append((c,randint(0,duration-2),False))
 
	def render(self):
		self.count += 1
		self.txt = ''
		tmp_load = []
		for c,d,done in self.payload:
			if not done:
				self.txt += chr(randint(0,25)+65)
				if d == 0:
 					done = True
				else:
					d -= 1
			else:
				self.txt += c  #no more random if your done
			#update payload
			tmp_load += [(c,d,done)]
 
		self.payload = tmp_load
		drawText(0.0,0.0,0.0,"rText",self.txt)
 
	def restore(self): #restore from dictionary
		if self.cname in Registry.Keys():
			data = Registry.GetKey(self.cname)
			self.duration = data["duration"]
			self.payload = data["payload"]
			self.txt = data["txt"]
			self.count = data["count"]
		else:
			print "nothing to restore"
 
	def savedata(self):
		data = {"duration":self.duration,
			    "payload":self.payload,
				"txt":self.txt,
				"count":self.count}
		Registry.SetKey(self.cname,data)
 
        # if I check if all or done then it stops just make sure
        # one random charactor has full duration
 
# you don't need a NEW class you need the same class how do you work
# with the same python class everytime this script runs?
cool = rText("classname2","WELCOME TO CHRIS WORLD",100)
 
cool.render()
cool.savedata()
#for i in range(cool.duration+2):
#	cool.render()
Window.RedrawAll()
 

You must be logged in to post a comment.