11
u/Volfegan Nov 07 '19
Amazing. The actual visual running this on Processing is even more beautiful than the video.
3
Nov 07 '19
Yeah, it's a nightmare trying to get a good video of pixel/point stuff like this. You should see what Twitter's compression did to it.
1
3
Nov 07 '19
Lerped colour version with extra mass/planet/sun/white dwarf/black hole/whatever in the middle too: https://youtu.be/l2e9yiqqOns
2
u/alphabet_street Nov 08 '19
Man give it the ol' smooth(8); treatment as well - incredible quality increase!
2
4
3
u/lostPixels Nov 08 '19
This is awesome! What are the f numbers that you're using (like 9f). I've never seen that before.
3
u/ijidau Nov 08 '19
f = Float. Ensuring it's a float and not an integer.
1
u/lostPixels Nov 08 '19
Oh cool, thanks! Little tips like this make Processing easier and easier to use.
2
2
1
1
1
u/JadoubeStudios Nov 09 '19
Would it be possible to add camera work to that?
1
u/Seraphaestus Nov 15 '19
Sure, this seems to work for giving a bit of rotation around the center
float r = -width/2f; PVector eye = new PVector(0, -height/2f, 150f); PVector center = new PVector(0f, 0f, 0f); PVector up = new PVector(0f, 1f, 0f); eye.x += r * cos(TAU * mouseX / width); eye.z += r * sin(TAU * mouseX / width); camera(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z);
1
u/Spiralwise Nov 14 '19
I've adapted the code for p5.js :
/** Original code from u/Deadfev
* url: https://www.reddit.com/r/processing/comments/dswnx6/a_galaxy_in_35_lines_of_code/
*/
const ringPop = 50;
const starPop = 3000;
var rings = [];
function setup() {
createCanvas(1200, 600, WEBGL);
blendMode(ADD); // Actually, blendMode doesnt work properly on WebGL.
camera(-width/2, -height/2, 150, 0, 0, 0, 0, 1, 0);
strokeWeight(0.1);
let innerRad = 1.0,
outerRad = 9.0,
inc = 1.0;
for (let ringIndex = 0; ringIndex < ringPop; ++ringIndex) {
append(rings, []);
let currentRing = rings[rings.length - 1];
for (let starIndex = 0; starIndex < starPop; ++starIndex) {
let a = random(0, 1) * TWO_PI;
let r = sqrt(random(sq(innerRad), sq(outerRad)));
append(currentRing, createVector(r * cos(a), r * sin(a), random(-inc, inc)));
}
innerRad += inc;
outerRad += inc * 1.5;
inc += 1;
}
}
function draw() {
background(0);
for (let ringIndex = 0; ringIndex < ringPop; ++ringIndex) {
push();
let c = lerpColor(color(73, 115, 161), color(157, 47, 77), ringIndex/ringPop);
stroke(red(c), green(c), blue(c), 00);
rotateY((TWO_PI/(ringIndex*ringIndex+1)*frameCount)/10);
rotateX(1.45);
drawRing(ringIndex);
pop();
}
}
function drawRing(index) {
let currentRing = rings[index];
beginShape(POINTS);
for (let starIndex = 0; starIndex < currentRing.length; ++starIndex)
vertex(currentRing[starIndex].x, currentRing[starIndex].y, currentRing[starIndex].z);
endShape();
}Here's how it looks : https://editor.p5js.org/Spiralwise/present/hdxED_vfW
Unfortunately :
blendModedoesn't work properly on WebGL. So, it looks pale.There is no PShape like Processing. So I have to build my shape at each frame. So the framerate is much lower than Processing.
1
Mar 26 '25
This is ridiculous of me to post, especially FIVE YEARS late... But you aren't getting spiral arms because you aren't accounting for fucking dark matter. I bet you've made a great gravitational simulation between particles, and yet indeed your simulation is not meeting observations. This is exactly what lead to the "discovery" of "dark matter". For SOME reason, that still nobody can explain, there's more mass in the regions surrounding the galaxy. You might get better results if you include invisible but massive particles that for some reason stick more towards the outside of the galaxy. lmk if you find out why
1
51
u/[deleted] Nov 07 '19
And the code (bonus colour version!)