pyclutter anyone?

donn donn.ingle at gmail.com
Fri Feb 5 18:19:06 CET 2010


No one uses pyClutter?
I have some code, it does not work, but maybe this will start to help 
solve the problem:

import clutter
from clutter import cogl

x,y=0,0

def boo(tl,frame,obj):#,evt):
	global x,y
	obj.set_position(x, y)

def xy(obj,evt):
	global x,y
	x,y = evt.x,evt.y

class G(clutter.Group):
	"""
	Attempt to make a Group that can clip its children to a path.
	"""
	def __init__(self,*args):
		clutter.Group.__init__(self,*args)
		#self.set_clip(0,0,10,10)
		self.connect("paint",self.do_paint)
		self._color = clutter.Color(255,200,100)
	def do_paint(self, args):
		width,height=200,200
		cogl.path_move_to(width / 2, 0)
		cogl.path_line_to(width, height)
		cogl.path_line_to(0, height)
		cogl.path_line_to(width / 2, 0)
		cogl.path_close()
		#cogl.set_source_color(self._color)
		#cogl.path_fill()

		## Colour me lost from here...
		cogl.clip_push_from_path()
		clutter.Group.do_paint(self)
		cogl.clip_pop()

def main():
	global group1
	stage = clutter.Stage()
	stage.set_size(500, 500)
	stage.set_color(clutter.color_from_string("#FFF"))

	rect1, rect2, rect3 = clutter.Rectangle(), clutter.Rectangle(), 
clutter.Rectangle()
	group1, group2, group3 = G(), clutter.Group(), clutter.Group()

	group1.add(rect1, group2)
	group2.add(rect2, group3)
	group3.add(rect3)

	group1.set_position(100, 100)
	group2.set_position(100, 100)
	group3.set_position(100, 100)

	rect1.set_position(0, 0)
	rect2.set_position(0, 0)
	rect3.set_position(0, 0)

	rect1.set_size(150, 150)
	rect2.set_size(150, 150)
	rect3.set_size(150, 150)

	rect1.set_color(clutter.color_from_string("#FF000090"))
	rect2.set_color(clutter.color_from_string("#00FF0090"))
	rect3.set_color(clutter.color_from_string("#0000FF90"))

	stage.add(group1)

	stage.show_all()
	group1.show_all()
	group2.show_all()
	group3.show_all()

	stage.connect("key-press-event", clutter.main_quit)
	stage.connect('destroy', clutter.main_quit)
	stage.connect('motion-event', xy)

	path = clutter.Path('M 0 0 L 300 0 L 300 300 L 0 300z')
	timeline = clutter.Timeline(4000)
	timeline.set_loop(True)
	alpha = clutter.Alpha(timeline,clutter.EASE_OUT_SINE)
	p_behaviour = clutter.BehaviourPath(alpha, path)
	path.add_move_to(0, 0)
	p_behaviour.apply(group3)	

	timeline.add_marker_at_time("foo",2000)

	timeline.start()

	t=clutter.Timeline(1000)
	t.set_loop(True)
	t.connect('new-frame', boo, group1)
	t.start()

	clutter.main()

if __name__ == '__main__':
	main()

\d

-- 
Fonty Python and Things! -- http://otherwise.relics.co.za/wiki/Software



More information about the Python-list mailing list