org.cosplay.prefabs.shaders

Members list

Concise view

Type members

Classlikes

class CPBeatShader(snd: Option[CPSound], smoothing: CPBeatShaderSmoothing, thresholdGain: Float, thresholdTailMs: Int) extends CPShader

A shader that changes brightness of its object based on the perceived beat of the given sound. This shader uses a simple beat-detection algorithm based on calculating root mean square (RMS) of amplitudes across all channels. RMS is constantly recalculated over a sliding window of the past few seconds. If the current amplitude value is above the RMS the beat is detected.

A shader that changes brightness of its object based on the perceived beat of the given sound. This shader uses a simple beat-detection algorithm based on calculating root mean square (RMS) of amplitudes across all channels. RMS is constantly recalculated over a sliding window of the past few seconds. If the current amplitude value is above the RMS the beat is detected.

It is important to note that this shader does not work by default for all types of sounds. For each particular sound profile you may need to "play" with smoothing and threshold gain to achieve the best visual effect.

Note that by default this shader is inactive and user must call start method to start this shader.

Attributes

smoothing

Smoothing mode. Default value is SMOOTH_UP.

snd

Sound asset to analyze for the beat detection. Note that the start of playing this sound should generally be synchronized in time with calling start method on this shader. If not provided - ensure that method setSound is called before this shader is started.

thresholdGain

A constant that can be used to fine tune the calculated RMS-based threshold. Once threshold is calculated it will be multiplied by this constant. Default value is 1.0f. Typical fine tuning values are between 0.5f and 0.9f.

thresholdTailMs

Duration of the sliding window in milliseconds that is used for calculating RMS-based threshold.

Source:
CPBeatShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any

Smoothing modes for the beat shader.

Smoothing modes for the beat shader.

Attributes

Source:
CPBeatShader.scala
Graph
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
class CPBorderShader(entireFrame: Boolean, width: Int, compensateWidth: Boolean, colorMixPerStep: Float, autoStart: Boolean) extends CPShader

Border shade shader.

Border shade shader.

This shader creates a gradually shaded border by dimming the background color of the pixels closer to the border of the frame or object.

Attributes

autoStart

Whether to start shader right away. Default value is false.

colorMixPerStep

Float value in [0,1] range indicating the color change per each step in the border.

compensateWidth

Whether or not to compensate for non-square form of the character "pixel". If true then for each horizontal line there will be 2 vertical lines giving the visual effect of the both horizontal and vertical border lines having the same width.

entireFrame

Whether apply to the entire camera frame or just the object this shader is attached to.

width

How many lines (vertical and horizontal) the shaded border width will be.

See also:
Example:

See CPBirdGame class for the example of using this shader.

See CPShaderExample class for the example of using shaders.

Source:
CPBorderShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any
class CPFadeInShader(entireFrame: Boolean, durMs: Long, bgPx: CPPixel, onFinish: CPSceneObjectContext => Unit, autoStart: Boolean, skip: (CPZPixel, Int, Int) => Boolean, balance: (Int, Int) => Float) extends CPShader

Fade in shader.

Fade in shader.

This shader can be used for 'fade in' effect for the entire camera frame or the individual scene object it is attached to. If used for entire camera frame effect it can be attached to an off-screen sprite.

Attributes

autoStart

Whether to start shader right away. Default value is true.

balance

A function that produces value in [0, 1] range that is used in color mixture. Value 0 means that the color will be 100% background, value 1 means that the color will be 100% the actual pixel color, value 0.5 means that the color will be a 50% mix between the background and the actual pixel color. The function takes two parameters: first is a current frame number since the start of the effect, and the second parameter is the last frame number of the effect. First parameter is always less then the second one. By default, the the (a, b) => a.toFloat / b function is used that gives gradual color transition through the frames range. Another popular function to use here is a sigmoid function: (a, b) => sigmoid.value(a - b / 2).toFloat() that gives a different visual effect.

bgPx

Background pixel to fade in from. Background pixel don't participate in shader effect.

durMs

Duration of the fade in effect in milliseconds.

entireFrame

Whether apply this shader to the entire camera frame or just the object this shader is attached to.

onFinish

Optional callback to call when this shader finishes. Default is a no-op.

skip

Predicate allowing to skip certain pixel from the shader. Predicate takes a pixel (with its Z-order), and X and Y-coordinate of that pixel. Note that XY-coordinates are always in relation to the entire canvas. Typically used to skip background or certain Z-index. Default predicate returns false for all pixels.

See also:
Example:

See CPShaderExample class for the example of using shaders.

Source:
CPFadeInShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any
class CPFadeOutShader(entireFrame: Boolean, durMs: Long, bgPx: CPPixel, onFinish: CPSceneObjectContext => Unit, autoStart: Boolean, skip: (CPZPixel, Int, Int) => Boolean, balance: (Int, Int) => Float) extends CPShader

Fade out shader.

Fade out shader.

This shader can be used for 'fade out' effect for the entire camera frame or the individual scene object it is attached to. If used for entire camera frame effect it can be attached to an off-screen sprite.

Attributes

autoStart

Whether to start shader right away. Default value is false.

balance

A function that produces value in [0, 1] range that is used in color mixture. Value 0 means that the color will be 100% background, value 1 means that the color will be 100% the actual pixel color, value 0.5 means that the color will be a 50% mix between the background and the actual pixel color. The function takes two parameters: first is a current frame number since the start of the effect, and the second parameter is the last frame number of the effect. First parameter is always less then the second one. By default, the the (a, b) => a.toFloat / b function is used that gives gradual color transition through the frames range. Another popular function to use here is a sigmoid function: (a, b) => sigmoid.value(a - b / 2).toFloat() that gives a different visual effect.

bgPx

Background pixel to fade out to. Background pixel don't participate in shader effect.

durMs

Duration of the fade out effect in milliseconds.

entireFrame

Whether apply to the entire camera frame or just the object this shader is attached to.

onFinish

Optional callback to call when this shader finishes. Default is a no-op.

skip

Predicate allowing to skip certain pixel from the shader. Predicate takes a pixel (with its Z-order), and X and Y-coordinate of that pixel. Note that XY-coordinates are always in relation to the entire canvas. Typically used to skip background or certain Z-index. Default predicate returns false for all pixels.

See also:
Example:

See CPShaderExample class for the example of using shaders.

Source:
CPFadeOutShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any
class CPFlashlightShader(radius: Int, autoStart: Boolean, skip: (CPZPixel, Int, Int) => Boolean) extends CPShader

Circular flashlight effect shader.

Circular flashlight effect shader.

This shader can be used to create a circular flashlight effect around the object. It renders its effect only for a scene object this shader is attached to (i.e. it does not work for entire screen).

Attributes

autoStart

Whether or not to toggle on the shader effect automatically. Default value is false.

radius

Radius of circular flashlight effect.

skip

Predicate allowing to skip certain pixel from the shader. Predicate takes a pixel (with its Z-order), and X and Y-coordinate of that pixel. Note that XY-coordinates are always in relation to the entire canvas. Typically used to skip background or certain Z-index. Default predicate returns false for all pixels.

See also:
Example:

See CPShaderExample class for the example of using shaders.

Source:
CPFlashlightShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any
class CPRandomFadeInShader(entireFrame: Boolean, durMs: Long, bgPx: CPPixel, onFinish: CPSceneObjectContext => Unit, keyFrame: Int, autoStart: Boolean, skipSpaces: Boolean, skip: (CPZPixel, Int, Int) => Boolean, balance: (Int, Int) => Float) extends CPShader

Fade in shader that uses random characters during fade in.

Fade in shader that uses random characters during fade in.

This shader can be used for 'fade in' effect for the entire camera frame or the individual scene object it is attached to. If used for entire camera frame effect it can be attached to an off-screen sprite.

Attributes

autoStart

Whether to start shader right away. Default value is true.

balance

A function that produces value in [0, 1] range that is used in color mixture. Value 0 means that the color will be 100% background, value 1 means that the color will be 100% the actual pixel color, value 0.5 means that the color will be a 50% mix between the background and the actual pixel color. The function takes two parameters: first is a current frame number since the start of the effect, and the second parameter is the last frame number of the effect. First parameter is always less then the second one. By default, the the (a, b) => a.toFloat / b function is used that gives gradual color transition through the frames range. Another popular function to use here is a sigmoid function: (a, b) => sigmoid.value(a - b / 2).toFloat() that gives a different visual effect.

bgPx

Background pixel to fade in from. Background pixel don't participate in shader effect.

durMs

Duration of the fade in effect in milliseconds.

entireFrame

Whether apply to the entire camera frame or just the object this shader is attached to.

keyFrame

nth-frame to render the effect. For example, if key frame is 3 than the effect will change on each 3rd frame and remain the same on all subsequent frames until next key frame is reached.

onFinish

Optional callback to call when this shader finishes. Default is a no-op.

skip

Predicate allowing to skip certain pixel from the shader. Predicate takes a pixel (with its Z-order), and X and Y-coordinate of that pixel. Note that XY-coordinates are always in relation to the entire canvas. Typically used to skip background or certain Z-index. Default predicate returns false for all pixels.

skipSpaces

Whether or not to skip space characters from the shader effect. Default value is false.

See also:
Example:

See CPShaderExample class for the example of using shaders.

See org.cosplay.examples.image.CPImageFormatsExample example that uses this shader.

Source:
CPRandomFadeInShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any
class CPShimmerShader(entireFrame: Boolean, colors: Seq[CPColor], keyFrame: Int, autoStart: Boolean, skip: (CPZPixel, Int, Int) => Boolean, durMs: Long, onDuration: CPSceneObjectContext => Unit) extends CPShader

Color shimmer shader.

Color shimmer shader.

This shader provides color shimmer effect for the entire camera frame or the individual scene object it is attached to. Shimmering consists of randomly changing a color of the pixel for a small period of time. If used for entire camera frame effect it can be attached to an off-screen sprite. Note that unlike CPSparkleShader that provides similar effect but with gradual dimming and brightening of color, the shimmer effect employs random color selection from the given set of colors.

Attributes

autoStart

Whether to start shader right away. Default value is false.

colors

Sequence of colors to use for shimmering effect. Colors will be selected randomly from this set.

durMs

Duration of the effect in milliseconds. By default, the effect will go forever.

entireFrame

Whether apply to the entire camera frame or just the object this shader is attached to.

keyFrame

nth-frame to render the effect. For example, if key frame is 5 than the colors will change on each 5th frame and remain the same on all subsequent frames until next key frame is reached.

onDuration

Optional callback to call when this shader finishes by exceeding the duration specified by durMs parameter. Default is a no-op.

skip

Predicate allowing to skip certain pixel from the shader. Predicate takes a pixel (with its Z-order), and X and Y-coordinate of that pixel. Note that XY-coordinates are always in relation to the entire canvas. Typically used to skip background or certain Z-index. Default predicate returns false for all pixels.

See also:
Example:

See CPShaderExample class for the example of using shaders.

Source:
CPShimmerShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any

Direction of the slide effect produced by CPSlideInShader and CPSlideOutShader shaders.

Direction of the slide effect produced by CPSlideInShader and CPSlideOutShader shaders.

Attributes

See also:
Companion:
object
Source:
CPSlideDirection.scala
Graph
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any

Attributes

Companion:
enum
Source:
CPSlideDirection.scala
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
class CPSlideInShader(dir: CPSlideDirection, entireFrame: Boolean, durMs: Long, bgPx: CPPixel, onFinish: CPSceneObjectContext => Unit, autoStart: Boolean, skip: (CPZPixel, Int, Int) => Boolean, balance: (Int, Int) => Float) extends CPShader

Slide in shader.

Slide in shader.

This shader can be used for 'slide in' or the directional gradual reveal effect for the entire camera frame or the individual scene object it is attached to. If used for entire camera frame effect it can be attached to an off-screen sprite.

Attributes

autoStart

Whether to start shader right away. Default value is true.

balance

A function that produces value in [0, 1] range that is used in color mixture. Value 0 means that the color will be 100% background, value 1 means that the color will be 100% the actual pixel color, value 0.5 means that the color will be a 50% mix between the background and the actual pixel color. The function takes two parameters: first is a current frame number since the start of the effect, and the second parameter is the last frame number of the effect. First parameter is always less then the second one. By default, the the (a, b) => a.toFloat / b function is used that gives gradual color transition through the frames range. Another popular function to use here is a sigmoid function: (a, b) => sigmoid.value(a - b / 2).toFloat that gives a different visual effect.

bgPx

Background pixel to fade in from.

dir

Slide direction as defined by CPSlideDirection.

durMs

Duration of the effect in milliseconds.

entireFrame

Whether apply to the entire camera frame or just the object this shader is attached to.

onFinish

Optional callback to call when this shader finishes. Default is a no-op.

skip

Predicate allowing to skip certain pixel from the shader. Predicate takes a pixel (with its Z-order), and X and Y-coordinate of that pixel. Note that XY-coordinates are always in relation to the entire canvas. Typically used to skip background or certain Z-index. Default predicate returns false for all pixels.

See also:
Example:

See CPShaderExample class for the example of using shaders.

Companion:
object
Source:
CPSlideInShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any

Companion object with utility methods.

Companion object with utility methods.

Attributes

Companion:
class
Source:
CPSlideInShader.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
class CPSlideOutShader(dir: CPSlideDirection, entireFrame: Boolean, durMs: Long, bgPx: CPPixel, onFinish: CPSceneObjectContext => Unit, autoStart: Boolean, skip: (CPZPixel, Int, Int) => Boolean, balance: (Int, Int) => Float) extends CPShader

Slide out shader.

Slide out shader.

This shader can be used for 'slide out' or the directional gradual hide effect for the entire camera frame or the individual scene object it is attached to. If used for entire camera frame effect it can be attached to an off-screen sprite.

Attributes

autoStart

Whether to start shader right away. Default value is false.

balance

A function that produces value in [0, 1] range that is used in color mixture. Value 0 means that the color will be 100% background, value 1 means that the color will be 100% the actual pixel color, value 0.5 means that the color will be a 50% mix between the background and the actual pixel color. The function takes two parameters: first is a current frame number since the start of the effect, and the second parameter is the last frame number of the effect. First parameter is always less then the second one. By default, the the (a, b) => a.toFloat / b function is used that gives gradual color transition through the frames range. Another popular function to use here is a sigmoid function: (a, b) => sigmoid.value(a - b / 2).toFloat that gives a different visual effect.

bgPx

Background pixel to fade out to.

dir

Slide direction as defined by CPSlideDirection.

durMs

Duration of the effect in milliseconds.

entireFrame

Whether apply to the entire camera frame or just the object this shader is attached to.

onFinish

Optional callback to call when this shader finishes. Default is a no-op.

skip

Predicate allowing to skip certain pixel from the shader. Predicate takes a pixel (with its Z-order), and X and Y-coordinate of that pixel. Note that XY-coordinates are always in relation to the entire canvas. Typically used to skip background or certain Z-index. Default predicate returns false for all pixels.

See also:
Example:

See CPShaderExample class for the example of using shaders.

Companion:
object
Source:
CPSlideOutShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any

Companion object with utility methods.

Companion object with utility methods.

Attributes

Companion:
class
Source:
CPSlideOutShader.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
class CPSparkleShader(entireFrame: Boolean, colors: Seq[CPColor], ratio: Float, steps: Int, autoStart: Boolean, skip: (CPZPixel, Int, Int) => Boolean, durMs: Long, onDuration: CPSceneObjectContext => Unit) extends CPShader

Color sparkle shader.

Color sparkle shader.

This shader provides color sparkle effect for the entire camera frame. Sparkling consists of picking number of random pixels on the frame and gradually dimming and brightening their colors creating a sparkling effect. Not that unlike CPShimmerShader that produces a random color changes, this shader relies on smooth gradual dimming and brightening. Both effects are visually similar but work differently.

Attributes

autoStart

Whether to start shader right away. Default value is false.

colors

Set of color to use for sparking effect. Colors will be randomly chosen for each pixel.

durMs

Duration of the effect in milliseconds. By default, the effect will go forever.

entireFrame

Whether apply to the entire camera frame or just the object this shader is attached to.

onDuration

Optional callback to call when this shader finishes by exceeding the duration specified by durMs parameter. Default is a no-op.

ratio

Percentage of pixels to sparkle at the same time. Default value is 0.04, i.e. 4%. For example, if the camera frame size is 100x50 characters then the default 4% ratio will result in 200 pixels sparkling at any given time.

skip

Predicate allowing to skip certain pixel from the shader. Predicate takes a pixel (with its Z-order), and X and Y-coordinate of that pixel. Note that XY-coordinates are always in relation to the entire canvas. Typically used to skip background or certain Z-index. Default predicate returns false for all pixels.

steps

Number of frames that it takes for entire sparkle cycle from brightening to dimming back.

See also:
Example:

See CPShaderExample class for the example of using shaders.

See org.cosplay.games.pong.CPPongTitleScene game scene for example of using this shader.

Source:
CPSparkleShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any
case class CPStarStreak(ch: Char, colors: Seq[CPColor], ratio: Float, steps: Int, speed: (Float, Float), z: Int)

An individual streak descriptor used by CPStarStreakShader.

An individual streak descriptor used by CPStarStreakShader.

Attributes

ch

Character to use to draw stars in this streak.

colors

Set of initial color for fading from. Colors will be randomly chosen for each star.

ratio

Percentage of stars visible at the same time. For example, the value of 0.04 means 4%, and if the camera frame size is 100x50 characters then 4% ratio will result in 200 stars showing at any given time.

speed

Tuple defining the X and Y-axis increment on each frame. This tuples defines both the speed and the direction stars in this streak will move with.

steps

Number of frames that it takes for entire star lifecycle in this streak.

z

Z-index at which to draw the stars in this streak.

See also:
Example:

See CPShaderExample class for the example of using shaders.

See org.cosplay.games.snake.CPSnakeTitleScene game scene for example of using this shader.

Source:
CPStarStreakShader.scala
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
class CPStarStreakShader(entireFrame: Boolean, bg: CPColor, streaks: Seq[CPStarStreak], autoStart: Boolean, skip: (CPZPixel, Int, Int) => Boolean, durMs: Long, onDuration: CPSceneObjectContext => Unit) extends CPShader

Star streak shader.

Star streak shader.

This shader produces a star streak effect with one or more streaks. Each streak defined by CPStarStreak class provides unique configuration for the set of stars: its character to render with, number of stars relative to the size of the current canvas, colors to use for fading, its lifetime, speed and direction to move and z-index. Each such set of stars can "streak" differently, e.g. providing parallax effect.

For example, here's an example of using this shader in the built-in Snake game for parallax starry skies effect on its title scene:

private val starStreakShdr = CPStarStreakShader(
   true,
   BG_PX.bg.get,
    Seq(
        CPStarStreak('.', CS, 0.025, 30, (-.5f, 0f), 0),
        CPStarStreak('.', CS, 0.015, 25, (-1.5f, 0f), 0),
        CPStarStreak('_', CS, 0.005, 20, (-2.0f, 0f), 0)
    ),
    skip = (zpx, _, _) => zpx.z == 1
)

Attributes

autoStart

Whether to start shader right away. Default value is false.

bg

Background color to fade into.

durMs

Duration of the effect in milliseconds. By default, the effect will go forever.

entireFrame

Whether apply to the entire camera frame or just the object this shader is attached to.

onDuration

Optional callback to call when this shader finishes by exceeding the duration specified by durMs parameter. Default is a no-op.

skip

Predicate allowing to skip certain pixel from the shader. Predicate takes a pixel (with its Z-order), and X and Y-coordinate of that pixel. Note that XY-coordinates are always in relation to the entire canvas. Typically used to skip background or certain Z-index. Default predicate returns false for all pixels.

See also:
Example:

See CPShaderExample class for the example of using shaders.

See org.cosplay.games.snake.CPSnakeTitleScene game scene for example of using this shader.

Source:
CPStarStreakShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any