xxxxxxxxxx
95
let N = [0, 4];
let P = 2;
let Nsorted = [0];
let posX = [0];
let posY = [0];
let posXS = [0];
let posYS = [0];
function setup() {
createCanvas(1000, 1000);
background(255);
}
function draw() {
for (let q = 0; q < 100; q++) {
//background(255, 255, 255, 1);
for (let k = 0; k < 100; k++) {
if (N[N.length - 1] <= 1) {
N = [0, pow(2, P) + 1];
P += 0.1;
} else {
N[N.length] = oddOrEven(N[N.length - 1]);
//print(N[N.length - 1]);
}
//sortA(posX, posXS, "ascending");
//sortA(posY, posYS, "ascending");
}
let c = (N[1] * (255 / 10));
drawN(
N,
1,
[c/3 % 255, c/4 % 64, c/2 % 127, 10],
10,
0.01,
1,
1,
width / 2,
height / 2
);
print(N[1] + ":" + N.length);
}
}
function isEven(n) {
return n / 2;
}
function isOdd(n) {
return n * 3 + 1;
}
function oddOrEven(n) {
if (n % 2 == 0) {
return isEven(n);
} else {
return isOdd(n);
}
}
function drawN(a, thickness, color, amplitude, angleMulti, scalex, scaley, originX, originY) {
strokeWeight(thickness);
posX[0] = originX;
posY[0] = originY;
let ox = originX;
let oy = originY;
for (let i = 1; i < a.length; i++) {
let round_a = a[i] % TWO_PI - PI;
let nx = ox + amplitude * cos(log(a[i]) * angleMulti);
let ny = oy + amplitude * sin(log(a[i]) * angleMulti);
posX[i] = nx;
posY[i] = ny;
ox = nx;
oy = ny;
}
for (let i = floor(a.length / 2); i < a.length; i++) {
stroke(color);
line(posX[i - 1] * scalex, posY[i - 1] * scaley, posX[i] * scalex, posY[i] * scaley);
}
}
function sortA(input, output, order) {
arrayCopy(input, output);
if (order == "ascending") {
output.sort(function (a, b) {
return a - b;
});
} else if (order == "descending") {
output.sort(function (a, b) {
return b - a;
});
}
}