Hi,
I'm playing around with the bspline behaviour and seeing something
odd. I can define a 4-point path that causes an object to curve down
the stage. However while it starts off smooth it gradually becomes
more jittery until at the end it is jumping about a considerable
degree. Is this a problem with the bspline implementation or
something in the way I am using it? I've attached a python test case
below.
Thanks,
Steve
import sys, math, colorsys
import clutter, cairo
from cluttercairo import CairoTexture
WIDTH = 1000
HEIGHT = 800
GRIDWIDTH = 10
GRIDHEIGHT = 8
BLOCKWIDTH = WIDTH/GRIDWIDTH
BLOCKHEIGHT = HEIGHT/GRIDHEIGHT
##############################################################################
# Drawing ops
def clear(ctx):
ctx.set_operator (cairo.OPERATOR_CLEAR)
ctx.paint()
ctx.set_operator(cairo.OPERATOR_OVER)
def drawlayout(tex):
ctx = tex.cairo_create()
clear(ctx)
# Axis'
ctx.set_line_width(1)
ctx.set_source_rgba(1, 1, 1, 1)
for x in range(0, WIDTH, int(BLOCKWIDTH)):
ctx.move_to(x+.5, 0)
ctx.line_to(x+.5, HEIGHT)
ctx.stroke()
for y in range(0, HEIGHT, int(BLOCKHEIGHT)):
ctx.move_to(0, y+.5)
ctx.line_to(WIDTH, y+.5)
ctx.stroke()
class BlockTexture(CairoTexture):
def __init__(self, name, colour):
CairoTexture.__init__(self, width=BLOCKWIDTH, height=BLOCKHEIGHT)
ctx = self.cairo_create()
tenpc = BLOCKWIDTH * 0.1
ctx.set_source_rgba(*colour)
ctx.move_to(tenpc, tenpc)
ctx.line_to(BLOCKWIDTH-tenpc, tenpc)
ctx.line_to(BLOCKWIDTH-tenpc, BLOCKWIDTH-tenpc)
ctx.line_to(tenpc, BLOCKWIDTH-tenpc)
ctx.close_path()
ctx.fill()
ctx.set_source_rgba(1,1,1,1)
ctx.set_font_size(16)
x_bearing, y_bearing, width, height = ctx.text_extents(name)[:4]
ctx.move_to(BLOCKWIDTH / 2 - width / 2,
BLOCKHEIGHT / 2 + height / 2)
ctx.show_text(name)
######################################################################
if __name__ == '__main__':
stage = clutter.Stage()
stage.connect('destroy', clutter.main_quit)
stage.connect('button-press-event', clutter.main_quit)
stage.connect('key-press-event', clutter.main_quit)
stage.set_size(WIDTH, HEIGHT)
stage.set_color(clutter.Color(0x0, 0x0, 0x0, 0xff))
if False:
background = CairoTexture(width=WIDTH, height=HEIGHT)
drawlayout(background)
background.set_position(0,0)
background.show()
stage.add(background)
bt = BlockTexture("Test", (0,0,1))
bt.show_all()
bt.set_position(0,0)
stage.add(bt)
## Define behaviour
timeline = clutter.Timeline(num_frames=int(240), fps=30)
timeline.set_loop(True)
knots = ((0, 0),
(WIDTH, 0),
(WIDTH, HEIGHT-BLOCKHEIGHT),
(0, HEIGHT-BLOCKHEIGHT),)
alpha = clutter.Alpha(timeline, clutter.ramp_func)
behave = clutter.BehaviourBspline(alpha=alpha, knots=knots)
behave.apply(bt)
timeline.start()
stage.show_all()
clutter.main()