Package org.openpatch.scratch.internal
Class Image
java.lang.Object
org.openpatch.scratch.internal.Image
The base class for representing scratch costumes and backdrops.
-
Constructor Summary
ConstructorDescriptionConstruct a ScratchImage object by a name and a path to an image.Construct a ScratchImage object by a name and a path to a sprite sheet.Copies a ScratchImage object -
Method Summary
Modifier and TypeMethodDescriptionvoid
changeTint
(double h) Changes the tint by adding a hue value to the current hue value.void
changeTransparency
(double step) Changes the transparency by adding a step value to the current transparency.void
draw()
Draw the image.void
draw
(processing.core.PGraphics buffer, double size, double degrees, double x, double y, RotationStyle style, Shader shader) Draw the scaled image at a given position.void
Draw the scaled image at a given position.void
drawAsBackground
(processing.core.PGraphics buffer) Draw the image as a background.void
drawDebug
(processing.core.PGraphics buffer, double size, double degrees, double x, double y, RotationStyle style) Draw the scaled image at a given position.int
Returns the heightgetName()
Returns the nameint
getPixel
(int x, int y) Returns the pixel at the given positiondouble
getTint()
Returns the tintdouble
Returns the transparencyint
getWidth()
Returns the widthstatic processing.core.PImage
Loads an image from a given path and returns it.static processing.core.PImage
Loads an image from a given path and returns a tile of the image.void
Sets the image from a given pathvoid
Sets the namevoid
setSize
(double percentage) Sets the size of the image to the specified percentage of the original size.void
setSize
(int width, int height) Sets the size of the image to the specified width and height.void
setTint
(double h) Sets the tint with huevoid
setTint
(double r, double g, double b) Sets the tint with rgbvoid
setTransparency
(double transparency) Sets the transparency.
-
Constructor Details
-
Image
Construct a ScratchImage object by a name and a path to an image.- Parameters:
name
- a a nameimagePath
- a path to an image
-
Image
Construct a ScratchImage object by a name and a path to a sprite sheet.- Parameters:
name
- a namespriteSheetPath
- a path to a sprite sheetx
- the x coordinate of the tiley
- the y coordinate of the tilewidth
- the width of the tileheight
- the height of the tile
-
Image
Copies a ScratchImage object- Parameters:
i
- the ScratchImage object to copy
-
-
Method Details
-
loadImage
Loads an image from a given path and returns it.- Parameters:
path
- the path to the image- Returns:
- the image
-
loadImage
Loads an image from a given path and returns a tile of the image.- Parameters:
path
- the path to the imagex
- the x coordinate of the tiley
- the y coordinate of the tilewidth
- the width of the tileheight
- the height of the tile- Returns:
- a tile of the image
-
getName
Returns the name- Returns:
- the name
-
setName
Sets the name- Parameters:
name
- unique name
-
getWidth
public int getWidth()Returns the width- Returns:
- the width
-
getHeight
public int getHeight()Returns the height- Returns:
- the height
-
getPixel
public int getPixel(int x, int y) Returns the pixel at the given position- Parameters:
x
- a x coordinatey
- a y coordinate- Returns:
- the pixel at the given position
-
setTint
public void setTint(double r, double g, double b) Sets the tint with rgb- Parameters:
r
- a red value [0...255]g
- a green value [0...255]b
- a blue value [0...255]
-
setTint
public void setTint(double h) Sets the tint with hue- Parameters:
h
- a hue value [0...255]
-
changeTint
public void changeTint(double h) Changes the tint by adding a hue value to the current hue value.- Parameters:
h
- a hue value [0...255]
-
getTint
public double getTint()Returns the tint- Returns:
- a hue value [0...255]
-
setTransparency
public void setTransparency(double transparency) Sets the transparency. 0 equals fully transparent.- Parameters:
transparency
- [0...255]
-
changeTransparency
public void changeTransparency(double step) Changes the transparency by adding a step value to the current transparency.- Parameters:
step
- a step value
-
getTransparency
public double getTransparency()Returns the transparency- Returns:
- the transparency [0...255]
-
setImage
Sets the image from a given path- Parameters:
imagePath
- the path to the image
-
setSize
public void setSize(double percentage) Sets the size of the image to the specified percentage of the original size.- Parameters:
percentage
- The desired size as a percentage of the original size
-
setSize
public void setSize(int width, int height) Sets the size of the image to the specified width and height. If a resized version with the requested dimensions already exists in cache, it will use that version. Otherwise, it creates a new resized copy from the original image and caches it for future use.- Parameters:
width
- The desired width of the image in pixelsheight
- The desired height of the image in pixels
-
draw
public void draw(processing.core.PGraphics buffer, double size, double degrees, double x, double y, RotationStyle style, Shader shader) Draw the scaled image at a given position.- Parameters:
buffer
- a buffersize
- a percentage valuedegrees
- directionx
- a x coordinatey
- a y coordinatestyle
- a rotation styleshader
- a shader
-
drawDebug
public void drawDebug(processing.core.PGraphics buffer, double size, double degrees, double x, double y, RotationStyle style) Draw the scaled image at a given position.- Parameters:
size
- a percentage valuedegrees
- directionx
- a x coordinatey
- a y coordinatestyle
- a rotation style
-
draw
public void draw(processing.core.PGraphics buffer, float size, float degrees, float x, float y, Shader shader) Draw the scaled image at a given position.- Parameters:
buffer
- a buffersize
- a percentage valuedegrees
- directionx
- a x coordinatey
- a y coordinateshader
- a shader
-
draw
public void draw()Draw the image. -
drawAsBackground
public void drawAsBackground(processing.core.PGraphics buffer) Draw the image as a background. The image is automatically scaled to fit the window size.- Parameters:
buffer
- a buffer
-