xxxxxxxxxx
var N = 20;
var size = 6;
var particles = [];
var func;
function setup() {
createCanvas(1112, 834);
background(0);
func = (z => z.multBy(z).add2(-1,0));
var d = size/N;
for (let i=-N; i<=N; i++){
for (let j=-N; j<=N; j++){
var z = new Complex(i*d, j*d);
particles.push(new Particle(z, func(z)));
}
}
setupUI();
}
/*function func(z){
return z.multBy(z).add2(-1,0);
}*/
function draw() {
//background(100);
stroke(255);
translate(width/2, height/2);
for (let p of particles){
p.draw();
p.update(func);
}
stroke(255);
strokeWeight(6);
line(-1000,0,1000,0);
line(0,-1000,0,1000);
stroke(50);
strokeWeight(4);
line(-1000,0,1000,0);
line(0,-1000,0,1000);
}
// ----------------------------- User interface - selection -----------------------------
var selectList;
function setupUI(){
selectList = [
'f(z)=z', 'f(z)=z^2', 'f(z)=z^2-1', 'f(z)=z^3-1', 'f(z)=exp(z)', 'f(z)=sinh(z)'
]
animationSelect = createSelect();
animationSelect.position(43, 140);
for (let name of selectList){
animationSelect.option(name);
}
animationSelect.selected('f(z)=z^2-1');
functionType = 1;
animationSelect.changed(animationSelectEvent);
}
function complexExp(z){
var r = Math.exp(z.real);
return new Complex(r*Math.cos(z.img), r*Math.sin(z.img));
}
function complexSinh(z){
var r1 = Math.exp(z.real);
var r2 = 1/r1;
return new Complex((r1*Math.cos(z.img)+r2*Math.cos(-z.img))/2, (r1*Math.sin(z.img)+r2*Math.sin(-z.img))/2);
}
var functionType;
function animationSelectEvent() {
let item = animationSelect.value();
if (item == 'f(z)=z')
func = (z => z);
if (item == 'f(z)=z^2')
func = (z => z.multBy(z));
if (item == 'f(z)=z^2-1')
func = (z => z.multBy(z).add2(-1,0));
if (item == 'f(z)=z^3-1')
func = (z => z.multBy(z).multBy(z).add2(-1,0));
if (item == 'f(z)=exp(z)'){
func = complexExp;
}
if (item == 'f(z)=sinh(z)'){
func = complexSinh;
}
background(0);
}