API Docs for: 6.0.1
Show:

Particle Class

Extends Base
Module: scrawlPhysics

Particle

Instantiation

  • scrawl.makeParticle()

Purpose

  • Defines Particle object, for physics simulations

Access

  • scrawl.entity.PARTICLENAME - for the Animation object

Constructor

Particle

(
  • [items]
)

Parameters:

  • [items] Object optional

    Key:value Object argument for setting attributes

Methods

addForce

(
  • item
)
chainable

Add a force to the forces array

Parameters:

  • item Object

    Anonymous Function, or FORCENAME String

Returns:

This

addSpring

(
  • items
)
chainable

Create a new Spring object and add it to this, and another, Particle objects' springs array

Argument can be either a PARTICLENAME String, or an Object which includes an end attribute set to a PARTICLENAME String

Parameters:

  • items Object

    Object consisting of key:value attributes; alternatively, use a PARTICLENAME String

Returns:

This

calculateLoads

() private chainable

Calculate the loads (via forces) acting on the particle for this calculation cycle iteration

Returns:

This

clone

(
  • items
)
chainable

Inherited from Base but overwritten in source\scrawlPhysics.js:468

Augments Base.clone()

Parameters:

  • items Object

    Object consisting of key:value attributes

Returns:

Cloned Particle object

dropEntity

() chainable

Dummy function - required to allow Particles to be processed alongside Entity objects

Returns:

This

forceStamp

() chainable

Alias for Particle.stamp()

Returns:

This

get

(
  • item
)

Retrieve an attribute value. If the attribute value has not been set, then the default value for that attribute will be returned.

Parameters:

  • item String

    Attribute key

Returns:

Attribute value

Example:

var box = scrawl.makeBlock({
    width: 50,
    });
box.get('width');               //returns 50
box.get('height');              //returns 0
box.get('favouriteAnimal');     //returns undefined

getStartValues

()

Particle.getStartValues

Returns:

Object containing x and y Number attributes representing the particle's current position with respect to its Cell's top left hand corner

linearCollide

() private chainable

Calculation cycle engine - linear particle collisions

Returns:

This

numberConvert

(
  • val
  • dim
)
private

Stamp helper function - convert string percentage values to numerical values

Parameters:

  • val String

    coordinate String

  • dim Number

    dimension value

Returns:

Number - value

parse

()

Turn the object into a JSON String

Returns:

object of object's currently set attributes

pickupEntity

() chainable

Dummy function - required to allow Particles to be processed alongside Entity objects

Returns:

This

removeSprings

() chainable

Delete all springs associated with this Particle

Returns:

This

removeSpringsTo

(
  • item
)
chainable

Delete a named Spring object from this Particle

Parameters:

  • item String

    SPRINGNAME String

Returns:

This

set

(
  • items
)
chainable

Inherited from Base but overwritten in source\scrawlPhysics.js:426

Augments Base.set()

Allows users to set the Particle's position and velocity attributes using startX, startY, start, deltaX, deltaY, delta or velocity, velocityX, velocityY values (delta and velocity are synonyms for each other)

Parameters:

  • items Object

    Object consisting of key:value attributes

Returns:

This

stamp

() chainable

Undertake a calculation cycle iteration

Returns:

This

stampActions (not a function)

() chainable

stamp helper object

Returns:

This

update

() chainable

Alias for Particle.stamp()

Returns:

This

updateEuler

() private chainable

Calculation cycle engine

Returns:

This

updateImprovedEuler

() private chainable

Calculation cycle engine

Returns:

This

updateRungeKutter

() private chainable

Calculation cycle engine

Returns:

This

updateStart

() chainable

Dummy function - required to allow Particles to be processed alongside Entity objects

Returns:

This

Properties

area

Number

Projected surface area - assumed to be of a sphere - in square meters

Default: 0.03

comment

String

Comment, for accessibility

Default: ''

drag

Number

Air drag coefficient - assumed to be operating on a smooth sphere

Default: 0.42

elasticity

Number

Elasticity coefficient, where 0.0 = 100% elastic and 1.0 is 100% inelastic

Default: 1

engine

String

Particle calculator engine - a String value.

Current engines include: 'rungeKutter' (most accurate), 'improvedEuler', 'euler' (default)

Default: 'euler'

forces

Array

An Array containing FORCENAME Strings and/or force Functions

Default: []

group

String

Current group

Default: ''

load

Vector private

Load Vector - recreated at the start of every calculation cycle iteration

Default: Zero vector

mass

Number

Particle mass value, in kilograms

Default: 1

mobile

Boolean

Mobility flag; when false, particle is fixed to the Cell at its position attribute coordinate vector

Default: true

name

String

Unique identifier for each object; default: computer-generated String based on Object's type

order

Number

Current order

Default: 0

place

Vector

Position vector - assume 1 pixel = 1 meter

Vector attributes can be set using the following alias attributes:

  • place.x - startX or start.x
  • place.y - startY or start.y

Default: Zero values vector

radius

Number

Particle radius, in meters

Default: 0.1

springs

Array

An Array containing SPRINGNAME Strings

Default: []

timestamp

String

Creation timestamp

Default: ''

title

String

Title, for accessibility

Default: ''

type

String final

Inherited from Base but overwritten in source\scrawlPhysics.js:275

Default: 'Particle'

userVar

Object

Object in which user key:value pairs can be stored - clonable

Default: {}

velocity

Vector

Velocity vector - assume 1 pixel = 1 meter per second

Vector attributes can be set using the following alias attributes:

  • velocity.x - deltaX or delta.x
  • velocity.y - deltaY or delta.y

Default: Zero values vector