Skip to content

Instantly share code, notes, and snippets.

@juliendehos
juliendehos / 1.js
Last active July 11, 2025 19:48
implementing optional parameters in three.hs
// In three.js, many functions have optional parameters.
// For example, the color constructor can take 0, 1, 2 or 3 parameters:
const c1 = new THREE.Color(0xff00ff);
const c2 = new THREE.Color();
const c3 = new THREE.Color(1,0,0);
const c4 = new THREE.Color('blue');
const c5 = new THREE.Color(new THREE.Color('green'));
// Here, the function is a bit complicated because the first parameter can have different types.
@juliendehos
juliendehos / 1_main.js
Last active July 11, 2025 09:12
on handling colors in three.hs
// in three.js, there are various ways to define a color:
// using an int
const light1 = new THREE.AmbientLight(0xff0000);
// using a predefined color (string)
const light2 = new THREE.AmbientLight("green");
// using a rgb triplet
const light3 = new THREE.AmbientLight(new THREE.Color(0,0,1));