CPCanvas

org.cosplay.CPCanvas
See theCPCanvas companion object
class CPCanvas(pane: CPZPixelPane, clip: CPRect)

2D rendering pane. Canvas is synonymous with screen, i.e. it is an object that allows to draw on the screen. Canvas has the dimension of the current scene or, if scene doesn't provide its own dimension, the size of the terminal. Note that this behavior means that canvas can change its size from frame to frame if the current scene does not provide its own dimension and the terminal size is changing. One can generally draw outside of canvas dimensions and any such pixels will be simply ignored.

For each game frame, the game engine creates a new empty canvas for all scene objects to draw on with the dimension set as described above. This canvas is available to scene objects via CPSceneObjectContext.getCanvas method. Game engine then compares previous canvas and this one to determine which areas of the terminal need redrawing.

You can also create the canvas object outside game loop using companion object methods. Such "off-line" canvas is convenient when one needs to draw something off the screen and then capture that drawing as an image, for example, during scene initialization out of the game loop.

Canvas (0,0) coordinate point is located in the top left corner. X-axis goes to the right and Y-axis points down. Every drawn pixel on the canvas also has a Z-index or depth. Pixel with larger or equal Z-index visually overrides the pixel with the smaller Z-index. Pixels with coordinates outside of the current canvas dimensions are ignored.

ASCII-based graphics are vastly different from the traditional raster-based graphics. Since ASCII-based drawing uses printable characters from ASCII character set that are displayed on basic text terminal most differences are obvious but some are more subtle and unexpected. For example, while straight vertical and horizontal lines are easy to implement many curved lines are much trickier to draw. Specifically, circles and ellipses, for example, are hard to do properly in automated way. Moreover, many complex curves need to be done manually, especially if they are dynamically redrawn on each frame update.

This class provides many methods for basic line and rectangular drawing, circle and polyline, anti-aliasing, "color" fill in, and much more. Most functions have multiple overridden variants with different parameters so that they can be easily used in different contexts. Note also that this class deals primarily with line ASCII art and has only few functions like antialiasing for the solid ASCII art.

One of the useful techniques of obtaining a complex "drawn-on-canvas" images is to create a new canvas object at the scene's start (see CPLifecycle.onStart method), draw all necessary ASCII art on it and then capture the image using one of the capture() methods in this class. Once image is obtained you can use it with any image-based sprites to display it.

There are many online tutorials for ASCII art that are highly recommended, including from:

See also the following resources for general ASCII art collections:

Value parameters

clip

Clipping region.

pane

Underlying z-pane.

Attributes

See also
Example

See CPCanvasExample class for the example of using canvas.

Companion
object
Source
CPCanvas.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def antialias(x: Int, y: Int, dim: CPDim, isBlank: CPPixel => Boolean): Unit

Antialiases solid ascii-art canvas region. Works only for solid ascii-art.

Antialiases solid ascii-art canvas region. Works only for solid ascii-art.

The antialiasing algorithm is based on implementation described at https://codegolf.stackexchange.com/questions/5450/anti-aliasing-ascii-art

Value parameters

dim

Dimension of the region.

isBlank

Predicate defining whether a particular pixel should be considered as a blank.

x

X-coordinate of the top level corner of the region.

y

Y-coordinate of the top level corner of the region.

Attributes

Source
CPCanvas.scala
def antialias(rect: CPRect, isBlank: CPPixel => Boolean): Unit

Antialiases solid ASCII-art canvas region. Works only for solid ASCII-art.

Antialiases solid ASCII-art canvas region. Works only for solid ASCII-art.

The antialiasing algorithm is based on implementation described at https://codegolf.stackexchange.com/questions/5450/anti-aliasing-ascii-art

Value parameters

isBlank

Predicate defining whether a particular pixel should be considered as a blank.

rect

Region to antialias.

Attributes

Source
CPCanvas.scala
def antialias(x1: Int, y1: Int, x2: Int, y2: Int, isBlank: CPPixel => Boolean): Unit

Antialiasing solid ASCII-art canvas region. Works only for solid ASCII-art.

Antialiasing solid ASCII-art canvas region. Works only for solid ASCII-art.

The antialiasing algorithm is based on implementation described at https://codegolf.stackexchange.com/questions/5450/anti-aliasing-ascii-art

Value parameters

isBlank

Predicate defining whether a particular pixel should be considered as a blank.

x1

X-coordinate of the top left corner for the region.

x2

X-coordinate of the bottom right corner for the region.

y1

Y-coordinate of the top left corner for the region.

y2

Y-coordinate of the bottom right corner for the region.

Attributes

Source
CPCanvas.scala
def artLinePixels(ax: Int, ay: Int, bx: Int, by: Int, z: Int, pxf: CPPosPixel => CPPixel, style: ArtLineStyle): ArrayBuffer[CPPosPixel]

Gets a mutable array of pixels representing the art line.

Gets a mutable array of pixels representing the art line.

Art-style drawings use characters from the "`'.,/\|_- character set (unless modified by pixel producing function whenever it is available as a parameter). Art-style drawing typically provide smoother gradients for curved lines. ART_BLOCK style uses only |\/_ characters while ART_SMOOTH uses all of the "'.`,/\|_- characters. ART_SMOOTH style is less performant then ART_BLOCK.

The following illustrates the difference between non-art and art-style drawings using a line vector example:

   non-art         ART_BLOCK        ART_SMOOTH
+------------+  +-------------+  +-------------+
|      ***** |  |        ____ |  |        ____ |
|    **      |  |    ___/     |  |    _,-'     |
| ***        |  | __/         |  | ,-'         |
+------------+  +-------------+  +-------------+

Value parameters

ax

X-coordinate of the start point.

ay

Y-coordinate of the start point.

bx

X-coordinate of the end point.

by

Y-coordinate of the end point.

pxf

Pixel producing function.

style

Art style. The default value is ART_BLOCK.

z

Z-index of the drawing. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def capture(x1: Int, y1: Int, x2: Int, y2: Int): CPImage

Captures given rectangular canvas region as an image. This method will capture only "visible" image of the given region.

Captures given rectangular canvas region as an image. This method will capture only "visible" image of the given region.

Value parameters

x1

X-coordinate of the top left corner of the region.

x2

X-coordinate of the bottom right corner of the region.

y1

Y-coordinate of the top left corner of the region.

y2

Y-coordinate of the bottom right corner of the region.

Attributes

Source
CPCanvas.scala
def capture(x1: Int, y1: Int, dim: CPDim): CPImage

Captures given rectangular canvas region as an image. This method will capture only "visible" image of the given region.

Captures given rectangular canvas region as an image. This method will capture only "visible" image of the given region.

Value parameters

x1

X-coordinate of the top left corner of the region.

y1

Y-coordinate of the top left corner of the region.

Attributes

Source
CPCanvas.scala
def capture(rect: CPRect): CPImage

Captures given rectangular canvas region as an image. This method will capture only "visible" image of the given region.

Captures given rectangular canvas region as an image. This method will capture only "visible" image of the given region.

Value parameters

rect

Rectangular region to capture.

Attributes

Source
CPCanvas.scala
def capture(): CPImage

Captures entire canvas as an image. This method will capture only "visible" image of the given region.

Captures entire canvas as an image. This method will capture only "visible" image of the given region.

Attributes

Source
CPCanvas.scala
def capture(x1: Int, y1: Int, x2: Int, y2: Int, zdx: Int*): CPImage

Captures given rectangular canvas region as an image. This method will capture only specified Z-index layers replacing pixels on other layers with CPPixel.XRAY in the resulting image.

Captures given rectangular canvas region as an image. This method will capture only specified Z-index layers replacing pixels on other layers with CPPixel.XRAY in the resulting image.

Value parameters

x1

X-coordinate of the top left corner of the region.

x2

X-coordinate of the bottom right corner of the region.

y1

Y-coordinate of the top left corner of the region.

y2

Y-coordinate of the bottom right corner of the region.

zdx

Z-indexes to capture.

Attributes

Source
CPCanvas.scala
def capture(x1: Int, y1: Int, dim: CPDim, zdx: Int*): CPImage

Captures given rectangular canvas region as an image. This method will capture only specified z-index layers replacing pixels on other layers with CPPixel.XRAY in the resulting image.

Captures given rectangular canvas region as an image. This method will capture only specified z-index layers replacing pixels on other layers with CPPixel.XRAY in the resulting image.

Value parameters

dim

Dimension of the region to capture.

x1

X-coordinate of the top left corner of the region.

y1

Y-coordinate of the top left corner of the region.

zdx

Z-indexes to capture.

Attributes

Source
CPCanvas.scala
def capture(rect: CPRect, zdx: Int*): CPImage

Captures given rectangular canvas region as an image. This method will capture only specified z-index layers replacing pixels on other layers with CPPixel.XRAY in the resulting image.

Captures given rectangular canvas region as an image. This method will capture only specified z-index layers replacing pixels on other layers with CPPixel.XRAY in the resulting image.

Value parameters

rect

Rectangular region to capture.

zdx

Z-indexes to capture.

Attributes

Source
CPCanvas.scala
def circlePixels(x: Int, y: Int, radius: Int, xFactor: Float, yFactor: Float, densFactor: Float, fillGaps: Boolean, pxf: (Int, Int) => CPPixel): ArrayBuffer[CPPosPixel]

Produces mutable array of pixels representing the circle.

Produces mutable array of pixels representing the circle.

Value parameters

densFactor

Density factor defines "granularity" of drawing. Values below 1.0 allow to compensate for discreetness of ASCII graphics. Typically, value of 0.5 is a good default.

fillGaps

Whether or not to fill potential gaps in circle drawing. Filling the gaps slows down the drawing but produces a better looking circle.

pxf

Pixel producer function.

radius

Radius of the circle in characters.

x

X-coordinate of the circle center.

xFactor

Horizontal squishing factor. Values below 1.0 will squish the circle horizontally. Values above 1.0 will stretch the circle horizontally. X-factor of 2.0 and Y-factor of 1.0 typically produce correct circle using 1x2 monospace font.

y

Y-coordinate of the circle center.

yFactor

Vertical squishing factor. Values below 1.0 will squish the circle vertically. Values above 1.0 will stretch the circle vertically. X-factor of 2.0 and Y-factor of 1.0 typically produce correct circle using 1x2 monospace font.

z

Z-index of the drawing. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def copyRect(x1: Int, y1: Int, x2: Int, y2: Int, destX: Int, destY: Int): Unit

Copies one rectangular areas in this canvas to another location in the same canvas.

Copies one rectangular areas in this canvas to another location in the same canvas.

Value parameters

destX

New X-coordinate of the top left corner.

destY

New Y-coordinate of the top left corner.

x1

X-coordinate of the top left corner of the area to copy.

x2

X-coordinate of the bottom right corner of the area to copy.

y1

Y-coordinate of the top left corner of the area to copy.

y2

Y-coordinate of the bottom right corner of the area to copy.

Attributes

Source
CPCanvas.scala
def copyRect(x1: Int, y1: Int, dim: CPDim, destX: Int, destY: Int): Unit

Copies one rectangular areas in this canvas to another location in the same canvas.

Copies one rectangular areas in this canvas to another location in the same canvas.

Value parameters

destX

New X-coordinate of the top left corner.

destY

New Y-coordinate of the top left corner.

dim

Dimension of the area to copy.

x1

X-coordinate of the top left corner of the area to copy.

y1

Y-coordinate of the top left corner of the area to copy.

Attributes

Source
CPCanvas.scala
def copyRect(rect: CPRect, destX: Int, destY: Int): Unit

Copies one rectangular areas in this canvas to another location in the same canvas.

Copies one rectangular areas in this canvas to another location in the same canvas.

Value parameters

destX

New X-coordinate of the top left corner.

destY

New Y-coordinate of the top left corner.

rect

Rectangular shape to copy.

Attributes

Source
CPCanvas.scala
def drawArtLine(ax: Int, ay: Int, bx: Int, by: Int, z: Int, pxf: CPPosPixel => CPPixel, style: ArtLineStyle): Unit

Draws an art line.

Draws an art line.

Art-style drawings use characters from the "`'.,/\|_- character set (unless modified by pixel producing function whenever it is available as a parameter). Art-style drawing typically provide smoother gradients for curved lines. ART_BLOCK style uses only |\/_ characters while ART_SMOOTH uses all of the "'.`,/\|_- characters. ART_SMOOTH style is less performant then ART_BLOCK.

The following illustrates the difference between non-art and art-style drawings using a line vector example:

   non-art         ART_BLOCK        ART_SMOOTH
+------------+  +-------------+  +-------------+
|      ***** |  |        ____ |  |        ____ |
|    **      |  |    ___/     |  |    _,-'     |
| ***        |  | __/         |  | ,-'         |
+------------+  +-------------+  +-------------+

Value parameters

ax

X-coordinate of the start point.

ay

Y-coordinate of the start point.

bx

X-coordinate of the end point.

by

Y-coordinate of the end point.

pxf

Pixel producing function.

style

Art style to use. Default value is ART_BLOCK.

z

Z-index of the drawing. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawArtPolyline(pts: Seq[(Int, Int)], z: Int, pxf: CPPosPixel => CPPixel, style: ArtLineStyle): Unit

Draws an art-style polyline.

Draws an art-style polyline.

Art-style drawings use characters from the "`'.,/\|_- character set (unless modified by pixel producing function whenever it is available as a parameter). Art-style drawing typically provide smoother gradients for curved lines. ART_BLOCK style uses only |\/_ characters while ART_SMOOTH uses all of the "'.`,/\|_- characters. ART_SMOOTH style is less performant then ART_BLOCK.

The following illustrates the difference between non-art and art-style drawings using a line vector example:

   non-art         ART_BLOCK        ART_SMOOTH
+------------+  +-------------+  +-------------+
|      ****  |  |        ___  |  |        ___  |
|    **      |  |    ___/     |  |    _,-'     |
| ***        |  | __/         |  | ,-'         |
+------------+  +-------------+  +-------------+

Value parameters

pts

Points of the polyline.

pxf

Pixel producing function.

style

Art style to use. Default value is ART_BLOCK.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawArtVector(x: Int, y: Int, deg: Float, len: Int, z: Int, xFactor: Float, yFactor: Float, pxf: CPPosPixel => CPPixel, style: ArtLineStyle): Unit

Draws art-style vector.

Draws art-style vector.

Art-style drawings use characters from the "`'.,/\|_- character set (unless modified by pixel producing function whenever it is available as a parameter). Art-style drawing typically provide smoother gradients for curved lines. ART_BLOCK style uses only |\/_ characters while ART_SMOOTH uses all of the "'.`,/\|_- characters. ART_SMOOTH style is less performant then ART_BLOCK.

The following illustrates the difference between non-art and art-style drawings using a line vector example:

   non-art         ART_BLOCK        ART_SMOOTH
+------------+  +-------------+  +-------------+
|      ***** |  |        ____ |  |        ____ |
|    **      |  |    ___/     |  |    _,-'     |
| ***        |  | __/         |  | ,-'         |
+------------+  +-------------+  +-------------+

Value parameters

deg

Angle of vector in degrees [0..360].

len

Length of the vector.

pxf

Pixel producer function.

style

Art-style to draw the vector with. Default is ART_BLOCK.

x

X-coordinate of the start point.

xFactor

Horizontal squishing factor. Values below 1.0 will squish the vector horizontally. Values above 1.0 will stretch the vector horizontally.

y

Y-coordinate of the start point.

yFactor

Vertical squishing factor. Values below 1.0 will squish the vector vertically. Values above 1.0 will stretch the vector vertically.

z

Z-index of the drawn vector. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawBorder(x1: Int, y1: Int, x2: Int, y2: Int, z: Int, top: CPPixel, leftTop: CPPixel, left: CPPixel, leftBottom: CPPixel, bottom: CPPixel, rightBottom: CPPixel, right: CPPixel, rightTop: CPPixel, title: Seq[CPPixel], titleX: Int, titleY: Int, skin: (Int, Int, CPPixel) => CPPixel): Unit

Draws a border.

Draws a border.

Value parameters

bottom

Bottom size pixel.

left

Left side pixel.

leftBottom

Left bottom corner pixel.

leftTop

Left top corner pixel.

right

Right side line pixel.

rightBottom

Right bottom corner pixel.

rightTop

Right top corner pixel.

skin

Skin function that takes global X and Y coordinates as well as default pixel at that location and returns the skinned pixel.

title

Title of the border. Default is no border.

titleX

X-coordinate of the title. Default is -1.

titleY

Y-coordinate of the title. Default is -1.

top

Top line pixel.

x1

X-coordinate of the top left corner.

x2

X-coordinate of the bottom right corner.

y1

Y-coordinate of the top left corner.

y2

Y-coordinate of the bottom right corner.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawCircle(x: Int, y: Int, radius: Int, z: Int, xFactor: Float, yFactor: Float, densFactor: Float, fillGaps: Boolean, pxs: Seq[CPPixel]): CPRect

Draws a circle.

Draws a circle.

Value parameters

densFactor

Density factor defines "granularity" of drawing. Values below 1.0 allow to compensate for discreetness of ASCII graphics. Typically, value of 0.5 is a good default.

fillGaps

Whether or not to fill potential gaps in circle drawing. Filling the gaps slows down the drawing but produces a better looking circle.

pxs

Sequence of pixels to use in drawing the circle.

radius

Radius of the circle in characters.

x

X-coordinate of the circle center.

xFactor

Horizontal squishing factor. Values below 1.0 will squish the circle horizontally. Values above 1.0 will stretch the circle horizontally. X-factor of 2.0 and Y-factor of 1.0 typically produce correct circle using 1x2 monospace font.

y

Y-coordinate of the circle center.

yFactor

Vertical squishing factor. Values below 1.0 will squish the circle vertically. Values above 1.0 will stretch the circle vertically. X-factor of 2.0 and Y-factor of 1.0 typically produce correct circle using 1x2 monospace font.

z

Z-index of the drawing. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawCircle(x: Int, y: Int, radius: Int, z: Int, xFactor: Float, yFactor: Float, densFactor: Float, fillGaps: Boolean, px: CPPixel): CPRect

Draws a circle with a single pixel returning its final shape.

Draws a circle with a single pixel returning its final shape.

Value parameters

densFactor

Density factor defines "granularity" of drawing. Values below 1.0 allow to compensate for discreetness of ASCII graphics. Typically, value of 0.5 is a good default.

fillGaps

Whether or not to fill potential gaps in circle drawing. Filling the gaps slows down the drawing but produces a better looking circle.

px

Pixel to draw a circle with.

radius

Radius of the circle in characters.

x

X-coordinate of the circle center.

xFactor

Horizontal squishing factor. Values below 1.0 will squish the circle horizontally. Values above 1.0 will stretch the circle horizontally. X-factor of 2.0 and Y-factor of 1.0 typically produce correct circle using 1x2 monospace font.

y

Y-coordinate of the circle center.

yFactor

Vertical squishing factor. Values below 1.0 will squish the circle vertically. Values above 1.0 will stretch the circle vertically. X-factor of 2.0 and Y-factor of 1.0 typically produce correct circle using 1x2 monospace font.

z

Z-index of the drawing. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawCircle(x: Int, y: Int, radius: Int, z: Int, xFactor: Float, yFactor: Float, densFactor: Float, fillGaps: Boolean, pxf: (Int, Int) => CPPixel): CPRect

Draws a circle returning its final shape returning its final shape.

Draws a circle returning its final shape returning its final shape.

Value parameters

densFactor

Density factor defines "granularity" of drawing. Values below 1.0 allow to compensate for discreetness of ASCII graphics. Typically, value of 0.5 is a good default.

fillGaps

Whether or not to fill potential gaps in circle drawing. Filling the gaps slows down the drawing but produces a better looking circle.

pxf

Pixel producer function.

radius

Radius of the circle in characters.

x

X-coordinate of the circle center.

xFactor

Horizontal squishing factor. Values below 1.0 will squish the circle horizontally. Values above 1.0 will stretch the circle horizontally. X-factor of 2.0 and Y-factor of 1.0 typically produce correct circle using 1x2 monospace font.

y

Y-coordinate of the circle center.

yFactor

Vertical squishing factor. Values below 1.0 will squish the circle vertically. Values above 1.0 will stretch the circle vertically. X-factor of 2.0 and Y-factor of 1.0 typically produce correct circle using 1x2 monospace font.

z

Z-index of the drawing. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawImage(img: CPImage, x: Int, y: Int, z: Int): Unit

Draws given image.

Draws given image.

Value parameters

img

Image to draw.

x

X-coordinate of the top left corner.

y

Y-coordinate of the top left corner.

z

Z-index to draw the given image at. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawLine(ax: Int, ay: Int, bx: Int, by: Int, z: Int, px: CPPixel): Unit

Draws a line.

Draws a line.

Value parameters

ax

X-coordinate of the start point.

ay

Y-coordinate of the start point.

bx

X-coordinate of the end point.

by

Y-coordinate of the end point.

px

Pixel to use to draw the line.

z

Z-index of the drawing. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawLine(ax: Int, ay: Int, bx: Int, by: Int, z: Int, startPx: CPPixel, linePx: CPPixel, endPx: CPPixel): Unit

Draws the line with custom endpoints.

Draws the line with custom endpoints.

Value parameters

ax

X-coordinate of the start point.

ay

Y-coordinate of the start point.

bx

X-coordinate of the end point.

by

Y-coordinate of the end point.

endPx

End pixel.

linePx

Line pixel.

startPx

Start pixel.

z

Z-index of the drawing. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawLine(ax: Int, ay: Int, bx: Int, by: Int, z: Int, pxs: Seq[CPPixel]): Unit

Draws a line.

Draws a line.

Value parameters

ax

X-coordinate of the start point.

ay

Y-coordinate of the start point.

bx

X-coordinate of the end point.

by

Y-coordinate of the end point.

pxs

Sequence of pixels to use to draw this line.

z

Z-index of the drawing. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawLine(ax: Int, ay: Int, bx: Int, by: Int, z: Int, pxf: (Int, Int) => CPPixel): Unit

Draws a line.

Draws a line.

Value parameters

ax

X-coordinate of the start point.

ay

Y-coordinate of the start point.

bx

X-coordinate of the end point.

by

Y-coordinate of the end point.

pxf

Pixel producing function.

z

Z-index of the drawing. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawPixel(px: CPPixel, x: Int, y: Int, z: Int): Unit

Draws a single pixel.

Draws a single pixel.

Value parameters

px

Pixel to draw.

x

X-coordinate of the pixel.

y

Y-coordinate of the pixel.

z

Z-index for this pixel. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawPixel(px: CPPixel, xy: (Int, Int), z: Int): Unit

Draws a single pixel.

Draws a single pixel.

Value parameters

px

Pixel to draw.

xy

Xy-coordinate tuple of the pixel.

z

Z-index for this pixel. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawPixel(char: Char, fg: CPColor, bg: Option[CPColor], x: Int, y: Int, z: Int): Unit

Draws a pixel.

Draws a pixel.

Value parameters

bg

Pixel optional background color. Default value is None.

char

Pixel character.

fg

Pixel foreground color.

x

X-coordinate of the pixel.

y

Y-coordinate of the pixel.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawPixels(x: Int, y: Int, z: Int, len: Int, pxf: (Int, Int) => CPPixel): Unit

Draws pixels.

Draws pixels.

Value parameters

len

Number of pixel to draw.

pxf

Pixel producing function.

x

X-coordinate of the start point.

y

Y-coordinate of the start point.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawPixels(x: Int, y: Int, z: Int, pxs: Seq[CPPixel]): Unit

Draws pixels.

Draws pixels.

Value parameters

pxs

Pixels to draw.

x

X-coordinate of the start point.

y

Y-coordinate of the start point.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawPolyline(pts: Seq[(Int, Int)], z: Int, px: CPPixel): Unit

Draws a polyline.

Draws a polyline.

Value parameters

pts

Points of polyline.

px

Pixel to use to draw a polyline with.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawPolyline(pts: Seq[(Int, Int)], z: Int, pxs: Seq[CPPixel]): Unit

Draws a polyline.

Draws a polyline.

Value parameters

pts

Points of polyline.

pxs

Pixel producing function.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawPolyline(pts: Seq[(Int, Int)], z: Int, pxf: (Int, Int) => CPPixel): Unit

Draws a polyline.

Draws a polyline.

Value parameters

pts

Points of the polyline.

pxf

Pixel producing function.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawRect(x1: Int, y1: Int, x2: Int, y2: Int, z: Int, px: CPPixel): Unit

Draws a rectangle.

Draws a rectangle.

Value parameters

px

Pixel to use for drawing.

x1

X-coordinate of the left top corner.

x2

X-coordinate of the right bottom corner.

y1

Y-coordinate of the left top corner.

y2

Y-coordinate of the right bottom corner.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawRect(x1: Int, y1: Int, dim: CPDim, z: Int, px: CPPixel): Unit

Draws a rectangle.

Draws a rectangle.

Value parameters

dim

Dimension of the rectangle.

px

Pixel to use for drawing.

x1

X-coordinate of the left top corner.

y1

Y-coordinate of the left top corner.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawRect(rect: CPRect, z: Int, px: CPPixel): Unit

Draws a rectangle.

Draws a rectangle.

Value parameters

px

Pixel to draw the rectangle with.

rect

Shape of rectangle to draw.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawRect(x1: Int, y1: Int, x2: Int, y2: Int, z: Int, pxf: (Int, Int) => CPPixel): Unit

Draws a rectangle.

Draws a rectangle.

Value parameters

pxf

Pixel producing function.

x1

X-coordinate of the left top corner.

x2

X-coordinate of the right bottom corner.

y1

Y-coordinate of the left top corner.

y2

Y-coordinate of the right bottom corner.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawRect(x1: Int, y1: Int, dim: CPDim, z: Int, pxf: (Int, Int) => CPPixel): Unit

Draws a rectangle.

Draws a rectangle.

Value parameters

dim

Dimension of the rectangle.

pxf

Pixel producing function.

x1

X-coordinate of the top left corner.

y1

Y-coordinate of the top left corner.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawRect(rect: CPRect, z: Int, pxf: (Int, Int) => CPPixel): Unit

Draws rectangle.

Draws rectangle.

Value parameters

pxf

Pixel producing function.

rect

Rectangle shape to draw.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawRect(x1: Int, y1: Int, x2: Int, y2: Int, z: Int, top: CPPixel, leftTop: CPPixel, left: CPPixel, leftBottom: CPPixel, bottom: CPPixel, rightBottom: CPPixel, right: CPPixel, rightTop: CPPixel, skin: (Int, Int, CPPixel) => CPPixel): Unit

Draws rectangle with specific pixels for lines and corners.

Draws rectangle with specific pixels for lines and corners.

Value parameters

bottom

Bottom size pixel.

left

Left side pixel.

leftBottom

Left bottom corner pixel.

leftTop

Left top corner pixel.

right

Right side line pixel.

rightBottom

Right bottom corner pixel.

rightTop

Right top corner pixel.

skin

Skin function that takes global X and Y coordinates as well as default pixel at that location and returns the skinned pixel.

top

Top line pixel.

x1

X-coordinate of the left top corner.

x2

X-coordinate of the right bottom corner.

y1

Y-coordinate of the left top corner.

y2

Y-coordinate of the right bottom corner.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawRect(x1: Int, y1: Int, dim: CPDim, z: Int, top: CPPixel, leftTop: CPPixel, left: CPPixel, leftBottom: CPPixel, bottom: CPPixel, rightBottom: CPPixel, right: CPPixel, rightTop: CPPixel): Unit

Draws rectangle with specific pixels for lines and corners.

Draws rectangle with specific pixels for lines and corners.

Value parameters

bottom

Bottom size pixel.

dim

Dimension of the rectangle.

left

Left side pixel.

leftBottom

Left bottom corner pixel.

leftTop

Left top corner pixel.

right

Right side line pixel.

rightBottom

Right bottom corner pixel.

rightTop

Right top corner pixel.

top

Top line pixel.

x1

X-coordinate of the top left corner.

y1

Y-coordinate of the top left corner.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawRect(rect: CPRect, z: Int, top: CPPixel, leftTop: CPPixel, left: CPPixel, leftBottom: CPPixel, bottom: CPPixel, rightBottom: CPPixel, right: CPPixel, rightTop: CPPixel): Unit

Draws rectangle with specific pixels for lines and corners.

Draws rectangle with specific pixels for lines and corners.

Value parameters

bottom

Bottom size pixel.

left

Left side pixel.

leftBottom

Left bottom corner pixel.

leftTop

Left top corner pixel.

rect

Rectangle shape.

right

Right side line pixel.

rightBottom

Right bottom corner pixel.

rightTop

Right top corner pixel.

top

Top line pixel.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawRectBorder(rect: CPRect, z: Int, chars: String, fg: CPColor, bg: Option[CPColor], title: Seq[CPPixel], titleX: Int, titleY: Int, skin: (Int, Int, CPPixel) => CPPixel): Unit

Draws a single color border for a given rectangle.

Draws a single color border for a given rectangle.

Value parameters

bg

An optional background color to be used for all border pixels.

chars

A sequence of character in the following order: top, top left border, left, bottom left corner, bottom, bottom right corner, right, top right corner.

fg

A foreground color to be used for all border pixels.

rect

A rectangle to draw a border around.

skin

Skin function that takes global X and Y coordinates as well as default pixel at that location and returns the skinned pixel. Default value is the function that returns the same pixel.

title

Title of the border. Default is no border.

titleX

X-coordinate of the title. Default is -1.

titleY

Y-coordinate of the title. Default is -1.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawSimpleBorder(x1: Int, y1: Int, x2: Int, y2: Int, z: Int, ver: CPPixel, hor: CPPixel, corner: CPPixel, title: Seq[CPPixel], titleX: Int, titleY: Int, skin: (Int, Int, CPPixel) => CPPixel): Unit

Draws a border using shorter set of parameters.

Draws a border using shorter set of parameters.

Value parameters

corner

Pixel for corners,

hor

Pixel for horizontal lines.

skin

Skin function that takes X and Y coordinates as well as default pixel at that location and returns the skinned pixel.

title

Title of the border. Default is no border.

titleX

X-coordinate of the title. Default is -1.

titleY

Y-coordinate of the title. Default is -1.

ver

Pixel for vertical lines.

x1

X-coordinate of the top left corner.

x2

X-coordinate of the bottom right corner.

y1

Y-coordinate of the top left corner.

y2

Y-coordinate of the bottom right corner.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawString(x: Int, y: Int, z: Int, str: String, fg: CPColor, bg: Option[CPColor]): Unit

Draws given string using system font.

Draws given string using system font.

Value parameters

bg

Optional background color. Default value is None.

fg

Foreground color.

str

String to draw.

x

X-coordinate of the first character.

y

Y-coordinate of the first character.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawStyledString(x: Int, y: Int, z: Int, ss: CPStyledString): Unit

Draws given styled string.

Draws given styled string.

Value parameters

ss

Styled string to draw.

x

X-coordinate of the first character.

y

Y-coordinate of the first character.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawVector(x: Int, y: Int, deg: Float, len: Int, z: Int, xFactor: Float, yFactor: Float, px: CPPixel): Unit

Draws a vector with a single pixel.

Draws a vector with a single pixel.

Value parameters

deg

Angle of vector in degrees [0..360].

len

Length of the vector.

px

Single pixel to draw vector with.

x

X-coordinate of the start point.

y

Y-coordinate of the start point.

z

Z-index of the drawn vector. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawVector(x: Int, y: Int, deg: Float, len: Int, z: Int, xFactor: Float, yFactor: Float, pxs: Seq[CPPixel]): Unit

Draws a vector.

Draws a vector.

Value parameters

deg

Angle of vector in degrees [0..360].

len

Length of the vector.

pxs

Sequence of pixels to use for drawing.

x

X-coordinate of the start point.

xFactor

Horizontal squishing factor. Values below 1.0 will squish the vector horizontally. Values above 1.0 will stretch the vector horizontally.

y

Y-coordinate of the start point.

yFactor

Vertical squishing factor. Values below 1.0 will squish the vector vertically. Values above 1.0 will stretch the vector vertically.

z

Z-index of the drawn vector. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def drawVector(x: Int, y: Int, deg: Float, len: Int, z: Int, xFactor: Float, yFactor: Float, pxf: (Int, Int) => CPPixel): Unit

Draws a vector.

Draws a vector.

Value parameters

deg

Angle of vector in degrees [0..360].

len

Length of the vector.

pxf

Pixel producer function.

x

X-coordinate of the start point.

xFactor

Horizontal squishing factor. Values below 1.0 will squish the vector horizontally. Values above 1.0 will stretch the vector horizontally.

y

Y-coordinate of the start point.

yFactor

Vertical squishing factor. Values below 1.0 will squish the vector vertically. Values above 1.0 will stretch the vector vertically.

z

Z-index of the drawn vector. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def fill(x: Int, y: Int, isBorder: CPZPixel => Boolean, pxf: (Int, Int) => CPPixel): Unit

Fills in bordered area with a pixel. This is also known as "bucket tool".

Fills in bordered area with a pixel. This is also known as "bucket tool".

Value parameters

isBorder

Border predicate.

pxf

Fill in pixel producer.

x

X-coordinate of the start point.

y

Y-coordinate of the start point.

Attributes

Source
CPCanvas.scala
def fillRect(x1: Int, y1: Int, x2: Int, y2: Int, z: Int, px: CPPixel): Unit

Fills the rectangular shape with given pixel.

Fills the rectangular shape with given pixel.

Value parameters

px

Pixel to fill in with.

x1

X-coordinate of the top left corner of the shape.

x2

X-coordinate of the bottom right corner of the shape.

y1

Y-coordinate of the top left corner of the shape.

y2

Y-coordinate of the bottom right corner of the shape.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def fillRect(x1: Int, y1: Int, dim: CPDim, z: Int, px: CPPixel): Unit

Fills the rectangular shape with given pixel.

Fills the rectangular shape with given pixel.

Value parameters

dim

Dimension of the rectangle to fill in.

px

Pixel to fill in with.

x1

X-coordinate of the top left corner of the shape.

y1

Y-coordinate of the top left corner of the shape.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def fillRect(x1: Int, y1: Int, dim: CPDim, z: Int, pxf: (Int, Int) => CPPixel): Unit

Fills the rectangular shape.

Fills the rectangular shape.

Value parameters

dim

Dimension of the rectangle to fill in.

pxf

Fill in pixel producing function.

x1

X-coordinate of the top left corner of the shape.

y1

Y-coordinate of the top left corner of the shape.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def fillRect(x1: Int, y1: Int, dim: CPDim, z: Int, pxs: Seq[CPPixel]): Unit

Fills the rectangular shape.

Fills the rectangular shape.

Value parameters

dim

Dimension of the rectangle to fill in.

pxs

Pixels to use for filling in.

x1

X-coordinate of the top left corner of the shape.

y1

Y-coordinate of the top left corner of the shape.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def fillRect(rect: CPRect, z: Int, px: CPPixel): Unit

Fills the rectangular shape.

Fills the rectangular shape.

Value parameters

px

Pixel to use for filling in.

rect

Rectangle shape to fill in.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def fillRect(x1: Int, y1: Int, x2: Int, y2: Int, z: Int, pxf: (Int, Int) => CPPixel): Unit

Fills the rectangular shape.

Fills the rectangular shape.

Value parameters

pxf

Fill in pixel producing function.

x1

X-coordinate of the top left corner of the shape.

x2

X-coordinate of the bottom right corner of the shape.

y1

Y-coordinate of the top left corner of the shape.

y2

Y-coordinate of the bottom right corner of the shape.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def fillRect(rect: CPRect, z: Int, pxf: (Int, Int) => CPPixel): Unit

Fills the rectangular shape.

Fills the rectangular shape.

Value parameters

pxf

Fill in pixel producing function.

rect

Rectangular shape to fill in.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def fillRect(x1: Int, y1: Int, x2: Int, y2: Int, z: Int, pxs: Seq[CPPixel]): Unit

Fills the rectangular shape.

Fills the rectangular shape.

Value parameters

pxs

Pixels to use for filling in.

x1

X-coordinate of the top left corner of the shape.

x2

X-coordinate of the bottom right corner of the shape.

y1

Y-coordinate of the top left corner of the shape.

y2

Y-coordinate of the bottom right corner of the shape.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def fillRect(rect: CPRect, z: Int, pxs: Seq[CPPixel]): Unit

Fills the rectangular shape.

Fills the rectangular shape.

Value parameters

pxs

Pixels to use for filling in.

rect

Rectangular shape to fill in.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala

Gets clipping region for this canvas. Note that it is available only for information purpose since all functions in this class automatically handle the clipping.

Gets clipping region for this canvas. Note that it is available only for information purpose since all functions in this class automatically handle the clipping.

Attributes

Source
CPCanvas.scala
def getZPixel(x: Int, y: Int): CPZPixel

Gets a pixel at given XY-coordinate.

Gets a pixel at given XY-coordinate.

Value parameters

x

X-coordinate.

y

Y-coordinate.

Attributes

Returns

Pixel at given coordinate.

Source
CPCanvas.scala
def inversePixel(x: Int, y: Int): Unit

Inverses color of the pixel at given XY-coordinate.

Inverses color of the pixel at given XY-coordinate.

Value parameters

x

X-coordinate.

y

Y-coordinate.

Attributes

Source
CPCanvas.scala
def isValid(x: Int, y: Int): Boolean

Tests whether or not given XY-coordinates are within this canvas.

Tests whether or not given XY-coordinates are within this canvas.

Value parameters

x

X-coordinate to test.

y

Y-coordinate to test.

Attributes

Source
CPCanvas.scala
def linePixels(ax: Int, ay: Int, bx: Int, by: Int, z: Int, pxf: (Int, Int) => CPPixel): ArrayBuffer[CPPosPixel]

Gets a mutable array of pixels representing a line.

Gets a mutable array of pixels representing a line.

Value parameters

ax

X-coordinate of the start point.

ay

Y-coordinate of the start point.

bx

X-coordinate of the end point.

by

Y-coordinate of the end point.

pxf

Pixel producing function.

z

Z-index of the drawing. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def polylinePixels(pts: Seq[(Int, Int)], z: Int, pxf: (Int, Int) => CPPixel): ArrayBuffer[CPPosPixel]

Gets a mutable array of pixels representing a polyline.

Gets a mutable array of pixels representing a polyline.

Value parameters

pts

Points of the polyline.

pxf

Pixel producing function.

z

Z-index. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala
def vectorPixels(x: Int, y: Int, deg: Float, len: Int, z: Int, xFactor: Float, yFactor: Float, pxf: (Int, Int) => CPPixel): ArrayBuffer[CPPosPixel]

Produces mutable array of pixels representing the vector.

Produces mutable array of pixels representing the vector.

Value parameters

deg

Angle of vector in degrees [0..360].

len

Length of the vector.

pxf

Pixel producer function.

x

X-coordinate of the start point.

xFactor

Horizontal squishing factor. Values below 1.0 will squish the vector horizontally. Values above 1.0 will stretch the vector horizontally.

y

Y-coordinate of the start point.

yFactor

Vertical squishing factor. Values below 1.0 will squish the vector vertically. Values above 1.0 will stretch the vector vertically.

z

Z-index of the drawn vector. Pixel with the larger or equal Z-index overrides the pixel with the smaller one.

Attributes

Source
CPCanvas.scala

Concrete fields

val dim: CPDim

Dimension of this canvas.

Dimension of this canvas.

Attributes

Source
CPCanvas.scala
val h: Int

Height of this canvas (shortcut API).

Height of this canvas (shortcut API).

Attributes

Source
CPCanvas.scala
val hF: Float

Height of this canvas as float (shortcut API).

Height of this canvas as float (shortcut API).

Attributes

Source
CPCanvas.scala
val height: Int

Height of this canvas.

Height of this canvas.

Attributes

Source
CPCanvas.scala
val rect: CPRect

Rectangle object (shape) for this canvas.

Rectangle object (shape) for this canvas.

Attributes

Source
CPCanvas.scala
val w: Int

Width of this canvas (shortcut API).

Width of this canvas (shortcut API).

Attributes

Source
CPCanvas.scala
val wF: Float

Width of this canvas as float (shortcut API).

Width of this canvas as float (shortcut API).

Attributes

Source
CPCanvas.scala
val width: Int

Width of this canvas.

Width of this canvas.

Attributes

Source
CPCanvas.scala
val xCenter: Int

X-coordinate of the center point of this canvas.

X-coordinate of the center point of this canvas.

Attributes

Source
CPCanvas.scala
final lazy val xCenterF: Float

X-coordinate of the center point of this canvas as a float.

X-coordinate of the center point of this canvas as a float.

Attributes

Source
CPCanvas.scala
val xMax: Int

Maximum X-coordinate of this canvas.

Maximum X-coordinate of this canvas.

Attributes

Source
CPCanvas.scala
final lazy val xMaxF: Float

Maximum X-coordinate of this canvas as a float.

Maximum X-coordinate of this canvas as a float.

Attributes

Source
CPCanvas.scala
val xMin: Int

Minimum X-coordinate of this canvas (always zero).

Minimum X-coordinate of this canvas (always zero).

Attributes

Source
CPCanvas.scala
final lazy val xMinF: 0.0f

Minimum X-coordinate of this canvas (always zero) as a float.

Minimum X-coordinate of this canvas (always zero) as a float.

Attributes

Source
CPCanvas.scala
val yCenter: Int

Y-coordinate of the center point of this canvas.

Y-coordinate of the center point of this canvas.

Attributes

Source
CPCanvas.scala
val yCenterF: Float

Y-coordinate of the center point of this canvas as a float.

Y-coordinate of the center point of this canvas as a float.

Attributes

Source
CPCanvas.scala
val yMax: Int

Maximum Y-coordinate of this canvas.

Maximum Y-coordinate of this canvas.

Attributes

Source
CPCanvas.scala
final lazy val yMaxF: Float

Maximum Y-coordinate of this canvas as a float.

Maximum Y-coordinate of this canvas as a float.

Attributes

Source
CPCanvas.scala
val yMin: Int

Minimum Y-coordinate of this canvas (always zero).

Minimum Y-coordinate of this canvas (always zero).

Attributes

Source
CPCanvas.scala
final lazy val yMinF: 0.0f

Minimum Y-coordinate of this canvas (always zero) as a float.

Minimum Y-coordinate of this canvas (always zero) as a float.

Attributes

Source
CPCanvas.scala