Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
jcponce committed Jul 2, 2024
1 parent 44f35fe commit 57be4d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions threejs/pendulums/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function init() {
renderer.setSize(window.innerWidth, window.innerHeight);
});

let colorBack = 0xbbe5edff;
let colorBack = 0x0000f;
scene.background = new THREE.Color(colorBack);

const light = new THREE.AmbientLight(0xdddddd, 0.2);
Expand All @@ -55,7 +55,7 @@ function init() {
const ground = createGround();
scene.add(ground);

scene.fog = new THREE.Fog(colorBack, 1, 80);
scene.fog = new THREE.Fog(colorBack, 1, 40);

const pendulums = [];
for (let i = 0; i < 12; i++) {
Expand Down
11 changes: 6 additions & 5 deletions threejs/pendulums/pendulum.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as THREE from 'three';

function createStringMesh(scene) {
const geometry = new THREE.CylinderGeometry(0.005, 0.005, 8);
const material = new THREE.MeshStandardMaterial({ color: 0x222222, roughness: 0, metalness: 0.2 });
const geometry = new THREE.CylinderGeometry(0.025, 0.025, 8);
const material = new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 0, metalness: 0.2 });
const string = new THREE.Mesh(geometry, material);
scene.add(string);
return string;
Expand Down Expand Up @@ -43,7 +43,7 @@ function createBallMesh(scene, hue) {
return ball;
}

export class Pendulum {
class Pendulum {

constructor(stringMesh, ballMesh, frequency, amplitude) {
this.string = stringMesh;
Expand All @@ -53,8 +53,9 @@ export class Pendulum {
}

update(totalTime) {
this.string.rotation.z = this.amplitude * Math.cos((this.frequency * totalTime) / 1000);
this.ball.rotation.z = this.amplitude * Math.cos((this.frequency * totalTime) / 1000);
let speed = 750;
this.string.rotation.z = this.amplitude * Math.cos((this.frequency * totalTime) / speed);
this.ball.rotation.z = this.amplitude * Math.cos((this.frequency * totalTime) / speed);
}
}

Expand Down

0 comments on commit 57be4d6

Please sign in to comment.