java.lang.Object
technology.sola.engine.graphics.Canvas
Direct Known Subclasses:
SoftwareRenderer, SolaImage

@NullMarked public class Canvas extends Object
Canvas is an array of pixels with a width and height defined.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    The height of the canvas.
    protected int[]
    The pixel array for the canvas.
    protected int
    The width of the canvas.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Canvas(int width, int height)
    Creates a Canvas instance with an empty array of pixels.
    Canvas(int width, int height, int[] pixels)
    Creates a canvas instance with desired array of pixels.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    int
    getPixel(float x, float y)
    Returns the hex value of the pixel at desired coordinate on the canvas.
    int
    getPixel(int x, int y)
    Returns the hex value of the pixel at desired coordinate on the canvas.
    int[]
     
    int
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • width

      protected int width
      The width of the canvas.
    • height

      protected int height
      The height of the canvas.
    • pixels

      protected int[] pixels
      The pixel array for the canvas.
  • Constructor Details

    • Canvas

      public Canvas(int width, int height)
      Creates a Canvas instance with an empty array of pixels.
      Parameters:
      width - the width of the Canvas
      height - the height of the canvas
    • Canvas

      public Canvas(int width, int height, int[] pixels)
      Creates a canvas instance with desired array of pixels.
      Parameters:
      width - the width of the Canvas
      height - the height of the canvas
      pixels - the array of pixels to use for this canvas
  • Method Details

    • getPixel

      public int getPixel(int x, int y)
      Returns the hex value of the pixel at desired coordinate on the canvas.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      the hex value of the pixel
    • getPixel

      public int getPixel(float x, float y)
      Returns the hex value of the pixel at desired coordinate on the canvas. Since pixels coordinates are integers this rounds the float values half up.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      the hex value of the pixel
    • getPixels

      public int[] getPixels()
      Returns:
      the array of pixels in the canvas
    • getWidth

      public int getWidth()
      Returns:
      the width of the canvas
    • getHeight

      public int getHeight()
      Returns:
      the height of the canvas