Comments (3)
I was thinking maybe we should add a GUI section for additional physics options.
Maybe we treat empty void as fluid.
perhaps add gravity.
or even perform the calculations using different formulae.
and give particles more properties so they can be used in these options
I believe that would be cool.
from particle-life.
You can add it easily by changing this formula here:
F = (g * 1) / d;
Change the "1" with a Long parameter.
Every atom must have a mass, so change the property of them:
atom = (x, y, c, m) => {
return { x: x, y: y, vx: 0, vy: 0, color: c, mass: m };
};
from particle-life.
I have made a version with mass:
<canvas id="life" width="500" height="500"></canvas>
<script>
//Hunar Ahmad @ brainxyz
m = document.getElementById("life").getContext("2d");
draw = (x, y, c, s) => {
m.fillStyle = c;
m.fillRect(x, y, s, s);
};
atoms = [];
atom = (x, y, c, m) => {
return { x: x, y: y, vx: 0, vy: 0, color: c, mass: m };
};
random = () => {
return Math.random() * 400 + 50;
};
create = (number, color, mass) => {
group = [];
for (let i = 0; i < number; i++) {
group.push(atom(random(), random(), color, mass));
atoms.push(group[i]);
}
return group;
};
rule = (atoms1, atoms2, g) => {
for (let i = 0; i < atoms1.length; i++) {
fx = 0;
fy = 0;
for (let j = 0; j < atoms2.length; j++) {
a = atoms1[i];
b = atoms2[j];
dx = a.x - b.x;
dy = a.y - b.y;
d = Math.sqrt(dx * dx + dy * dy);
if (d > 0 && d < 80) {
F = (g * 1) / d;
fx += F * dx;
fy += F * dy;
}
}
a.vx = (a.vx + fx) * 0.5;
a.vy = (a.vy + fy) * 0.5;
a.x += a.vx;
a.y += a.vy;
if (a.x <= 0 || a.x >= 500) { a.vx *= -1; }
if (a.y <= 0 || a.y >= 500) { a.vy *= -1; }
}
};
yellow = create(200, "yellow", 0.8);
red = create(200, "red", 0.9);
green = create(200, "green", 1.1);
update = () => {
rule(green, green, -0.32);
rule(green, red, -0.17);
rule(green, yellow, 0.34);
rule(red, red, -0.1);
rule(red, green, -0.34);
rule(yellow, yellow, 0.15);
rule(yellow, green, -0.2);
m.clearRect(0, 0, 500, 500);
draw(0, 0, "black", 500);
for (i = 0; i < atoms.length; i++) {
draw(atoms[i].x, atoms[i].y, atoms[i].color, atoms[i].mass);
}
requestAnimationFrame(update);
};
update();
</script>
from particle-life.
Related Issues (20)
- [Feature request] Distance-based force HOT 8
- Option to import/export different models HOT 2
- [Feature request] Spawn or destroy pixels based off rules HOT 1
- Lua port HOT 4
- I've seen your video and I had to try myself :) HOT 1
- webgl version HOT 1
- [Feature request] Apply physics interaction
- Question: is this based on rule-set ? HOT 3
- another Go port HOT 1
- release binary version doesn't seems to use openMP HOT 1
- Mac M1 binary release HOT 1
- A random idea HOT 11
- migrating to openGL 4.3 and other various breaking change HOT 5
- QB64-PE port HOT 1
- [Feature Request] A) Import/Export Weights/Params - and B) Time-dependent functions as a parameter HOT 3
- Superfluid HOT 10
- Simultaneous attractive and repulsive forces in the same particle HOT 23
- 200+ FPS (on an simple laptop) HOT 12
- WTF HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from particle-life.