var frameWidth = WIDTH/100;
var frameHeight = HEIGHT/100;
createCanvas(WIDTH, HEIGHT);
let newx = map(mouseX, 0, width, 0, 2);
let newy = map(mouseY, height, 0, 0, 2);
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 > 4 || p.y > 3 || p.x < 0 || p.y < 0 ) {
if(mouseButton == RIGHT){
if (fieldShow == false) {
var P = (t, x, y) => 2.2*( -PI*0.1*sin(PI*(0.25*sin(2*PI / 10* t) *x*x + (1 - 2* (0.25) *sin(2*PI / 10 *t))* x))* cos(PI* y) );
var Q = (t, x, y) => 2.2*( PI*0.1 *cos(PI*(0.25*sin(2*PI / 10* t) *x*x + (1 - 2 *(0.25) *sin(2*PI / 10 *t))* x))* sin(PI*y)*(2 *(0.25)* sin(2*PI / 10* t)* x + 1 - 2 *(0.25)* sin(2*PI/ 10* t)) );
function Particle(_x, _y, _t, _h) {
this.radius = random(4,6);
this.op = random(187,200);
this.r = random(180,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, 0, 2, 0, width);
this.updatey = map(-this.y, 0, 2, 0, height);
ellipse(this.updatex, this.updatey, 2*this.radius, 2*this.radius);
buttonField = createButton('Field');
buttonField.position(250, 470);
buttonField.mousePressed(fieldShow);
for(var k=ymin; k<=ymax; k+=ystep){
for(var j=xmin; j<=xmax; j+=xstep){
var xx = j + sc * P(this.time, j, k);
var yy = k + sc * Q(this.time, j, k);
var lj = map(j, 0, 2, 0, width);
var lk = map(-k, 0, 2, 0, height);
var lx = map(xx, 0, 2, 0, width);
var ly = map(-yy, 0, 2, 0, height);
var angle = atan2(ly-lk, lx-lj);
var dist = sqrt((lk-ly)*(lk-ly)+(lj-lx)*(lj-lx));
triangle(-8, -2, 8, 0, -8, 2);