Skip to content

icyaj/ShootingParticles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shooting Particles

To view the global live version example please navigate to --> https://shooting-particles.herokuapp.com/.

The local version example is instead run by running 'npm start' in the terminal accessed by --> http://localhost:8080/

Table of Contents

ShootingParticles

A class that encompasses the toolbar, canvas including the draw-space.

Parameters

  • initGravity boolean The initial boolean value for the gravity feature. (optional, default true)
  • initRandomise boolean The initial boolean value for the randomise feature. (optional, default false)
  • initViscosity number The initial value for the viscosity. (optional, default 0)
  • initParticleColor string The initial particle colour. (optional, default 'white')
  • initMaximumParticles number The maximum amount of particles allowed in the space at one time. (optional, default 200)

keyPressed

Checks to see if the C key is pressed for clearing the particles.

clearParticles

Clears all particles

draw

The draw function for the ShootingParticles.

createToolbar

Creates the toolbar which includes: the three sliders (colour, viscosity and size) and the two toggle buttons (gravity and randomise).

positionToolbar

Positions the toolbar in respect to the current window size. Used when the toolbar is initially setup and when the window is re-sized.

createText

Draws the toolbar text onto the screen.

changeGravity

The function that is called when the gravity button is toggled. Sets the gravity variable to true when false and vice versa. Also changes the gravity button colour when toggled.

changeRandomise

The function that is called when the randomise button is toggled. Sets the randomise variable to true when false and vice versa. Also changes the randomise button colour when toggled.

setVariables

This is called from the draw function to set each of the colour, size & viscosity variables depending on the value on the sliders. If randomise is set to true the value of the colour & size slider is incremented.

createParticle

Creates a new particle. Called when the mouse is pressed or dragged. A new particle is created as long as the cursor is outside of the toolbar. Also deletes the oldest particle if the particle limit is reached.

gravity

Sets the gravity property.

Parameters

  • newGravity boolean The boolean variable to set the gravity on or off.

Returns any nothing

gravity

Gets the boolean value of the gravity property.

Returns boolean this._gravity - Returns the boolean value of the gravity property.

randomise

Sets the randomise property.

Parameters

  • newRandomise boolean The boolean variable to set the randomise on or off.

Returns any nothing

randomise

Gets the boolean value of the randomise property.

Returns boolean this._randomise - Returns the boolean value of the randomise property.

viscosity

Sets the viscosity property.

Parameters

  • newViscosity number The number variable to set the value of the viscosity.

Returns any nothing

viscosity

Gets the number value of the viscosity property.

Returns number this._gravity - Returns the number value of the viscosity property.

particleColor

Sets the particle colour property.

Parameters

  • newParticleColor string The string variable to set the active colour to be displayed.

Returns any nothing

particleColor

Gets the string value of the particle colour property.

Returns string this._particleColor - Returns the string value of the particle colour property.

maximumParticles

Sets the maximum particles property.

Parameters

  • newMaximumParticles number The number variable to set the maximum number of particles active on the canvas.

Returns any nothing

maximumParticles

Gets the number value of the maximum particles property.

Returns number this._maximumParticles - Returns the number value of the maximum particles property.

particles

Sets the particles list property.

Parameters

  • newParticles array The array that contains all the particle classes active on the board.

Returns any nothing

particles

Gets the array of the particles property.

Returns array this._particles - Returns the array of the particles property.

Particle

A class that represents the Particle component.

Parameters

  • x number The initial x co-ordinate for the particle. (optional, default 0)
  • y number The initial y co-ordinate for the particle. (optional, default 0)
  • velX number The initial velocity with respect to the x-axis for the particle. (optional, default random(-.1,.1))
  • velY number The initial velocity with respect to the y-axis for the particle. (optional, default random(-.1,.1))

move

Moves the particle depending on it's current position and velocities.

display

Draws the particle onto the canvas.

handleInteractions

Updates the particle velocity depending on the distance to the other particles and if it is in close proximity to the mouse.

xPos

Sets the x position property.

Parameters

  • newXPos number The number variable to set the value of the x position.

Returns any nothing

xPos

Gets the number value of the x position property.

Returns number this._xPos - Returns the number value of the x position property.

yPos

Sets the y position property.

Parameters

  • newYPos number The number variable to set the value of the y position.

Returns any nothing

yPos

Gets the number value of the y position property.

Returns number this._yPos - Returns the number value of the y position property.

xVel

Sets the x velocity property.

Parameters

  • newXVel number The number variable to set the value of the x velocity.

Returns any nothing

xVel

Gets the number value of the x velocity property.

Returns number this._xVel - Returns the number value of the x velocity property.

yVel

Sets the y velocity property.

Parameters

  • newYVel number The number variable to set the value of the y velocity.

Returns any nothing

yVel

Gets the number value of the y velocity property.

Returns number this._yVel - Returns the number value of the y velocity property.

mass

Sets the mass property.

Parameters

  • newMass number The number variable to set the value of the mass.

Returns any nothing

mass

Gets the number value of the mass property.

Returns number this._mass - Returns the number value of the mass property.

color

Sets the particle colour property.

Parameters

  • newColor string The string variable to set the colour of the particle.

Returns any nothing

color

Gets the string value of the particle colour property.

Returns string this._color - Returns the string value of the particle colour property.

Sketch from https://www.openprocessing.org,

Called: Jelly Sim,

Original Sketch By: nebulaeandstars,

Adapted Sketch By: hkxx26

Link: https://www.openprocessing.org/sketch/587065,

Licence: https://creativecommons.org/licenses/by-sa/3.0/

Meta

  • license: CC-BY-SA-3.0

About

A Fun Interactive Particle Simulator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published