From 8f39a00fc61897ad77a254d928e62cacb97d99a1 Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Mon, 16 Jul 2018 22:49:54 +1000 Subject: [PATCH] still following vector field tutorial --- vector_field/vector_field.pde | 151 ++++++++++++++++++++++++++++++++-- 1 file changed, 145 insertions(+), 6 deletions(-) diff --git a/vector_field/vector_field.pde b/vector_field/vector_field.pde index bd7a357..968bf96 100644 --- a/vector_field/vector_field.pde +++ b/vector_field/vector_field.pde @@ -3,11 +3,11 @@ ArrayList points = new ArrayList(); // colors used for points color[] pal = { - color(0, 91, 197), + color(0, 91, 233), color(0, 180, 252), - color(23, 249, 255), - color(223, 147, 0), - color(248, 190, 0) + color(147, 0, 255), + color(223, 47, 130), + color(248, 90, 230) }; // global configuration @@ -46,9 +46,17 @@ void draw() { point(xx, yy); //draw // placeholder for vector field calculations - float n = TWO_PI * noise(p.x,p.y); - PVector v = new PVector(n,n); + float n1 = 2* map(noise(p.x,p.y), 0, 1, -1, 1); + float n2 = 3 * map(noise(p.y/3, p.x/2), 0, 1, -1, 1); + //PVector v = new PVector(cos(n),sin(n)); + + float sinn = sin(n1); + PVector v2 = swirl(new PVector(n2, n1), 1.3); + float xt = sq(sinn)*sinn; + float yt = sq(cosn)*cosn; + + PVector v = new PVector(xt,yt); // v is vector from the field //PVector v = new PVector(0.1, 0.1); @@ -60,3 +68,134 @@ void draw() { } time += 0.001; } + +PVector circle(float n) { // polar to cartesian coordinates + return new PVector(cos(n), sin(n)); +} + +PVector astroid(float n) { + float sinn = sin(n); + float cosn = cos(n); + + float xt = sq(sinn)*sinn; + float yt = sq(cosn)*cosn; + + return new PVector(xt, yt); +} + +PVector cissoid(float n) { + float sinn2 = 2*sq(sin(n)); + + float xt = sinn2; + float yt = sinn2*tan(n); + + return new PVector(xt, yt); +} + +PVector kampyle(float n) { + float sec = 1/sin(n); + + float xt = sec; + float yt = tan(n)*sec; + + return new PVector(xt, yt); +} + +PVector rect_hyperbola(float n) { + float sec = 1/sin(n); + + float xt = 1/sin(n); + float yt = tan(n); + + return new PVector(xt, yt); +} + +final static float superformula_a = 1; +final static float superformula_b = 1; +final static float superformula_m = 6; +final static float superformula_n1 = 1; +final static float superformula_n2 = 7; +final static float superformula_n3 = 8; +PVector superformula(float n) { + float f1 = pow(abs(cos(superformula_m*n/4)/superformula_a), superformula_n2); + float f2 = pow(abs(sin(superformula_m*n/4)/superformula_b), superformula_n3); + float fr = pow(f1+f2, -1/superformula_n1); + + float xt = cos(n)*fr; + float yt = sin(n)*fr; + + return new PVector(xt, yt); +} + +PVector sinusoidal(PVector v, float amount) { + return new PVector(amount * sin(v.x), amount * sin(v.y)); +} + +PVector waves2(PVector p, float weight) { + float x = weight * (p.x + 0.9 * sin(p.y * 4)); + float y = weight * (p.y + 0.5 * sin(p.x * 5.555)); + return new PVector(x, y); +} + +PVector polar(PVector p, float weight) { + float r = p.mag(); + float theta = atan2(p.x, p.y); + float x = theta / PI; + float y = r - 2.0; + return new PVector(weight * x, weight * y); +} + +PVector swirl(PVector p, float weight) { + float r2 = sq(p.x)+sq(p.y); + float sinr = sin(r2); + float cosr = cos(r2); + float newX = 0.8 * (sinr * p.x - cosr * p.y); + float newY = 0.8 * (cosr * p.y + sinr * p.y); + return new PVector(weight * newX, weight * newY); +} + +PVector hyperbolic(PVector v, float amount) { + float r = v.mag() + 1.0e-10; + float theta = atan2(v.x, v.y); + float x = amount * sin(theta) / r; + float y = amount * cos(theta) * r; + return new PVector(x, y); +} + +PVector power(PVector p, float weight) { + float theta = atan2(p.y, p.x); + float sinr = sin(theta); + float cosr = cos(theta); + float pow = weight * pow(p.mag(), sinr); + return new PVector(pow * cosr, pow * sinr); +} + +PVector cosine(PVector p, float weight) { + float pix = p.x * PI; + float x = weight * 0.8 * cos(pix) * cosh(p.y); + float y = -weight * 0.8 * sin(pix) * sinh(p.y); + return new PVector(x, y); +} + +PVector cross(PVector p, float weight) { + float r = sqrt(1.0 / (sq(sq(p.x)-sq(p.y)))+1.0e-10); + return new PVector(weight * 0.8 * p.x * r, weight * 0.8 * p.y * r); +} + +PVector vexp(PVector p, float weight) { + float r = weight * exp(p.x); + return new PVector(r * cos(p.y), r * sin(p.y)); +} + +// parametrization P={pdj_a,pdj_b,pdj_c,pdj_d} +float pdj_a = 0.1; +float pdj_b = 1.9; +float pdj_c = -0.8; +float pdj_d = -1.2; +PVector pdj(PVector v, float amount) { + return new PVector( amount * (sin(pdj_a * v.y) - cos(pdj_b * v.x)), + amount * (sin(pdj_c * v.x) - cos(pdj_d * v.y))); +} + +final float cosh(float x) { return 0.5 * (exp(x) + exp(-x));} +final float sinh(float x) { return 0.5 * (exp(x) - exp(-x));}