gewel.draw.SceneSequence
- class gewel.draw.SceneSequence(scenes: Iterable[gewel.draw.Scene], render_width: int = 640, render_height: int = 480, z: Union[float, Tvf, PyTvf] = 0.0)[source]
Bases:
gewel.draw.BaseSceneMethods
appendThis method renders the drawable into pixels.
Fade the object from it's current alpha to a new value.
Change the value of an attribute of the object from the value it has at the current next-action time to a new value by ramping it linearly between the old and new values over the course of a given duration.
Return a version of the drawable that is rotated.
Return a version of the drawable that is rotated.
Construct and return a new drawable that is scaled in the x and y directions.
Set the next-action time.
Construct and return a new drawable that is transformed by the translation matrix specified by the parameters.
Construct and return a new drawable that is translated by a relative amount in the x and y directions.
Wait for a specified amount of time.
Wait for another object to finish whatever action it is currently doing.
Update the next-action time so that it is at least the given time.
Attributes
alphaTransparency/opacity.
render_heightrender_widthThe next-action time.
zz depth of the object.
- draw(ctx: cairocffi.context.Context, t: float) None[source]
This method renders the drawable into pixels.
Drawableobjects typically have time-varying behavior. For example, the x and y location of the object in a scene may be time-varying floats (see theTvfclass for details). It is the responsibility of thedraw()method to render the correct pixels for time passed in.Note that this method is very rarely called directly by user code. Instead, it is called by utility classes that render a
Scenecontaining aDrawableobjects. Examples includegewel.record.Mp4Recorder, which renders a scene to an MP4 file, orgewel.player.Playerthat creates an interactive preview of aSceneor thegewel.draw.Scene.__repr__()method that render a scene into an IPython notebook widget.- Parameters
ctx – The context in which to render. This is an object with low-level drawing primitives that the
draw()method relies on to render at the pixel level.t – The time at which to render. That is, we should render the object as it is intended to appear at this time in the scene. Exactly what that is is typically controlled by properties of the object that are
Tvfobjects.
- fade_to(alpha: Union[float, Tvf, PyTvf], duration: float, update_time: bool = True)
Fade the object from it’s current alpha to a new value. Alpha values range from 0.0, which means completely transparent, to 1.0, which means completely opaque. Most newly constructed
Drawableclasses that support alpha default to a value of 1.0.See Using fade_to() for sample usage.
- Parameters
alpha – The new alpha value. Should be between 0.0 and 1.0, inclusive. Values outside this range produce undefined behavior that may change in future versions.
duration – The amount of time, in seconds, the fade from the current alpha to the new alpha should take.
update_time – Should the object’s time be updated. Normally this is True. Making it False does not change the time, so that other updates can be made on the same object at the same time it is fading. For example,
move_to()can be called to make the object move as it fades.
- Returns
- Return type
None
- ramp_attr_to(name: str, to: float, duration: float, update_time: bool = True) None
Change the value of an attribute of the object from the value it has at the current next-action time to a new value by ramping it linearly between the old and new values over the course of a given duration.
See Next-Action Time During Scripting for more on next-action time.
- Parameters
name – Name of the attribute to update.
to – Value to change to.
duration – Time in seconds over which the value ramps from the old to the new value.
update_time – If
True, update the object’s next-action time so that it isdurationlater than it was.
- rotated(radians: Union[float, Tvf, PyTvf], z: Optional[Union[float, Tvf, PyTvf]] = None) Drawable
Return a version of the drawable that is rotated. See also
rotated_degrees().- Parameters
radians – How much to rotate by, in radians.
z – The z depth of the resulting drawable. If not supplied, the z depth of
selfis used.
- Returns
A new drawable that renders as the original but rotated.
- Return type
- rotated_degrees(degrees: Union[float, Tvf, PyTvf], z: Optional[Union[float, Tvf, PyTvf]] = None) Drawable
Return a version of the drawable that is rotated. See also
rotated().- Parameters
degrees – How much to rotate by, in degrees.
z – The z depth of the resulting drawable. If not supplied, the z depth of
selfis used.
- Returns
A new drawable that renders as the original but rotated.
- Return type
- scaled(sx: Union[float, Tvf, PyTvf], sy: Optional[Union[float, Tvf, PyTvf]] = None, z: Optional[Union[float, Tvf, PyTvf]] = None) Drawable
Construct and return a new drawable that is scaled in the x and y directions.
- Parameters
sx – Scale in the x direction.
sy – Scale in the y direction.
z – The z depth of the resulting drawable. If not supplied, the z depth of
selfis used.
- Returns
A new drawable that renders as the original but scaled.
- Return type
- set_time(t: float)
Set the next-action time.
See Next-Action Time During Scripting for more on next-action time.
- Parameters
t – The new next-action time.
- property time: float
The next-action time. See Next-Action Time During Scripting for more on next-action time.
- Returns
The next action time.
- Return type
float
- transformed(xx: Union[float, Tvf, PyTvf] = 1.0, yx: Union[float, Tvf, PyTvf] = 0.0, xy: Union[float, Tvf, PyTvf] = 0.0, yy: Union[float, Tvf, PyTvf] = 1.0, x0: Union[float, Tvf, PyTvf] = 0.0, y0: Union[float, Tvf, PyTvf] = 0.0, z: Optional[Union[float, Tvf, PyTvf]] = None) Drawable
Construct and return a new drawable that is transformed by the translation matrix specified by the parameters. The default parameter values produce the identity transform.
The location of any point (x, y) in the original drawable is translated to the new point (x’, y’) where
x’ =
xx* x +xy* y +x0and
y’ =
yy* y +yx* x +y0- Parameters
xx – Element of the matrix.
yx – Element of the matrix.
xy – Element of the matrix.
yy – Element of the matrix.
x0 – Translation in x
y0 – Translation in y
z – z depth of the new drawable. If
Nonethenself.zis used.
- Returns
A transformed version of
self.- Return type
- translated(dx: Union[float, Tvf, PyTvf], dy: Union[float, Tvf, PyTvf], z: Optional[Union[float, Tvf, PyTvf]] = None) Drawable
Construct and return a new drawable that is translated by a relative amount in the x and y directions.
- Parameters
dx – How far to translate in the x direction.
dy – How far to translate in the y direction.
z – The z depth of the resulting drawable. If not supplied, the z depth of
selfis used.
- Returns
A new drawable that renders as the original but translated.
- Return type
- wait(duration: float) None
Wait for a specified amount of time. This updates the object’s next-action time by adding a constant amount of time to it.
See Next-Action Time During Scripting for more on next-action time.
- Parameters
duration – How long to wait, in seconds.
- wait_for(other: Union[gewel._timekeeper.TimekeeperMixin, Iterable[gewel._timekeeper.TimekeeperMixin]]) None
Wait for another object to finish whatever action it is currently doing. This method us used at scripting time to ensure that an object updates its next-action time so that it is no earlier than the next-action time of another object.
See Next-Action Time During Scripting for more on next-action time.
- Parameters
other – The object to wait for. Or, an iterable collection of objects. If iterable, then wait for the one with the latest time.
- wait_until(at_least: float) None
Update the next-action time so that it is at least the given time. If it is already greater than that, change nothing.
See Next-Action Time During Scripting for more on next-action time.
- Parameters
at_least – The minimum new next-action time.