-
Notifications
You must be signed in to change notification settings - Fork 1
/
unsigned.html
87 lines (71 loc) · 1.72 KB
/
unsigned.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
<html>
<body>
<canvas id="myCanvas" width="1080" height="1080"></canvas>
<script>
//
// This is software is provided as-is for educational purposes only
//
// If you want to generate them, you need to write this section on the fly
const np=5
const di=[0,0,0,0,0] // distribution 0 CDF, 1 Normal
const ro=[0,0,270,90,90] // rotation
const cl=[1,0,0,2,1] // color 0 red, 1 green, 2 blue
const mu=[1,2,2,2,4] // multipliers
// Consts
const n=1080 // dim
const m=0.5*(n-1) // mean
const s=n/6.0 // st.dev
// Generate the gaussian and sum gaussian
const p1=new Float64Array(n);
const c1=new Float64Array(n);
let t=0;
for(let i=0;i<n;i++){
p1[i]=Math.exp(-0.5*((i-m)*(i-m)/(s*s)))
c1[i]=p1[i]+t
t=c1[i]
}
// Renormalize the summed one
let mx=1.0/c1[n-1];
for(let i=0;i<n;i++){ c1[i]*=mx }
// Make the colors from parameters
const c=new Float64Array(n*n*3);
let x,y;
for(let k=0;k<np;k++){ // params
for(i=0;i<n;i++){
for(j=0;j<n;j++){
x=i
y=j
if (ro[k]===90) {x=j;y=n-i-1;}
else if(ro[k]===180){x=n-i-1;y=n-j-1;}
else if(ro[k]===270){x=n-j-1;y=i;}
let v=(di[k]===0)?c1[i]:p1[i]
let l=cl[k] + 3*(x+n*y)
c[l]=c[l]+mu[k]*v
}
}
}
// Generate the image
const d=document.getElementById('myCanvas').getContext('2d');
d.beginPath();
d.rect(0,0,n,n);
d.fillStyle="#000000";
d.fill();
const cf=new Array(n*n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
d.beginPath();
d.rect(i,j,1,1);
k=3*(i+n*j)
d.fillStyle = "#"+(
"000000" + (
((255.0 * (c[k+0] % 1)) <<16) +
((255.0 * (c[k+1] % 1)) <<8) +
((255.0 * (c[k+2] % 1)) <<0)).toString(16)
).substr(-6)
d.fill();
}
}
// Done!
</script>
</body>
</html>