An image based on two-dimensional pixel array.
This is the primary tool for creating in-code images. This class has number of constructors and companion utility methods to aid in creating in-code images in variety of ways. Here's a typical example of using this class to create an in-code image. Note the use of companion object function prepSeq():
object CPAlienImage extends CPArrayImage(
prepSeq("""
| . .
| \/
| (@@)
| g/\_)(_/\e
|g/\(=--=)/\e
| //\\
| _| |_
"""),
(ch, _, _) => ch&C_LIME
)
Value parameters
- data
-
Image data. Note that given data array should not have
null
values. - origin
-
The origin of the image like file path or URL.
Attributes
- Companion
- object
- Source
- CPArrayImage.scala
- Graph
-
- Supertypes
- Known subtypes
-
object CPBikingAniImage.typeobject CPBirdAniImage.typeobject CPCubeAniImage.typeobject CPCurveAniImage.typeobject CPDancerAniImage.typeobject CPHandAniImage.typeobject CPLogoCatAniImage.typeobject CPMacarena1AniImage.typeobject CPMacarena2AniImage.typeobject CPMacarena3AniImage.typeobject CPMacarena4AniImage.typeobject CPMacarena5AniImage.typeobject CPPointManAniImage.typeobject CPRunnerAniImage.typeobject CPSomersaultAniImage.typeobject CPSpinningGlobeAniImage.typeobject CPCircle1aImage.typeobject CPCircle1bImage.typeobject CPCircle1cImage.typeobject CPCircle2aImage.typeobject CPCircle2bImage.typeobject CPCircle3Image.typeobject CPCircle4Image.typeobject CPCircle5Image.typeobject CPCircle6Image.typeobject CPCircle9Image.typeobject CPAardvarkImage.typeobject CPAlienImage.typeobject CPAlienPlanetImage.typeobject CPAmigaImage.typeobject CPArrowImage.typeobject CPAstronaut1Image.typeobject CPAstronaut2Image.typeobject CPAtari2080STImage.typeobject CPBananaImage.typeobject CPBatImage.typeobject CPBearImage.typeobject CPBedImage.typeobject CPBeetleImage.typeobject CPBrickNImage.typeobject CPBrickWImage.typeobject CPCactusImage.typeobject CPCalculatorImage.typeobject CPCapsuleImage.typeobject CPCarImage.typeobject CPCastleImage.typeobject CPCloudImage.typeobject CPCrownImage.typeobject CPCubesImage.typeobject CPDogImage.typeobject CPDolphinImage.typeobject CPFlamingoImage.typeobject CPGameBoyImage.typeobject CPGingerbreadImage.typeobject CPGlobeImage.typeobject CPGrimReaperImage.typeobject CPHelicopterImage.typeobject CPIceCreamImage.typeobject CPKnifeImage.typeobject CPLanderImage.typeobject CPMoon1Image.typeobject CPMoon2Image.typeobject CPMotorcycleImage.typeobject CPMouseImage.typeobject CPOceanLinerImage.typeobject CPPlaneImage.typeobject CPRocket1Image.typeobject CPRocket2Image.typeobject CPSatellite1Image.typeobject CPSatellite2Image.typeobject CPSatellite3Image.typeobject CPSaturnImage.typeobject CPShieldImage.typeobject CPSkullImage.typeobject CPSpaceShipImage.typeobject CPSunGlassesImage.typeobject CPSwordImage.typeobject CPTelescopeImage.typeobject CPTntImage.typeobject CPTornadoImage.typeobject CPTruckImage.typeobject CPUmbrellaImage.typeShow all
Members list
Value members
Constructors
Creates an image from 2D array of characters.
Creates an image from 2D array of characters.
Value parameters
- data
-
Image data.
- skin
-
Skinning function. The function takes a character, its X and Y coordinate and returns a new pixel.
Attributes
- Source
- CPArrayImage.scala
Creates an image from the sequence of strings.
Creates an image from the sequence of strings.
Value parameters
- data
-
Image data.
- skin
-
Skinning function. The function takes a character, its X and Y coordinate and returns a new pixel.
Attributes
- Source
- CPArrayImage.scala
Creates an image from a single string.
Creates an image from a single string.
Value parameters
- data
-
Single string image data.
- skin
-
Skinning function. The function takes a character, its X and Y coordinate and returns a new pixel.
Attributes
- Source
- CPArrayImage.scala
Creates a single pixel image.
Creates an image from give 2D array of characters.
Creates an image from give 2D array of characters.
Value parameters
- bg
-
Optional background color for image pixels.
- chArr
-
Image data.
- fg
-
Foreground color of image pixels.
Attributes
- Source
- CPArrayImage.scala
Creates an image from give 2D array of characters without background color.
Creates an image from give 2D array of characters without background color.
Value parameters
- chArr
-
Image data.
- fg
-
Foreground color of image pixels.
Attributes
- Source
- CPArrayImage.scala
Creates an image from give string.
Creates an image from give string.
Value parameters
- bg
-
Optional background color for image pixels.
- data
-
Single string image data.
- fg
-
Foreground color of image pixels.
Attributes
- Source
- CPArrayImage.scala
Creates an image from give string without background color.
Creates an image from give string without background color.
Value parameters
- data
-
Single string image data.
- fg
-
Foreground color of image pixels.
Attributes
- Source
- CPArrayImage.scala
Creates an image from given sequence of pixels.
Creates an image from given sequence of pixels.
Value parameters
- pxs
-
Sequence of pixel to create a new image from.
Attributes
- Source
- CPArrayImage.scala
Concrete methods
Gets internal read-only 2D representation of this image.
Gets image dimension.
Gets pixel at the given XY-coordinate.
Inherited methods
Antialiases solid ASCII art image returning new image. Works only
for solid ASCII art. Algorithm is loosely based on https://codegolf.stackexchange.com/questions/5450/anti-aliasing-ascii-art.
Antialiases solid ASCII art image returning new image. Works only
for solid ASCII art. Algorithm is loosely based on https://codegolf.stackexchange.com/questions/5450/anti-aliasing-ascii-art.
Here's an example of antialiasing a solid ASCII art shape:
xx xxx xxx db <xb <xb
xxxx xxx xxx dxxb Yxb Yxb
xxxxxx xxx xxx dxxxxb Yxb Yxb
xxx xxx xxx xxx dxx xxb xxb xxb
xxxx xxx xxx xxx Yxxb xxF xxF xxF
xxxxxx xxx xxx YxxxxF dxF dxF
xxxx xxx xxx ===> YxxF dxF dxF
x xx xxx xxx x ; YF dxF dxF ;
xx xxx xxx xx xb dxF dxF dx
xxx xxx xxx xxx xxb <xF <xF <xx
xxxx xxx xxx xx xxxb Yxb Yxb Yx
xxxxx xxx xxx x Yxxx> Yx> Yx> V
Value parameters
- isBlank
-
Function to determine if given pixel is blank for the purpose of antialiasing.
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
Makes a deep snapshot copy of the current image.
Makes a deep snapshot copy of the current image.
Value parameters
- skin
-
Optional skin to apply when copying.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Makes a deep snapshot copy of the subregion of the current image.
Makes a deep snapshot copy of the subregion of the current image.
Value parameters
- rect
-
Subregion to copy.
- skin
-
Optional skin to apply when copying.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Compares the receiver object (this
) with the argument object (that
) for equivalence.
Compares the receiver object (this
) with the argument object (that
) for equivalence.
Any implementation of this method should be an equivalence relation:
- It is reflexive: for any instance
x
of typeAny
,x.equals(x)
should returntrue
. - It is symmetric: for any instances
x
andy
of typeAny
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any instances
x
,y
, andz
of typeAny
ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
.
If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode
to ensure that objects which are "equal" (o1.equals(o2)
returns true
) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)
).
Value parameters
- that
-
the object to compare against this object for equality.
Attributes
- Returns
-
true
if the receiver object is equivalent to the argument;false
otherwise. - Definition Classes
-
CPGameObject -> Any
- Inherited from:
- CPGameObject
- Source
- CPGameObject.scala
Tests if there is a pixel in this image for which given predicate would return true
.
Tests if there is a pixel in this image for which given predicate would return true
.
Value parameters
- f
-
Predicate to test.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Loops over the pixels in image.
Loops over the pixels in image.
Value parameters
- f
-
Function to call on each pixel.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Shortcut to get image height.
Gets unique ID of this game object.
Gets unique ID of this game object.
Attributes
- Inherited from:
- CPGameObject
- Source
- CPGameObject.scala
Gets rectangle shape of this image.
Gets optional set of organizational tags. Note that by default the set of tags is empty.
Gets optional set of organizational tags. Note that by default the set of tags is empty.
Attributes
- See also
- Inherited from:
- CPGameObject
- Source
- CPGameObject.scala
Shortcut to get image width.
Shortcut to get image height.
Flips this image horizontally returning a new image. Note that this method does only shallow copy and returned image will delegate to this image. Use copy method to get a full deep copy before calling this method to get a full new image.
Flips this image horizontally returning a new image. Note that this method does only shallow copy and returned image will delegate to this image. Use copy method to get a full deep copy before calling this method to get a full new image.
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
Tests whether this and given images have the same dimensions and the same pixels in corresponding locations.
Tests whether this and given images have the same dimensions and the same pixels in corresponding locations.
Value parameters
- img
-
Image to test.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Loops over the pixels in image. Iteration over the pixels in this image will be horizontal first. In other words, given the pixels with the following coordinates:
Loops over the pixels in image. Iteration over the pixels in this image will be horizontal first. In other words, given the pixels with the following coordinates:
+-----------------+
|(0,0) (1,0) (2,0)|
|(0,1) (1,1) (2,1)|
|(0,2) (1,2) (2,2)|
+-----------------+
this method will iterate in the following order:
(0,0) (1,0) (2,0) (0,1) (1,1) (2,1) (0,2) (1,2) (2,2)
Value parameters
- f
-
Function to call on each pixel. Note that unlike standard foreach function, this function also takes pixel's XY-coordinate.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Loops over the pixels in image. Iteration over the pixels in this image will be horizontal first. In other words, given the pixels with the following coordinates:
Loops over the pixels in image. Iteration over the pixels in this image will be horizontal first. In other words, given the pixels with the following coordinates:
+-----------------+
|(0,0) (1,0) (2,0)|
|(0,1) (1,1) (2,1)|
|(0,2) (1,2) (2,2)|
+-----------------+
this method will iterate in the following order:
(0,0) (1,0) (2,0) (0,1) (1,1) (2,1) (0,2) (1,2) (2,2)
Value parameters
- f
-
Function to call on each pixel. Note that unlike standard foreach function, this function also takes pixel's XY-coordinate.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Loops over the pixels in image. Iteration over the pixels in this image will be vertical first. In other words, given the pixels with the following coordinates:
Loops over the pixels in image. Iteration over the pixels in this image will be vertical first. In other words, given the pixels with the following coordinates:
+-----------------+
|(0,0) (1,0) (2,0)|
|(0,1) (1,1) (2,1)|
|(0,2) (1,2) (2,2)|
+-----------------+
this method will iterate in the following order:
(0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2)
Value parameters
- f
-
Function to call on each pixel. Note that unlike standard foreach function, this function also takes pixel's XY-coordinate.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Detects all background pixels and replaces them with a given pixel returning new image.
Detects all background pixels and replaces them with a given pixel returning new image.
A pixel is considered to be a background pixel when:
- It's satisfies given predicate
- It's not equal to given replacement pixel
- There's a path from it to the edge of the image through background pixels only
For example, a fully enclosed area of the image containing background pixels will NOT be considered a background as there's no path to the edge of the image without crossing a non-background pixels.
Value parameters
- isBgPx
-
Predicate determining if given pixel is a background pixel.
- replacePx
-
Pixel to replace the detected background pixels.
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
Crops and centers the image returning a new image instance. Given dimension can be bigger or smaller.
Crops and centers the image returning a new image instance. Given dimension can be bigger or smaller.
Value parameters
- bgPx
-
Background pixel in case of bigger dimension. Default value is CPPixel.XRAY.
- newDim
-
Dimension to crop by.
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
Crops this image using given insets. Insets can be positive or negative.
Crops this image using given insets. Insets can be positive or negative.
Value parameters
- bgPx
-
Background pixel in case of bigger dimension. Default value is CPPixel.XRAY.
- insets
-
Insets to crop by.
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
Saves this image in REXPaint CSV format.
Saves this image in REXPaint CSV format.
Value parameters
- bg
-
Background color to replace in pixels with no background.
- file
-
File instance.
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
Saves this image in REXPaint CSV format.
Saves this image in REXPaint CSV format.
Value parameters
- bg
-
Background color to replace in pixels with no background.
- path
-
Local file path.
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
Saves this image in REXPaint XP format. Note that this is a native format used by REXPaint and images in this format can be loaded by REXPaint for editing.
Saves this image in REXPaint XP format. Note that this is a native format used by REXPaint and images in this format can be loaded by REXPaint for editing.
Value parameters
- bg
-
Background color to set in pixels that have no background defined.
- file
-
File instance.
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
Saves this image in REXPaint XP format.
Saves this image in REXPaint XP format.
Value parameters
- bg
-
Background color to replace in pixels with no background.
- path
-
Local file path.
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
Saves this image in *.txt
format. Note that this format does not retain the color information.
Saves this image in *.txt
format. Note that this format does not retain the color information.
Value parameters
- path
-
Local file path.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Saves this image in *.txt
format. Note that this format does not retain the color information.
Saves this image in *.txt
format. Note that this format does not retain the color information.
Value parameters
- file
-
File instance.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Creates shallow copy of this image with given skin function. Note that this method will wrap this image and delegate to it instead of creating a full copy of the image. To make a deep copy use copy method.
Creates shallow copy of this image with given skin function. Note that this method will wrap this image and delegate to it instead of creating a full copy of the image. To make a deep copy use copy method.
Value parameters
- f
-
Skinning function. The function takes an existing pixel, its X and Y coordinate and return a new pixel.
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
Splits this image into sequence of [w,h]
images.
Splits this image into sequence of [w,h]
images.
Value parameters
- h
-
Split height.
- w
-
Split width.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Attaches given image underneath this image returning a new combined image.
Attaches given image underneath this image returning a new combined image.
Value parameters
- bgPx
-
Background pixel to use when combined image has large width.
- img
-
Image to attached.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Attaches given image to the right of this image returning a new combined image.
Attaches given image to the right of this image returning a new combined image.
Value parameters
- bgPx
-
Background pixel to use when combined image has large height.
- img
-
Image to attached.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Converts this image into 2D array of pixels.
Converts this image into 2D array of pixels.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Trims blank rows and columns from this image returning a new, trimmed image.
Trims blank rows and columns from this image returning a new, trimmed image.
Value parameters
- isBlank
-
Function to determine if an individual pixel is blank. Row or column is blank if all of its pixels satisfy this predicate.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
A shortcut method that detects background pixels and replaces them with CPPixel.XRAY returning a new image. This effectively makes the background transparent.
A shortcut method that detects background pixels and replaces them with CPPixel.XRAY returning a new image. This effectively makes the background transparent.
This is equivalent to:
replaceBg(isBgPx, CPPixel.XRAY)
Value parameters
- isBgPx
-
Predicate determining if given pixel is a background pixel.
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
A shortcut method that considers all pixels with ' ' (space) character as background pixels and replaces them with CPPixel.XRAY returning a new image. This effectively makes the background transparent.
A shortcut method that considers all pixels with ' ' (space) character as background pixels and replaces them with CPPixel.XRAY returning a new image. This effectively makes the background transparent.
This is equivalent to:
replaceBg(_.char == ' ', CPPixel.XRAY)
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
Flips this image vertically returning a new image. Note that this method does only shallow copy and returned image will delegate to this image. Use copy method to get a full deep copy before calling this method to get a full new image.
Flips this image vertically returning a new image. Note that this method does only shallow copy and returned image will delegate to this image. Use copy method to get a full deep copy before calling this method to get a full new image.
Attributes
- See also
- Inherited from:
- CPImage
- Source
- CPImage.scala
Shortcut to get image width.
Inherited fields
Gets the origin of this asset. Typically, this should be a URL, file name or class name for in-code assets like array images, animations or system font.
Gets the origin of this asset. Typically, this should be a URL, file name or class name for in-code assets like array images, animations or system font.
Attributes
- Inherited from:
- CPImage
- Source
- CPImage.scala
Returns a string representation of the object.
Returns a string representation of the object.
The default representation is platform dependent.
Attributes
- Returns
-
a string representation of the object.
- Inherited from:
- CPImage
- Source
- CPImage.scala