Home Reference Source
public class | source

Ball

Extends:

WorldElement → Ball

The Ball class is a particle class used to draw round particles with the advantage that they can be labeled and displayed with a gradient, giving a more realistic feel to the particle.

Static Method Summary

Static Public Methods
public static

Gets a color depending on the value a charge has.

public static

Gets the sign a charge must have depending on the value a charge has.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

Flag for enabling a gradient on the ball.

public

Flag for allowing the ball to be dragged around.

public

Spot for writing a label on the ball.

public

Radius of the ball in units.

public

Flag for allowing the ball to become a topmost object when its beging dragged, Default value is true.

public

Upper spot for writing a label on the bal..

Method Summary

Private Methods
private

draw()

Main draw function for the ball called by the World automatically.

private

Tests if the mouse is over the ball.

Inherited Summary

From class WorldElement
public

Sets the color in HEX format of the element.

public

Sets the cursor style when the mouse is over the element.

public

Flag for enabling or diabling this element.

public

Flag set when the element is being dragged around.

public

Sets the font of the element.

public

Sets the current height of the element.

public

Flag for allowing the element to be dragged around.

public

Sets the move style of the element.

public

Flag set when the mouse is over the element.

public

Sets a callback function for when the element is dragged around.

public

Sets the position of the element.

public

Sets the renderer used for the element.

public

Sets the rotation of the element.

public

A copy of the z-index value is stored here.

public

Sets the drawing scale of the element.

public

Flag for determining if the element will be a top-most element when dragged around.

public

Flag used to determine if an object is a child of WorldElement.

public

Sets the current width of the element.

public

Sets the world where this element is found.

public

Sets the z-index of the element.

public

Adds the provided coordinates to the position.

public

Sets if the element is draggable.

public

Function called when the mouse moves to check if the pointer is over the element.

public

Sets the color in HEX format of the element.

public

Sets the position of the element.

public

Sets the scale of the element.

public

setZ(z: number)

Sets the z-index of the element.

private

resize()

Function called when the canvas gets resized.

private

setWorld(world: World)

Sets the world object where element will be drawn.

private

topmost(state: boolean)

Sets the element as a topmost element.

Static Public Methods

public static getChargeColor(charge: number): string source

Gets a color depending on the value a charge has. If the charge is positive the color is COLORS.RED. If the charge is negative the color is COLORS.BLUE. If the charge is neutral the color is COLORS.GRAY.

Params:

NameTypeAttributeDescription
charge number

Charge of the particle in coulombs.

Return:

string

Color for the charge.

public static getChargeSign(charge: number): string source

Gets the sign a charge must have depending on the value a charge has. If the charge is positive the sign is "+". If the charge is negative the sign is "-". If the charge is neutral the sign is "".

Params:

NameTypeAttributeDescription
charge number

Charge of the particle in coulombs.

Return:

string

Sign for the charge.

Public Constructors

public constructor(r: number, opts: object) source

Override:

WorldElement#constructor

Params:

NameTypeAttributeDescription
r number
  • optional
  • default: 1

Radius of the charge in units.

opts object
  • optional

Object that contains valid Ball properties with values. Their values will be assigned at the end of the constructor. If an invalid property is passed then the value will be ignored.

Public Members

public gradient: boolean source

Flag for enabling a gradient on the ball. The color used for gradient is the one set in Ball.color. Default value is true.

public isDraggable: boolean source

Flag for allowing the ball to be dragged around. Default value is true.

Override:

WorldElement#isDraggable

public lowerLabel: string source

Spot for writing a label on the ball. If the Ball.upperLabel is blank, then the lower label will be centered on the particle. If not, then it will be the lower label on the ball. Default value is "".

public r: number source

Radius of the ball in units. Default value is 1.

public topmostOnDrag: boolean source

Flag for allowing the ball to become a topmost object when its beging dragged, Default value is true.

Override:

WorldElement#topmostOnDrag

public upperLabel: string source

Upper spot for writing a label on the bal.. Default value is "".

Private Methods

private draw() source

Main draw function for the ball called by the World automatically.

private isMouseOver(): boolean source

Tests if the mouse is over the ball.

Override:

WorldElement#isMouseOver

Return:

boolean

True if the mouse is over the ball, false otherwise.