xxxxxxxxxx
84
let lineSpace = 12; //space between waves
let lineHeight = 6; //height of each wave-line
let lineOffset = -3; //offset line from wave
let theta = 0.0;
let amp = 400.0; //amplitude of the wave, and radius of circle
let wait = 2000.0; //wave offset
let dx;
let xvalues;
let speed = 0.005 //growth wave speed
let mainColor = 0
let circleColor = 255
function setup() {
createCanvas(1200, 1200);
maxHeight = amp * 2 + lineSpace;
dx = (TWO_PI / wait) * lineSpace;
xvalues = new Array(floor(maxHeight / lineSpace));
//frameRate(1)
}
let angle = -amp
let anglex = 0;
let spdx = 1.5
let angley = 0;
let spdy = 0.75
function draw() {
background(0);
//angleMode(DEGREES)
translate(width / 2, height / 2)
fill(circleColor)
stroke(0)
//circle(0, 0, amp * 2)
theta += speed;
let x = theta;
let altura = 4
let space = 4
let init = -amp
let centerOffset = init
let total = amp * 2 / (space + altura)
let distCateto = cateto(amp, centerOffset)
let bottom = {}
let top = {}
let xxxx = 10
noStroke()
for (i = 0; i < total; i++) {
let cosx = cos(x)
//here control the wave length in/out
let offsetX = map(cosx, -1, 1, -amp * 2, 0);
centerOffset = centerOffset + space
total = amp * 2 / (space + altura)
distCateto = cateto(amp, centerOffset)
bottom = {
x1: -distCateto,
y1: -centerOffset,
x2: distCateto,
y2: -centerOffset
}
centerOffset = centerOffset + altura
distCateto = cateto(amp, centerOffset)
top = {
x1: -distCateto,
y1: -centerOffset,
x2: distCateto,
y2: -centerOffset
}
let dcolor = dist(bottom.x1, bottom.y1, max(bottom.x1, bottom.x2 + offsetX), bottom.y2)
let rmapcolor = map(dcolor, 0, amp * 2, 255, 0)
textSize(16);
fill(255, 75, rmapcolor-75)
if (i % 2)
text(round(dcolor), top.x2 + 30, top.y2);
quad(bottom.x1, bottom.y1, top.x1, top.y1, top.x2, top.y2, max(bottom.x1, bottom.x2 + offsetX), bottom.y2)
x += dx;
}
angle += speed
anglex += spdx
angley += spdy
}
const cateto = (raio, altura) => sqrt(pow(raio, 2) - pow(altura, 2))