Class Pen
java.lang.Object
org.openpatch.scratch.Pen
A pen draws lines onto the canvas of its layer, like Scratch's pen. Every sprite has one
(
getPen()) that follows it; a pen of your own can be added to a stage and moved with
setPosition(double, double).
What a pen draws stays where it was drawn on the screen: a camera moving later does not move
it. A sprite's pen draws onto Layer.BACKGROUND, behind the sprites, unless it is moved
with setLayer(Layer).
this.getPen().setColor(new Color(255, 0, 0));
this.getPen().setSize(4);
this.getPen().down();
this.move(50);
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeColor(double by) voidchangeSize(double by) voidchangeTransparency(double by) voiddown()Puts the pen down: it leaves a dot, and a line wherever it moves.voideraseAll()Erases everything drawn on the pen's layer, by any pen or stamp.getColor()getLayer()doublegetSize()doublevoidMoves the pen to the mouse pointer, drawing if it is down.voidMoves the pen to a random position on the stage, drawing if it is down.booleanisDown()voidsetColor(double hue) Sets the colour by Scratch's colour number (hue) from 0 to 100, at full saturation and brightness, like Scratch's "set pen color to".voidsetColor(double red, double green, double blue) voidvoidvoidsetPosition(double x, double y) Moves the pen, drawing a line from where it was if it is down.voidsetPosition(Vector2 position) voidsetSize(double size) voidsetTransparency(double transparency) voidstamp()Stamps the pen's sprite onto the pen's layer, like Scratch's "stamp" block.voidup()Lifts the pen: it no longer draws.
-
Constructor Details
-
Pen
public Pen()A pen of your own, at (0, 0); add it to a stage withstage.add(pen).
-
-
Method Details
-
getColor
- Returns:
- the colour lines are drawn in
-
setColor
- Parameters:
color- the colour to draw lines in
-
setColor
public void setColor(double hue) Sets the colour by Scratch's colour number (hue) from 0 to 100, at full saturation and brightness, like Scratch's "set pen color to".- Parameters:
hue- the colour from 0 to 100
-
setColor
public void setColor(double red, double green, double blue) - Parameters:
red- red from 0 to 255green- green from 0 to 255blue- blue from 0 to 255
-
changeColor
public void changeColor(double by) - Parameters:
by- how much to change the colour (hue, 0 to 100, going around)- Scratch Block:
- change pen [color v] by (c)
-
getSize
public double getSize()- Returns:
- the line width in stage pixels
-
setSize
public void setSize(double size) - Parameters:
size- the line width in stage pixels (at least 1)- Scratch Block:
- set pen size to (size)
-
changeSize
public void changeSize(double by) - Parameters:
by- how much to change the line width- Scratch Block:
- change pen size by (size)
-
getTransparency
public double getTransparency()- Returns:
- the transparency in percent (0 opaque, 100 invisible)
-
setTransparency
public void setTransparency(double transparency) - Parameters:
transparency- in percent (0 opaque, 100 invisible)
-
changeTransparency
public void changeTransparency(double by) - Parameters:
by- how much to change the transparency
-
getLayer
- Returns:
- the layer whose canvas the pen draws on
-
setLayer
- Parameters:
layer- the layer whose canvas the pen draws on
-
isDown
public boolean isDown()- Returns:
- whether the pen is down and draws when it moves
-
down
public void down()Puts the pen down: it leaves a dot, and a line wherever it moves.- Scratch Block:
- pen down
-
up
public void up()Lifts the pen: it no longer draws.- Scratch Block:
- pen up
-
setPosition
public void setPosition(double x, double y) Moves the pen, drawing a line from where it was if it is down.- Parameters:
x- world xy- world y
-
setPosition
- Parameters:
position- world position
-
goToRandomPosition
public void goToRandomPosition()Moves the pen to a random position on the stage, drawing if it is down. -
goToMousePointer
public void goToMousePointer()Moves the pen to the mouse pointer, drawing if it is down. -
getPosition
- Returns:
- the pen's world position
-
stamp
public void stamp()Stamps the pen's sprite onto the pen's layer, like Scratch's "stamp" block.- Scratch Block:
- stamp
-
eraseAll
public void eraseAll()Erases everything drawn on the pen's layer, by any pen or stamp.- Scratch Block:
- erase all
-