Git Product home page Git Product logo

proton's Introduction


Proton is a lightweight and powerful Javascript particle animation library. Use it to easily create a variety of cool particle effects.

Check out examples at http://drawcall.github.io/Proton/. The 3D version of the proton engine is here here. An available react version is here.

Features

  • Easy to use It takes only a dozen lines of code to create a particle animation effect.
  • Multiple effects Use Proton to create flames, fireworks, bullets, explosions, and more.
  • Any scene You can use it in frameworks such as react, vue, angular, and pixi.js, Phaser, etc.
  • Efficient rendering Its rendering efficiency is very high, you can render tens of thousands of particles in the page.
  • Simulated physics Proton can simulate various physical properties including gravity and Brownian motion.
  • Several renderers Proton provides a variety of renderers, of course you can also customize your own renderer
    • CanvasRenderer - Proton's canvas renderer
    • DomRenderer - Proton's dom renderer, supporting hardware acceleration.
    • WebGLRenderer - Proton's webgl renderer.
    • PixelRenderer - Proton's pixel renderer, It can implement pixel animation.
    • EaselRenderer - Easeljs proton renderer.
    • EaselRenderer - Pixi.js proton renderer.
    • CustomRenderer - Use a custom renderer that can be applied to any scene.

Documentation

See detailed documentation please visit https://projects.jpeer.at/proton/. Thank you very much @matsu7089 for writing a good tutorial.

Installation

Install using npm

Note: NPM package-name has been changed from proton-js to proton-engine

npm install proton-engine --save
import Proton from "proton-engine";

OR include in html

<script type="text/javascript" src="js/proton.min.js"></script>

Usage

Proton is very simple to use, a dozen lines of code can create a particle animation.

const proton = new Proton();
const emitter = new Proton.Emitter();

//set Rate
emitter.rate = new Proton.Rate(Proton.getSpan(10, 20), 0.1);

//add Initialize
emitter.addInitialize(new Proton.Radius(1, 12));
emitter.addInitialize(new Proton.Life(2, 4));
emitter.addInitialize(new Proton.Velocity(3, Proton.getSpan(0, 360), "polar"));

//add Behaviour
emitter.addBehaviour(new Proton.Color("ff0000", "random"));
emitter.addBehaviour(new Proton.Alpha(1, 0));

//set emitter position
emitter.p.x = canvas.width / 2;
emitter.p.y = canvas.height / 2;
emitter.emit(5);

//add emitter to the proton
proton.addEmitter(emitter);

// add canvas renderer
const renderer = new Proton.CanvasRenderer(canvas);
proton.addRenderer(renderer);

Remarks

  • Proton.Span (or Proton.getSpan) is a very important concept of the Proton engine, it's everywhere. If you understand its usage, you can create almost any desired effect!

  • If you want to create wind, rain, or snow, etc, you can use the emitter.preEmit method to pre-render the scene.

  • Use Proton.Body and Proton.Color at the same time. I suggest you'd better use the WebGLRenderer not CanvasRenderer.

  • Added Proton.Cyclone behavior, you can make vortex effects with Cyclone. Demo please check here.

  • proton.fps In most cases, you don't need to set this property. You can set this property when the game engine has fixed fps or some browsers have a higher refresh rate.

  • Use Euler integration calculation is more accurate (default false) Proton.USE_CLOCK = false or true;.

Proton has now been upgraded to the v4 version. Performance has been greatly improved and api also has some improvements. For more details, please check here.

Building

node is a dependency, use terminal to install it with:

git clone git://github.com/drawcall/Proton.git

...
npm install
npm run build

And run example

npm start
//vist http://localhost:3001/example/

Changelog

Detailed changes for each release are documented in the release notes.

License

Proton is released under the MIT License. http://www.opensource.org/licenses/mit-license

proton's People

Contributors

aholla avatar cha0s avatar dependabot[bot] avatar drawcall avatar fantasticsoul avatar frandias avatar holyzfy avatar hyandell avatar jpeer264 avatar rodritter avatar xucz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

proton's Issues

Cannot Add Renderer: Proton is not defined

Hi,

Have been trying to figure out what's the issue for a while but am stuck;
I'm trying to setup a real quick/simple PoC with Angular on Stackblitz

I'm basically reusing the QuickStart code from Proton's Readme.md wrapped in a component.
Everything looks fine, except when the code reaches this.proton.addRenderer(renderer); where it fails with a Proton is not defined error

Thinking it could be related to a Stackblitz issue (seeing how it complains about not being able to find the module, although it is clearly false), I created a brand new Angular-Cli project locally, and am having a different error: _1.default is not a constructor.

I tried import Proton from 'proton-js' as well as import {default as Proton} from 'proton-js' and import * as Proton from 'proton-js'; All three cases fails

TLDR:

There seem to be a problem with how the ProtonJs DEFAULT export is causing issues with (I guess) Webpack and how it handles default export (admittedly it may be Webpack/Angular-Cli issue but seeing as both uses tons of libraries likely to also export default modules, and how Proton seems to have had a related change recently...)

Repulse zone / area

Hello,

Thank you for this amazing library!

I wonder if it would be possible to set a Proton zone as a repulsive area. I would like to have all the canvas filled with particles and some shapes inside it which are repulsive.

I've tried to use the CrossZone property but for example if I set a CircleZone as a CrossZone "bound" the particles are only staying inside the CircleZone, and I would like to have them outside it. I've also tried CrossZone "collision" but I can't make it work.

Cheers,
Paul

Can be integrated with phaser?

Is possible to add proton to a custom group in phaser?

(I also have a question: is this project dead? I don't see much activity)

Emitter size

I'd like to suggest the ability for an emitter to define a rectangle in which particles are created at random points, rather than a single point

how to stop the emitter?

I try to stop the emitter,I use the cancelAnimationFrame,but by this,the picture just freeze.
I'm a fresh in this,I want to stop the next emitter.Pleae help me.

Custom Renderer

Is it possible to use a custom rendering engine yourself ?

Initial particle size

Hello,
Is there a way to change the initial size of the particles so they don't look the same size when the emitter starts?
I'm trying
emitter.addInitialize(new Proton.Body(image, new Proton.Span(1, 100), new Proton.Span(1, 100)));
but the size is always the same.
Thanks in advance.

Size for emiiter

The ability for an emitter to define a rectangle in which particles are created at random points, rather than a single point.
How this is being handled with random points?
Some suggestion please, Newbie here

requestAnimationFrame polyfill should either be removed or safe for server

I want to be able to run Proton on a server, where window doesn't exist. You can still simulate particles even if you don't actually render them.

This is currently not possible, as Proton does import './polyfill/requestAnimationFrame';, which throws something like:

.../node_modules/proton-js/src/polyfill/requestAnimationFrame.js:9
		for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
                                         ^
ReferenceError: window is not defined
    at window (.../node_modules/proton-js/src/polyfill/requestAnimationFrame.js:9:42)
    at .../node_modules/proton-js/src/polyfill/requestAnimationFrame.js:6:3
    at .../node_modules/proton-js/build/proton.min.js:10:84
    at Object.<anonymous> (.../node_modules/proton-js/build/proton.min.js:10:149)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)

on a server environment.

I don't see that requestAnimationFrame is actually used anywhere in the engine. Only the examples.

Pixi.js: Emit 'once' true does not destroy/remove the sprite/graphic from the Pixi Container.

Using Pixi.js v 5.2.1, my Pixi Container remains littered with destroyed particles. I copy pasted this example into my environment and it works fine.

However if I try to use emitter.emit('once', true), as used in this example, my container does not remove the now dead particles. The particles just hang static in the canvas - as far as proton is concerned they're dead - but not removed from Pixi.

Any help please?

非常需要文档!谢谢!~

您好,同为flash开发者。您的类库看起来不错。希望能够抽空完善下文档。。谢谢。。示例代码只能满足基本的使用。。。

Proton emitter - DOM Renderer - particles with ID names‏

Hey Im using your proton emitter for the DOM Renderer.

Simple question: How can I emit particles with ID names?

var particle = document.getElementById("particle")
emitter.addInitialize(new Proton.ImageTarget(particle));

It would be amazing if your engine can do so.

Let me know

lineRect bug

if lineRect use 'getSymmetric' , and then sometimes particle move following line.

it is happened direction changed if particle do not go outside of line checking(this.getDistance(p.x, p.y) <= radius) when next frame

and then particle is moved following on line

how do check changed direction

i think direction is changed , there is one more checking about it's changed

getImageData error after context.drawImage

In proton we have following code:
getImageData:function(a,b,c){
a.drawImage(b,c.x,c.y);
var d=a.getImageData(c.x,c.y,c.width,c.height);
a.clearRect(c.x,c.y,c.width,c.height);
return d
}

And I get error @ getImageData, if remove the line of drawImage everything is OK.
As I'm not familiar with html and js, could any one give me some advice?
MUCH THANKS !

Readme incorrect

Noting that the Readme indicates that "LicenseFinder" is licensed under the MIT rather than Proton.

It's also common to have a LICENSE file in the root of the package with the specific MIT license text that applies and who the copyright holders are.

custom behaviour function - change color of single particle on applyBehaviour

Hello, I just stumbled upon an interresting problem.

Let me describe the frame:

Split the canvas in 4 parts with a horizontal and vertical centered line. When a particle enters one of the 4 areas, it should change it's color.

I tried using particle.color = xxx, I tried adding a behaviour with particle.addBehaviour(new Proton.Color(color, color));
Any ideas?

emitter.addBehaviour(customBehaviour());

customBehaviour = function() {
return {
initialize : function(particle) {
particle.alpha = 0;
},
applyBehaviour : function(particle) {
if (particle.energy <= particle.age/10) {
particle.alpha = particle.energy;
} else {
particle.alpha = particle.age/10;
}
var cx = canvas.width / 2,
cy = canvas.height / 2,
color;
if (particle.p.x <= cx) {
color = "#ffffff";
if (particle.p.y > cy) {
color = "#ff0000";
}
} else {
color = "#00ff00";
if (particle.p.y > cy) {
color = "#0000ff";
}
}
particle.color = color;
}
}
}

Thanks for your help!

Feature suggestion: Multiple interpolation points

I have started using proton in my game and it's going pretty nicely! I've managed to set it up together with pixi and I haven't had any problems thus far.

However, a feature I think would really be helpful is the ability to add multiple points to a transition, not just two.

For instance: say I want to display a gentle smoke puff. I want the particles to smoothly fade in, stay at 100% alpha for a while and then disappear.

This would require multiple points inside Proton.Alpha, for instance -- each with its own value, interpolation and life. Example syntax: emitter.addBehaviour(new Proton.Alpha([new Proton.AlphaPoint(0.0, 'easeInOutCubic'), new Proton.AlphaPoint(1.0, 'easeInOutCubic'), new Proton.AlphaPoint(0.0, 'easeInOutCubic')]));.

How to create a Force at a particular position?

Hi there - first of all: amazing library! It's a little hard to spot all the potential (hence this issue for example) without more documentation, but it's clear that you've built some really powerful concepts that when put together should be able to achieve just about anything; so kudos!

On to my particular question: I'm trying to build a simple wind animation of particles. What I have is a grid of wind data, so for example imagine on a canvas of 1000x1000 that I would have points at every 100x and 100y. For each point, I have the U and V components of the wind; ie the fx and fy for particles.

So for Proton, I figured it should be easy if I could add a behaviour similar to a GravityWell, but then for a particular force (rather than just gravity). Eg Proton.ForcePosition(targetPos.x, targetPos.y, fx, fy).

But the Force behaviour only has fx and fy... no position? Is there a way to combine PointZones with the Force behaviour to achieve what I'm trying to do here?

(eg so that the particles flow through the canvas similar to windy.com for example)

fabric js

Can you give sample example for render the proton effects to canvas in fabric.js?

Update the image dynamically

Hey,

I am playing around with the example /render/pixel/google.html.
Is it possible to change the images dynamically?

Regards

npm

please add package.json

npm users need to use this fork which does not include latest updates.

thankyou for an amazing package 👍

Spiderweb is not interactive

I've copy/pasted the proton spider web from this pen: https://codesandbox.io/s/proton-spiderweb-0fzi4.

In the pen it is interactive. but in my project not at all. Lines don't move when the cursor gets close to them, nothing happens on click.

I am using it in a React component, surrounded by a div and also after the tag there are some other divs.
I've tried removing the other divs but it still does not work, so I suppose the issue isn't there. Other than that, all the code is exactly as in the pen.

I am also using the same version of proton-engine and raf-manager as in the pen.

Anyone having any idea what could be causing this?
Thank you!

rendering problem

Dear A-jie,

How are you? My name is Jacky, I've tried to use your proton.js to add a particle effect into my webpage, it works fine in FireFox, mobile Safari & mobile Chrome, but not sure why there is a problem of my page when rendering in Mac desktop version Safari and Chrome - but your demo page still looks fine under these 2 platforms!

Here is my link:

https://www.sharpmotion.com.hk/
https://www.sharpmotion.com.hk/about

Attached is the screen shot
screenshot

Thanks a lot!

Jacky

Velocity/Speed of the particles doubles on every page load

if i am loading the particles using a script on a page route. Every time i route to that page, the speed of the particles double, than what it was before. Even if i destroy the proton element or remove all emitters and behaviours after page unload

Is there a way to get particles to respond to page resize?

Hey,

I have a project based on this demo where you render an Image to Canvas then run Proton.ImageZone() to get particle zones.

Problem is, no matter what I try, I can't get the particles to respond to a window resize, and recenter in the canvas. What I'm trying is:

On window resize, I set an origin object with x and y values of half the window width and height.

function customToZoneBehaviour() {
    return {
        initialize : function(particle) {
            particle.old.origin = {
                x: origin.x,
                y: origin.y
            };

            particle.R = Math.random() * 10;
            particle.Angle = Math.random() * Math.PI * 2;
            particle.speed = Math.random() * (-2) + 1;
            particle.zones = zones.map(function(o) {
                return o.getPosition().clone();
            });
        },
        applyBehaviour : function(particle) {
            particle.v.clear();
            particle.Angle += particle.speed;
            zoneX = particle.zones[curZone % totalZones].x + particle.R * Math.cos(particle.Angle);
            zoneY = particle.zones[curZone % totalZones].y + particle.R * Math.sin(particle.Angle);
            particle.p.x += (zoneX - particle.p.x) * 0.15;
            particle.p.y += (zoneY - particle.p.y) * 0.15;

            //TODO: responsive to center
            particle.p.x = particle.p.x + ((origin.x - particle.old.origin.x) / 2);
        }
    };
}

This always moves too far in the correct direction. I suspect because it is transitioning and not simply moving to the desired coordinates.

So is there a way to move a particle to new coordinates without a transition?

Thanks

pixi renderer outdated

Hi,

pixirenderer should work with pixi4? i am not able to make it work properly, there are a lot of glitch, mask issue, performance problem and so on.

can you confirm that it's supposed to work and i have to dig more on my side?

Removing Emitter leaves particles

Removing Emitter stops updating emitted particles and they are left on screen.

I expect particles to die normally after emitter is removed.

I have done a workaround that calls Emitter.stop() and waits for max lifetime and then calls Emitter.destroy()

Rotate behavior: unexpected result

I've tried to use particle rotation behaviour, and suddenly found unexpected results.
After digging in code I've found a Rotate method "applyBehaviour" that has

if (this.style === 'to' || this.style === 'TO' || this.style === '_') {
particle.rotation += particle.data.rotationB + (particle.data.rotationA - particle.data.rotationB) * this.energy
}...

It has "+=" operator, but "=" expected here

So it's probably a bug.

Controlling the max number of particles

Hi, this is really impressive work :)
I'm trying to write a ParticleDesigner parser for proton, but didn't find how to control the particle number ... is there a way to do it ?

I know I can have some control with Proton.Rate but what I want is ti force oldest particles to die when the total displayed particles reach a given number (or span)

Rotate is break if I use Color

I use rotate and it works fine
emitter.addBehaviour(new Proton.Rotate( new Proton.Span(0, 360), 2, "to" ));

but once I add Color, Rotate stops working


emitter.addBehaviour(new Proton.Rotate( new Proton.Span(0, 360), 2, "to" ));
emitter.addBehaviour(new Proton.Color('ff0000', 'ff0000'));

change speed

Hello. Incredible work!

Using the 'drugs' sample, how to we slow the speed down to about 25%?

proton = new Proton;
  emitter = new Proton.Emitter();
  emitter.rate = new Proton.Rate(new Proton.Span(5, 10), new Proton.Span(.05, .2));
  emitter.addInitialize(new Proton.ImageTarget(image));
  emitter.addInitialize(new Proton.Mass(1));
  emitter.addInitialize(new Proton.Life(2, 4));
  emitter.addInitialize(new Proton.V(new Proton.Span(0.5, 1.5), new Proton.Span(0, 360), 'polar'));
  emitter.addBehaviour(new Proton.Alpha(1, [.7, 1]));
  emitter.addBehaviour(new Proton.Scale(1, 0));
  emitter.addBehaviour(new Proton.Color('random', '#9e24e7', Infinity, Proton.easeInSine));
  emitter.p.x = canvas.width / 2;
  emitter.p.y = canvas.height / 2;
  emitter.emit();
  proton.addEmitter(emitter);
  renderer = new Proton.Renderer('canvas', proton, canvas);
  renderer.start();

^---- Which parameter to modify above?

Proton.destory

The destroy function of Proton have a typo (destory instead of destroy)

Havin Trouble on React js installation

@i:~$ sudo npm install -g create-react-app
[sudo] password for rahul:
/usr//npm-global/bin/create-react-app -> /usr/npm-global/lib/node_modules/create-react-app/index.js

  • [email protected]
    updated 1 package in 18.296s
    @i:~$ create-react-app hello
    create-react-app: command not found

please add documentation to your site

please add documentation to your site.
its hard to use this amazing library without docs.

  1. in Proton.js -> function destory has misprint -- must be renamed to destroy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.