let wall; let eyeZ; let sh; let t; let es = []; const CYCLE = 100; function setup() { createCanvas(windowWidth, windowHeight, WEBGL); let dep = max(width,height); ortho(-width / 2, width / 2, height / 2, -height / 2,-dep*2 , dep*2); eyeZ = height / 2 / tan((30 * PI) / 180); // The default distance the camera is away from the origin. wall = new IntersectPlane(0, 0, 1, 0, 0, 300); noStroke(); init(); //shader sh = createShader(vert,frag); this.shader(sh); sh.setUniform("u_resolution", [width,height]); sh.setUniform("u_lightDir", [1,-1,-1]); } function draw() { background('#002D52'); //culclate mousePos let x = mouseX - width / 2; let y = (mouseY - height / 2)*-1; /* let radius = 200; x = cos(frameCount/CYCLE*TWO_PI)*radius; y = sin(frameCount/CYCLE*TWO_PI)*radius; */ const Q = createVector(0, 0, eyeZ); // A point on the ray and the default position of the camera. const v = createVector(x, y, -eyeZ); // The direction vector of the ray. let intersect; // The point of intersection between the ray and a plane. let closestLambda = eyeZ * 10; // The draw distance. let lambda = wall.getLambda(Q, v); // The value of lambda where the ray intersects the object if (lambda < closestLambda && lambda > 0) { // Find the position of the intersection of the ray and the object. intersect = p5.Vector.add(Q, p5.Vector.mult(v, lambda)); closestLambda = lambda; } const mousePos = createVector(intersect.x,intersect.y,intersect.z); for(let item of es) { item.setTarget(mousePos); item.update(); item.display(); } } function init() { let size = min(width,height)*0.7; let span = size/3; for(let y = -size/2; y <= size/2; y+=span) { for(let x = -size/2; x <= size/2; x+=span) { es.push(new Eye(createVector(x,y,0),span*0.4)); } } } class Eye { constructor(_pos,_radius) { this.pos = _pos; this.radius = _radius; this.dMult = random(0.05,0.1); this.currentTarget = createVector(0,0,1); this.target = createVector(0,0,1); this.tex = createGraphics(this.radius*4,this.radius*2); } setTarget(_targetPos) { this.target = _targetPos; } update() { this.currentTarget.add(p5.Vector.sub(this.target,this.currentTarget).mult(this.dMult)); } drawTex() { this.tex.ellipseMode(CENTER); this.tex.noStroke(); this.tex.background("#F4F8FB"); let diameter = this.tex.width*0.2; let noiseMult = noise(this.pos.x + sin((frameCount/CYCLE)*TWO_PI)); diameter += (noiseMult-0.5)/5 * diameter; this.tex.fill(100); this.tex.ellipse(this.tex.width/2,this.tex.height/2,diameter,diameter); this.tex.push(); this.tex.translate(this.tex.width/2,this.tex.height/2); for(let r = 0 ; r