xxxxxxxxxx
91
const r = 100; //pupil radius [pixels]
//let theta; //field angle [rad]
const layeralt = [100, 200, 300, 400];
const freq = [0.02, 0.02, 0.02, 0.02];
const strength = [80, 80, 80, 80];
let alpha1;
let alpha2;
function setup() {
theta = 20 * PI / 180;
alpha1 = createSlider(-30, 30, -10);
alpha2 = createSlider(-30, 30, 10);
createCanvas(600, 1000);
}
function draw() {
let mean1 = [];
let mean2 = [];
background(235);
push();
translate(width * 0.5 , height * 0.5);
noFill();
strokeWeight(2);
stroke(100);
line(-r, 0, r, 0);
stroke(100);
//line(-r, 0, -r - height * tan(theta), -height);
//line(r, 0, r + height * tan(theta), -height);
/*for (let ni = 0; ni < layeralt.length; ni++) {
let alt = -layeralt[ni];
strokeWeight(0.5);
line(-width / 2, -layeralt[ni], width / 2, -layeralt[ni]);
strokeWeight(1);
for (let mi = 0; mi < width; mi++) {
line(-width / 2 + mi,
alt + strength[ni] * (noise(mi * freq[ni], 10 * ni) - 0.5),
-width / 2 + mi + 1,
alt + strength[ni] * (noise((mi + 1) * freq[ni], 10 * ni) - 0.5));
}
}*/
// dir 1
strokeWeight(1);
let alpha = alpha1.value() * PI / 180;
stroke(200, 0, 0);
line(-r, 0, -r + height * tan(alpha), -height);
line(r, 0, r + height * tan(alpha), -height);
for (let mi = 0; mi < width; mi++) {
mean1.push(0);
mean2.push(0);
if (-width / 2 + mi < -r || -width / 2 + mi + 1 > r)
continue;
let sum1 = 0;
let sum2 = 0;
for (let ni = 0; ni < layeralt.length; ni++) {
sum1 += strength[ni] * (noise((mi + layeralt[ni] * tan(alpha)) * freq[ni], 10 * ni) - 0.5);
sum2 += strength[ni] * (noise((mi + 1 + layeralt[ni] * tan(alpha)) * freq[ni], 10 * ni) - 0.5);
}
mean1[mi] = sum1;
mean2[mi] = sum2;
line(-width / 2 + mi, sum1, -width / 2 + mi + 1, sum2);
}
/*
// dir 2
alpha = alpha2.value() * PI / 180;
stroke(0, 0, 200);
line(-r, 0, -r + height * tan(alpha), -height);
line(r, 0, r + height * tan(alpha), -height);
for (let mi = 0; mi < width; mi++) {
if (-width / 2 + mi < -r || -width / 2 + mi + 1 > r)
continue;
stroke(0, 0, 200);
let sum1 = 0;
let sum2 = 0;
for (let ni = 0; ni < layeralt.length; ni++) {
sum1 += strength[ni] * (noise((mi + layeralt[ni] * tan(alpha)) * freq[ni], 10 * ni) - 0.5);
sum2 += strength[ni] * (noise((mi + 1 + layeralt[ni] * tan(alpha)) * freq[ni], 10 * ni) - 0.5);
}
line(-width / 2 + mi, sum1, -width / 2 + mi + 1, sum2);
mean1[mi] += sum1;
mean2[mi] += sum2;
mean1[mi] /= 2;
mean2[mi] /= 2;
stroke(0, 200, 0);
line(-width / 2 + mi, mean1[mi], -width / 2 + mi + 1, mean2[mi]);
}
*/
pop();
}