CPAnimation

org.cosplay.CPAnimation$
See theCPAnimation companion class
object CPAnimation

Companion object containing factory methods.

Attributes

Companion
class
Source
CPAnimation.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def filmStrip(id: String, frameMs: Long, loop: Boolean, bounce: Boolean, imgs: Seq[CPImage]): CPAnimation

Creates new filmstrip animation with given parameters.

Creates new filmstrip animation with given parameters.

filmstrip animation is a variation of time-based animation where all key frames have the same duration, like in a movie, hence the name.

Value parameters

bounce

If loop is true this defines how animation will loop once it reaches the last key frame: from the beginning or bounce and going backward towards the beginning. Default value is false which will force looping animation to start from the beginning.

frameMs

Individual frame duration in milliseconds (applied to all frames).

id

Unique ID of the animation.

imgs

Sequence of animation images.

loop

Whether or not to loop the animation. If false animation will stop after the last key frame is played out. Default value is true.

Attributes

See also
Source
CPAnimation.scala
def previewAnimation(ani: CPAnimation, frameDim: CPDim, emuTerm: Boolean, bg: CPPixel): Unit

Previews given animation.

Previews given animation.

Typically, you would use this method together with image definition. Place this call into @main function to quickly preview the animation by running this function:

object CPCubeAniImage extends CPArrayImage(
   prepSeq(13 * 8,
       """
         |+------+      +------+      +------+      +------+      +------+   +-------+    +------+   +------+
         ||`.    |`.    |\     |\     |      |     /|     /|    .'|    .'|  / |     /|    |      |   |\     |\
         ||  `+--+---+  | +----+-+    +------+    +-+----+ |  +---+--+'  |  +-+----+ |    +------+   | +----+-+
         ||   |  |   |  | |    | |    |      |    | |    | |  |   |  |   |  | |    | |    |      |   | |    | |
         |+---+--+   |  +-+----+ |    +------+    | +----+-+  |   +--+---+  | +----+-+    +------+   +-+----+ |
         | `. |   `. |   \|     \|    |      |    |/     |/   | .'   | .'   |/     |/     |      |    \|     \|
         |   `+------+    +------+    +------+    +------+    +------+'     +------+      +------+     +------+
   """),
   (ch, _, _) => ch&C_WHITE
)

@main def preview(): Unit =
   val ani = CPAnimation.filmStrip(
       "ani",
       200,
       true,
       false,
       CPCubeAniImage.trimBg().split(13, 7)
   )
   CPAnimation.previewAnimation(ani, CPDim(13, 7))
   sys.exit(0)

Value parameters

ani

Animation to preview.

bg

Background pixel. Default value is CPPixel('.', C_GRAY2, C_GRAY1).

emuTerm

Whether to use a terminal emulation. Default value is true.

frameDim

Dimension of the keyframe.

Attributes

See also
Source
CPAnimation.scala
def timeBased(id: String, loop: Boolean, bounce: Boolean, frames: Seq[(CPImage, Long)]): CPAnimation

Creates new time-based animation with given parameters.

Creates new time-based animation with given parameters.

Time-based animation is based on idea that animation is a sequence of image and duration pairs. Playing such animation simply means sequentially playing and image for its specified duration and then switching to the next one and repeating the same process.

Note that unlike discreet graphics based animation the timing tuning of the terminal ASCII-based animation can be tricky. It is often counterintuitive that faster refresh rate produces blurrier animation and the slower timing would sometime yield better result. There is also a significant difference on whether the sprite is moving vertically or horizontally on the terminal screen as well as how much it moves in relation to animation timing. There's also a perceptible difference in how sprite animation is viewed on the built-in terminal emulator and the actual native terminal such as iTerm2 or xterm. Make sure to experiment with timing of your animations!

Value parameters

bounce

If loop is true this defines how animation will loop once it reaches the last key frame: from the beginning or bounce and going backward towards the beginning. Default value is false which will force looping animation to start from the beginning.

frames

Animation images with their corresponding durations in milliseconds.

id

Unique ID of the animation.

loop

Whether or not to loop the animation. If false animation will stop after the last key frame is played out. Default value is true.

Attributes

Returns

Newly created animation.

See also
Source
CPAnimation.scala