kzr project 07
function setup() {
createCanvas(480,480);
}function latticeCloseEnough(xc, yc, c1X, c1Y, c2X, c2Y, step, bSquare) {
var smaller = false;
var bigger = false;
for(var x = xc - step/2; x <= xc + step/2; x += step){
for(var y = yc - step/2; y <= yc + step/2; y += step){
r1r2 = dist(x,y,c1X,c1Y) * dist(x,y,c2X,c2Y)
if (r1r2 <= bSquare) smaller = true;
else bigger = true;
}
}
return smaller & bigger;
}function cassiniOvals(c1X, c1Y, c2X, c2Y, colorStretch) {
var step = 8;
var dist1 = dist(c1X, c1Y, mouseX, mouseY);
var dist2 = dist(c2X, c2Y, mouseX, mouseY);
var bSquare = dist1 * dist2;
var range = 3;
var scale = 0.2;
var start = 4;
var bSquareArray = Array.apply(null, Array(range)).map(function (_, i) {return bSquare * scale * (i + start);});
for (var y = 0; y <= height; y += step) {
for (var x = 0; x <= width; x += step) {
for (var pos = 0; pos < bSquareArray.length; pos ++) {
var posColor = map(pos,0,range - 1,0,255);
stroke((posColor + 50) * colorStretch,(posColor - 50) * colorStretch,posColor * colorStretch);
if(latticeCloseEnough(x, y, c1X, c1Y, c2X, c2Y, step, bSquareArray[pos])){
point(x,y);
}
}
}
}
}
function draw() {
background(0);
strokeWeight(2.5);
var c1X = width / 2;
var c1Y = height / 2;
var c2Y = height / 2;
var amount = 4;
for (var i = 1; i <= 2; i += (1 / amount)) {
var colorStretch = map(i,0,2,0.1,1);
cassiniOvals(c1X * i,c1Y,c1X * (2 - i),c2Y, colorStretch);
}
}
This project was really cool to me. I used the Cassini Oval curve for this project from the MathWorld site. The main part of this project for me was creating a lattice checking function, so that the points did not get wider apart as the distances from the centers increased for larger increments. When I used a basic distance checking function, when the b-squared distance increased, the “bands” of points got thicker. I also used the .apply function I found online, which was hard for me to learn at first because I did not know about lambda expressions. Overall, this project really forced me to learn how to reorganize my code and the structure overall.
Below is a screenshot on the right of a standard overlapping Cassini ovals when distance is short, and another screenshot on the left when the mouse is towards one side of the canvas, making the distances from the two centers larger.

