Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
jcponce committed Aug 21, 2024
1 parent 3af9974 commit 5a29e7d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 22 deletions.
24 changes: 12 additions & 12 deletions threejs/galaxy/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function initializeScene() {
parameters.spin = 1
parameters.randomness = 0.5
parameters.randomnessPower = 3
parameters.insideColor = '#ff6030'
parameters.outsideColor = '#1b3984'
parameters.insideColor = '#2e74ff'
parameters.outsideColor = '#6de9e7'

let geometry = null
let material = null
Expand Down Expand Up @@ -75,15 +75,15 @@ function initializeScene() {
// Position
const radius = Math.random() * parameters.radius

const branchAngle = (i % parameters.branches) / parameters.branches * Math.PI * 2
// const branchAngle = (i % parameters.branches) / parameters.branches * Math.PI * 2

positions[i3] = Math.cos(branchAngle) * radius
positions[i3 + 1] = 0
positions[i3 + 2] = Math.sin(branchAngle) * radius
// positions[i3] = Math.cos(branchAngle) * radius
// positions[i3 + 1] = 0
// positions[i3 + 2] = Math.sin(branchAngle) * radius

// positions[i3] = (Math.random() - 0.5) * 5
// positions[i3 + 1] = (Math.random() - 0.5) * 5
// positions[i3 + 2] = (Math.random() - 0.5) * 5
positions[i3] = (Math.random() - 0.5) * 5
positions[i3 + 1] = (Math.random() - 0.5) * 5
positions[i3 + 2] = (Math.random() - 0.5) * 5


// Randomness
Expand Down Expand Up @@ -174,9 +174,9 @@ function initializeScene() {
*/
// Base camera
const camera = new THREE.PerspectiveCamera(75, sizes.width / sizes.height, 0.1, 100)
camera.position.x = 3
camera.position.y = 3
camera.position.z = 3
camera.position.x = 5
camera.position.y = 5
camera.position.z = 5
scene.add(camera)

// Controls
Expand Down
54 changes: 44 additions & 10 deletions threejs/galaxy/shaders/galaxy/vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,33 @@ attribute vec3 aRandomness;

varying vec3 vColor;

vec3 thomas(vec3 position, float dt) {
float speed = 400.0;
float dx = (sin(position.y) - 0.208186 * position.x) * speed;
float dy = (sin(position.z) - 0.208186 * position.y) * speed;
float dz = (sin(position.x) - 0.208186 * position.z) * speed;

position.x += dx * dt;
position.y += dy * dt;
position.z += dz * dt;

return position;
}


void main(){
vec4 modelPosition = modelMatrix * vec4(position, 1.0);
//vec4 modelPosition = modelMatrix * vec4(position, 1.0);

// Spin
float angle = atan(modelPosition.x, modelPosition.z);
float distanceToCenter = length(modelPosition.xz);
float angleOffset = (1.0 / distanceToCenter) * uTime * 0.5;
angle +=angleOffset;
modelPosition.x = cos(angle)* distanceToCenter;
modelPosition.z = sin(angle) * distanceToCenter;
// // Spin
// float angle = atan(modelPosition.x, modelPosition.z);
// float distanceToCenter = length(modelPosition.xz);
// float angleOffset = (1.0 / distanceToCenter) * uTime * 0.5;
// angle +=angleOffset;
// modelPosition.x = cos(angle)* distanceToCenter;
// modelPosition.z = sin(angle) * distanceToCenter;

// Randomness
modelPosition.xyz += aRandomness;
// // Randomness
// modelPosition.xyz += aRandomness;

// // Lorenz system
// vec3 pos = modelPosition.xyz; // Introduce some initial randomness
Expand All @@ -41,6 +54,27 @@ void main(){
// }

// modelPosition.xyz = pos;

// Apply the Lorenz system
// float dt = 1.01 * uTime; // Scale time for better control
// vec3 newPosition = thomas(modelPosition.xyz, dt);
// modelPosition = vec4(newPosition, 1.0);

// Apply the Thomas attractor directly to the initial position
vec3 newPosition = position;

// Time factor for attractor dynamics
float totalTime = uTime * 0.0001; // Adjust this to control speed
for (int i = 0; i < 100; i++) { // Increase the iteration count for smoother paths
newPosition = thomas(newPosition, totalTime);
}

// Damping to prevent expansion
//float damping = 0.79; // Damping factor (less than 1 to reduce expansion)
//newPosition *= damping;


vec4 modelPosition = modelMatrix * vec4(newPosition, 1.0);


vec4 viewPosition = viewMatrix * modelPosition;
Expand Down

0 comments on commit 5a29e7d

Please sign in to comment.