-
Notifications
You must be signed in to change notification settings - Fork 1
/
zebra-lines.js
74 lines (41 loc) · 1.24 KB
/
zebra-lines.js
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
// Procedural Equirectangular Textures
// Zebra Lines Pattern
//
// defaults = {...} - default parameters
// pattern( ... ) - calculate color of pixel
// texture( params ) - generate a texture
// material( ... ) - material shader fix
import { Vector3 } from "three";
import { retexture, map } from "pet/texture-generator.js";
var defaults = {
$name: 'Zebra lines',
width: 512,
height: 256,
scale: 60,
angle: 0,
};
var vec = new Vector3( );
function pattern( x, y, z, color, options, /*u, v, px, py*/ ) {
vec.set( x, y, z );
var a = vec.angleTo( options.up ),
sin = Math.sin( options.scale*a );
var k = map( sin, 0, 1, -options.scale/500, options.scale/500 );
color.setHSL( 0, 0, k );
}
function options( params ) {
var angle = ( params.angle ?? defaults.angle )*Math.PI/180;
return {
scale: map( params.scale ?? defaults.scale, 151, 2 ),
up: new Vector3( 0,
1e-6*Math.round( 1e6*Math.cos( angle ) ),
1e-6*Math.round( 1e6*Math.sin( angle ) ) ),
width: params.width ?? defaults.width,
height: params.height ?? defaults.height,
};
}
function texture( ...opt ) {
return retexture( opt, defaults, options, pattern );
}
export { pattern, defaults, texture };
export { material } from "pet/texture-generator.js";