xxxxxxxxxx
"use strict"
let orbitPoints = [];
let circles;
let startTime;
let p;
function setup() {
createCanvas(600, 600);
createCircles();
background(255);
startTime = millis();
colorMode(HSB, 100);
}
function draw() {
let t = ( millis() - startTime )*0.001;
let theta = 0.1*t;
//Random Archimedean spiral:
//let r = random(0.2) + random(0.3) *theta;
let r = 0.5 + 0.1*theta;
let p = createVector(r*cos(theta),r*sin(theta))
if(r < 1.0) {
orbitPoints = trackedIterativeInversion(p.x,p.y,circles);
}
else{
startTime = millis();
//background(255);
noLoop();
return;
}
strokeWeight(1);
noFill();
stroke(100*r,100,100,10);
for(let k = 0; k < orbitPoints.length-1; k++) {
let p = orbitPoints[k];
let q = orbitPoints[k+1];
let i = 0.5*(p.x + 1)*width;
let j = 0.5*(p.y + 1)*height;
let i2 = 0.5*(q.x + 1)*width;
let j2 = 0.5*(q.y + 1)*height;
line(i,j,i2,j2);
}
}
/*
function mouseClicked() {
startTime = millis();
}
*/
function OrthoganalCircle(theta,dTheta) {
let R = 1.0/cos(dTheta);
this.r = abs(tan(dTheta));
this.x = R*cos(theta);
this.y = R*sin(theta);
this.containsPoint = function(p){
let c = createVector(this.x,this.y);
return c.dist(p) < this.r;
};
this.invert = function(p){
let c = createVector(this.x,this.y);
let op = c.dist(p);
let oq = this.r*this.r/op;
let dq = p5.Vector.sub(p,c).normalize().mult(oq);
return p5.Vector.add(c,dq);
};
}
function createCircles() {
const dTheta = 4.4;
let c1 = new OrthoganalCircle(0,dTheta);
let c2 = new OrthoganalCircle(TWO_PI/3,dTheta);
let c3 = new OrthoganalCircle(2*TWO_PI/3,dTheta);
circles = [c1,c2,c3];
}
function trackedIterativeInversion(x,y,circles) {
let flag = true ;
let points = [createVector(x,y)];
const iterations = 10;
for(let i = 0; i<iterations; i++) {
var k;
flag = true;
for ( k in circles ) {
let circle = circles[k];
let p = points[points.length-1];
if (circle.containsPoint(p)){
points.push(circle.invert(p));
flag = false;
}
}
if (flag) {
break;
}
}
return points;
}
/*----------Some little helpers to convert from pixel indecies to disk coordinates ---------------*/
function xx(i){
return 2*i/width - 1;
}
function yy(i){
return 2*i/height -1;
}
function ii(x){
return 0.5*(x +1)*width;
}
function jj(y){
return 0.5*(y +1)*height;
}
function indexx(i,j){
return 4*(i + j*width);
}