PenSkin

PenSkin

new PenSkin(id, renderer)

Create a Skin which implements a Scratch pen layer.

Parameters:
Name Type Description
id int

The unique ID for this Skin.

renderer RenderWebGL

The renderer which will use this Skin.

Listens to Events:

Extends

Members

(private, static, constant) DefaultPenAttributes :PenSkin#PenAttributes

The pen attributes to use when unspecified.

Type:

_canvas :HTMLCanvasElement

Type:
  • HTMLCanvasElement

_canvasDirty :boolean

Type:
  • boolean

_id :int

Inherited From:
Type:
  • int

(private) _renderer :RenderWebGL

Type:

_rotationCenter :Vec3

Inherited From:
Type:
  • Vec3

_texture :WebGLTexture

Type:
  • WebGLTexture

(private) _uniforms :Object.<string, *>

Inherited From:

The uniforms to be used by the vertex and pixel shaders. Some of these are used by other parts of the renderer as well.

Type:
  • Object.<string, *>

id

Inherited From:

rotationCenter

Inherited From:

size

Overrides:

Methods

(private) _setAttributes(context, penAttributes)

Set context state to match provided pen attributes.

Parameters:
Name Type Description
context CanvasRenderingContext2D

the canvas rendering context to be modified.

penAttributes PenAttributes

the pen attributes to be used.

(private) _setCanvasSize(canvasSize)

Set the size of the pen canvas.

Parameters:
Name Type Description
canvasSize Array.<int>

the new width and height for the canvas.

calculateRotationCenter() → {Array.<number>}

Inherited From:

Get the center of the current bounding box

Returns:

the center of the current bounding box

Type
Array.<number>

clear()

Clear the pen layer.

dispose()

Overrides:

Dispose of this object. Do not use it after calling this method.

drawLine(penAttributes, x0, y0, x1, y1)

Draw a line on the pen layer.

Parameters:
Name Type Description
penAttributes PenAttributes

how the line should be drawn.

x0 number

the X coordinate of the beginning of the line.

y0 number

the Y coordinate of the beginning of the line.

x1 number

the X coordinate of the end of the line.

y1 number

the Y coordinate of the end of the line.

drawPoint(penAttributes, x, y)

Draw a point on the pen layer.

Parameters:
Name Type Description
penAttributes PenAttributes

how the point should be drawn.

x number

the X coordinate of the point to draw.

y number

the Y coordinate of the point to draw.

drawStamp(stampElement, x, y)

Stamp an image onto the pen layer.

Parameters:
Name Type Description
stampElement HTMLCanvasElement | HTMLImageElement | HTMLVideoElement

the element to use as the stamp.

x number

the X coordinate of the stamp to draw.

y number

the Y coordinate of the stamp to draw.

getTexture(pixelsWide, pixelsTall) → {WebGLTexture}

Overrides:
Parameters:
Name Type Description
pixelsWide int

The width that the skin will be rendered at, in GPU pixels.

pixelsTall int

The height that the skin will be rendered at, in GPU pixels.

Returns:

The GL texture representation of this skin when drawing at the given size.

Type
WebGLTexture

getUniforms(scale) → {object.<string, *>}

Inherited From:

Update and returns the uniforms for this skin.

Parameters:
Name Type Description
scale Array.<number>

The scaling factors to be used.

Returns:

the shader uniforms to be used when rendering with this Skin.

Type
object.<string, *>

onNativeSizeChanged(event)

React to a change in the renderer's native size.

Parameters:
Name Type Description
event object

The change event.

setRotationCenter(x, y)

Inherited From:

Set the origin, in object space, about which this Skin should rotate.

Parameters:
Name Type Description
x number

The x coordinate of the new rotation center.

y number

The y coordinate of the new rotation center.

Fires:

Type Definitions

PenAttributes

Properties:
Name Type Attributes Description
diameter number <optional>

The size (diameter) of the pen.

color4f Array.<number> <optional>

The pen color as an array of [r,g,b,a], each component in the range [0,1].

Attributes to use when drawing with the pen

Type:
  • object