var frameWidth = WIDTH/100;
var frameHeight = HEIGHT/100;
let a_1, a_2, b_1, b_2, c_1, c_2, d_1, d_2;
let myPointA, myPointB, myPointC, myPointD;
let colorA = {r:255, g: 100, b:0};
let colorB = {r:255, g: 0, b:0};
let colorC = {r:0, g: 0, b:250};
let colorD = {r:0, g: 200, b:0};
createCanvas(WIDTH, HEIGHT);
myPointA = new DraggablePoint(width / 2+70, height / 2+70, 20, colorA);
myPointB = new DraggablePoint(width / 2+70, height / 2-70, 20, colorB);
myPointC = new DraggablePoint(width / 2-70, height / 2+70, 20, colorC);
myPointD = new DraggablePoint(width / 2-70, height / 2-70, 20, colorD);
myPointA.checkHovering();
myPointB.checkHovering();
myPointC.checkHovering();
myPointD.checkHovering();
a_1 = map(myPointA.x, 0, width, -5, 5);
a_2 = map(myPointA.y, height, 0, -3.5, 3.5);
b_1 = map(myPointB.x, 0, width, -5, 5);
b_2 = map(myPointB.y, height, 0, -3.5, 3.5);
c_1 = map(myPointC.x, 0, width, -5, 5);
c_2 = map(myPointC.y, height, 0, -3.5, 3.5);
d_1 = map(myPointD.x, 0, width, -5, 5);
d_2 = map(myPointD.y, height, 0, -3.5, 3.5);
translate(width/2, height/2);
let newx = map(mouseX, 0, width, -5, 5);
let newy = map(mouseY, height, 0, -3.5, 3.5);
particles[currentParticle] = new Particle(newx+random(-splatter,splatter), newy+random(-splatter,splatter), t,h);
if (currentParticle >= numMax)
for (var i=particles.length-1; i>=0; i-=1) {
if ( p.x > 9 || p.y > 7 || p.x < -9 || p.y < -7 ) {
function mousePressed() {
myPointA.checkDragging();
myPointB.checkDragging();
myPointC.checkDragging();
myPointD.checkDragging();
function mouseReleased() {
a_1 * (c_1 * (x * x + y * y) + d_1 * x + d_2 * y) +
b_1 * (c_1 * x - c_2 * y + d_1) +
2 * c_1 * (d_1 * x + d_2 * y) +
c_2 * (2 * d_2 * x - 2 * d_1 * y) +
c_1 * c_1 * (x * x + y * y) +
c_2 * c_2 * (x * x + y * y) +
a_2 * (c_1 * (x * x + y * y) + d_1 * x + d_2 * y) -
b_1 * (c_2 * x + c_1 * y + d_2) +
2 * c_1 * (d_1 * x + d_2 * y) +
c_2 * (2 * d_2 * x - 2 * d_1 * y) +
c_1 * c_2 * (x * x + y * y) +
c_2 * c_2 * (x * x + y * y) +
function Particle(_x, _y, _t, _h) {
this.radius = random(4,6);
this.op = random(187,200);
this.r = random(254,255);
this.g = random(164,255);
this.update = function() {
this.k1 = P(this.time, this.x, this.y);
this.j1 = Q(this.time, this.x, this.y);
this.k2 = P(this.time + 1/2 * this.h, this.x + 1/2 * this.h * this.k1, this.y + 1/2 * this.h * this.j1);
this.j2 = Q(this.time + 1/2 * this.h, this.x + 1/2 * this.h * this.k1, this.y + 1/2 * this.h * this.j1);
this.k3 = P(this.time + 1/2 * this.h, this.x + 1/2 * this.h * this.k2, this.y + 1/2 * this.h * this.j2);
this.j3 = Q(this.time + 1/2 * this.h, this.x + 1/2 * this.h * this.k2, this.y + 1/2 * this.h * this.j2);
this.k4 = P(this.time + this.h, this.x + this.h * this.k3, this.y + this.h * this.j3);
this.j4 = Q(this.time + this.h, this.x + this.h * this.k3, this.y + this.h * this.j3);
this.x = this.x + this.h/6 *(this.k1 + 2 * this.k2 + 2 * this.k3 + this.k4);
this.y = this.y + this.h/6 *(this.j1 + 2 * this.j2 + 2 * this.j3 + this.j4);
this.display = function() {
fill(this.r, this.b, this.g, this.op);
this.updatex = map(this.x, -9.9, 9.9, -width, width);
this.updatey = map(-this.y, -7, 7, -height, height);
ellipse(this.updatex, this.updatey, 2*this.radius, 2*this.radius);
buttonField = createButton('Field');
buttonField.position(windowWidth/2, 570);
buttonField.mousePressed(fieldShow);
for(var k=ymin; k<=ymax; k+=ystep){
for(var j=xmin; j<=xmax; j+=xstep){
var xx = j + sc * P(_time, j, k);
var yy = k + sc * Q(_time, j, k);
var lj = map(j, -9.9, 9.9, -width, width);
var lk = map(-k, -7, 7, -height, height);
var lx = map(xx, -9.9, 9.9, -width, width);
var ly = map(-yy, -7, 7, -height, height);
var angle = atan2(ly-lk, lx-lj);
var dist = sqrt((lk-ly)*(lk-ly)+(lj-lx)*(lj-lx));
triangle(-10, -4, 10, 0, -10, 4);
constructor(x, y, size, color) {
this.x = mouseX + this.offsetX;
this.y = mouseY + this.offsetY;
fill(this.color.r, this.color.g, this.color.b);
ellipse(this.x, this.y, this.size);
let d = dist(mouseX, mouseY, this.x, this.y);
this.offsetX = this.x - mouseX;
this.offsetY = this.y - mouseY;
let d = dist(mouseX, mouseY, this.x, this.y);