-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
142 lines (118 loc) · 4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html lang="en">
<head>
<title>OkLab visualisation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
background-color: #ccc;
color: #000;
}
a {
color: #f00;
}
</style>
</head>
<body>
<script type="module">
import * as THREE from 'https://unpkg.com/three/build/three.module.js';
import { OrbitControls } from 'https://unpkg.com/three/examples/jsm/controls/OrbitControls.js';
let camera, controls, scene, renderer;
init();
animate();
function init() {
renderer = new THREE.WebGLRenderer();
// renderer = new THREE.WebGLRenderer( { antialias: true } );
// renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x444444 );
const aspect = window.innerWidth / window.innerHeight;
camera = new THREE.OrthographicCamera( -10*aspect, 10*aspect, 10, -10, 1, 1000 );
camera.position.set( 0, 0, 10 );
controls = new OrbitControls( camera, renderer.domElement );
// controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
// controls.dampingFactor = 0.05;
// controls.screenSpacePanning = false;
// controls.minDistance = 100;
// controls.maxDistance = 500;
// controls.maxPolarAngle = Math.PI / 2;
buildScene(scene);
controls.update(); // must be called after any manual change
document.body.appendChild( renderer.domElement );
window.addEventListener( 'resize', onWindowResize, false );
}
function buildScene() {
const sphere = new THREE.SphereBufferGeometry(1, 4, 2);
function oklabColorPoint(L, a, b) {
const rgb = oklab_to_linear_srgb({L, a, b});
if (!rgb) {
return null;
}
const c1 = 10 * a;
const c2 = 10 * b;
const light = 10 * (L-0.5);
const scale = 0.05;
const color = new THREE.Color(rgb.r, rgb.g, rgb.b);
const material = new THREE.MeshBasicMaterial({color});
const mesh = new THREE.Mesh(sphere, material);
mesh.position.x = c1;
mesh.position.y = light;
mesh.position.z = c2;
mesh.scale.x = scale;
mesh.scale.y = scale;
mesh.scale.z = scale;
mesh.updateMatrix();
mesh.matrixAutoUpdate = false;
return mesh;
}
for (let L = 0; L < 1; L += 0.0249) {
for (let a = -1; a < 1; a += 0.01) {
for (let b = -1; b < 1; b += 0.01) {
const mesh = oklabColorPoint(L, a, b);
if (mesh) {
scene.add(mesh);
}
}
}
}
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
controls.update();
renderer.render( scene, camera );
}
// struct Lab {const L; const a; const b;};
// struct RGB {const r; const g; const b;};
function oklab_to_linear_srgb(c)
{
const l_ = c.L + 0.3963377774 * c.a + 0.2158037573 * c.b;
const m_ = c.L - 0.1055613458 * c.a - 0.0638541728 * c.b;
const s_ = c.L - 0.0894841775 * c.a - 1.2914855480 * c.b;
const l = l_*l_*l_;
const m = m_*m_*m_;
const s = s_*s_*s_;
const rgb = {
r: + 4.0767245293*l - 3.3072168827*m + 0.2307590544*s,
g: - 1.2681437731*l + 2.6093323231*m - 0.3411344290*s,
b: - 0.0041119885*l - 0.7034763098*m + 1.7068625689*s,
};
if (rgb.r<0||rgb.g<0||rgb.b<0||rgb.r>1||rgb.g>1||rgb.b>1) {return null};
// // if (rgb.r<0) {rgb.r = 0};
// // if (rgb.g<0) {rgb.g = 0};
// // if (rgb.b<0) {rgb.b = 0};
// // if (rgb.r>1) {rgb.r = 1};
// // if (rgb.g>1) {rgb.g = 1};
// // if (rgb.b>1) {rgb.b = 1};
// console.log(rgb);
return rgb;
}
</script>
</body>
</html>