xxxxxxxxxx
79
// https://en.wikipedia.org/wiki/Ikeda_map
let myp = 50; // starting points / lines
let iterations = 300; // line segments
let tn; // angle
let u = 0.918; // ikeda factor
var xn = [iterations];
var yn = [iterations];
function setup() {
createCanvas(500, 500);
noLoop();
}
function draw() {
background(255);
translate(width / 2, height / 2);
for (let i = 0; i < myp; i++) ikeda();
}
function ikeda() {
xn[0] = random(-1, 1) * width / 2; // related to center translate need all 4 quadrants
yn[0] = random(-1, 1) * height / 2;
strokeWeight( random(1,4) );
stroke( random(100,200),random(100,200),random(100,200) );
for (let i = 1; i < iterations; i++) {
tn = 0.4 - (6 / (1 + pow(xn[i - 1], 2) + pow(yn[i - 1], 2)));
xn[i] = 1 + u * (xn[i - 1] * cos(tn) - yn[i - 1] * sin(tn));
yn[i] = u * (xn[i - 1] * sin(tn) + yn[i - 1] * cos(tn));
line(xn[i - 1], yn[i - 1], xn[i], yn[i]);
}
}
/*
// IKEDA Function
// https://discourse.processing.org/t/drawing-ikeda-function/9536
// https://en.wikipedia.org/wiki/Ikeda_map#Octave/MATLAB_code_for_point_trajectories
int p =100; // starting points / lines
int iterations = 1000; // line segments
float tn; // angle
float u = 0.9;//0.918; // ikeda factor
float[] xn = new float[iterations];
float[] yn = new float[iterations];
color cp;
void setup() {
size(500, 500);
noLoop();
}
void ikeda() {
xn[0] = random(-1,1)*width/2; // related to center translate need all 4 quadrants
yn[0] = random(-1,1)*height/2;
cp = color(random(127,200),random(127,200),random(127,200));
for (int i=1; i<iterations; i++) {
tn = 0.4 - (6 /(1+pow(xn[i-1], 2) + pow(yn[i-1], 2)));
xn[i] = 1 + u * (xn[i-1]* cos(tn) - yn[i-1]*sin(tn));
yn[i] = u*( xn[i-1]*sin(tn)+yn[i-1]*cos(tn));
stroke(cp);
line(xn[i-1], yn[i-1], xn[i], yn[i]);
}
}
void draw() {
background(200,200,0);
translate(width/2, height/2);
for ( int k=0; k<p; k++) ikeda();
}
void mouseWheel(MouseEvent event) {
float e = event.getCount();
u += e*0.02;
println("ikead: "+nf(u,1,3));
redraw();
}
*/