commit dd659c517009ab707d92b50c817643836b46398b Author: Anish Lakhwara Date: Wed Jul 11 23:09:37 2018 +1000 up to vector folds, missing cosfunc diff --git a/.fslckout b/.fslckout new file mode 100644 index 0000000..58c2e44 Binary files /dev/null and b/.fslckout differ diff --git a/folds/folds.pde b/folds/folds.pde new file mode 100644 index 0000000..e8347b1 --- /dev/null +++ b/folds/folds.pde @@ -0,0 +1,79 @@ +void setup() { + size(600, 600); + background(0); + smooth(8); + noFill(); + stroke(250, 15); + strokeWeight(0.9); + + x1=y1=-3; + x2=y2=3; + y=y1; + step=(x2-x1)/(2.321*width); +} + +float x1, y1, x2, y2; // function domain +float step; // step within domain +float y; + +boolean go = true; +void draw() { + if (go) { + for (int i=0; (i<20)&go; i++) { // draw 20 lines at once + for (float x=x1; x<=x2; x+=step) { + drawVariation(x, y); + } + y+=step; + if (y>y2) { + go = false; + println("done"); + //save("pdj + hyperbolic * pdj.png"); + } + } + } +} + +void drawVariation(float x, float y) { + PVector v = new PVector(x, y); + float amount = 2.0; + v = addF(pdj(v,amount),mulF(hyperbolic(v,amount),pdj(v,amount))); + + //wrapping + v.x = (v.x - x1) % (x2-x1); + if(v.x<0) v.x += (x2-x1); + v.y = (v.y - y1) % (y2-y1); + if(v.y<0) v.y += (y2-y1); + v.x += x1; + v.y += y1; + + float xx = map(v.x+0.003*randomGaussian(), x1, x2, 20, width-20); + float yy = map(v.y+0.003*randomGaussian(), y1, y2, 20, height-20); + point(xx, yy); +} + +PVector sinusoidal(PVector v, float amount) { + return new PVector(amount * sin(v.x), amount * sin(v.y)); +} + +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); +} + +// parametrization P={pdj_a,pdj_b,pdj_c,pdj_d} +float pdj_a = 0.4; +float pdj_b = 1.23; +float pdj_c = -0.3; +float pdj_d = -1.98; +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))); +} + +PVector addF(PVector v1, PVector v2) { return new PVector(v1.x+v2.x, v1.y+v2.y); } +PVector subF(PVector v1, PVector v2) { return new PVector(v1.x-v2.x, v1.y-v2.y); } +PVector mulF(PVector v1, PVector v2) { return new PVector(v1.x*v2.x, v1.y*v2.y); } +PVector divF(PVector v1, PVector v2) { return new PVector(v2.x==0?0:v1.x/v2.x, v2.y==0?0:v1.y/v2.y); } diff --git a/folds/pdj + hyperbolic * pdj.png b/folds/pdj + hyperbolic * pdj.png new file mode 100644 index 0000000..e338447 Binary files /dev/null and b/folds/pdj + hyperbolic * pdj.png differ diff --git a/vector_field/vector_field.pde b/vector_field/vector_field.pde new file mode 100644 index 0000000..bd7a357 --- /dev/null +++ b/vector_field/vector_field.pde @@ -0,0 +1,62 @@ +// dynamic list with our points, PVector holds position +ArrayList points = new ArrayList(); + +// colors used for points +color[] pal = { + color(0, 91, 197), + color(0, 180, 252), + color(23, 249, 255), + color(223, 147, 0), + color(248, 190, 0) +}; + +// global configuration +float vector_scale = 0.01; // vector scaling factor, we want small steps +float time = 0; // time passes by + +void setup() { + size(800, 800); + strokeWeight(0.66); + background(0, 5, 25); + noFill(); + smooth(8); + + // noiseSeed(1111); // sometimes we select one noise field + + // create points from [-3,3] range + for (float x=-3; x<=3; x+=0.07) { + for (float y=-3; y<=3; y+=0.07) { + // create point slightly distorted + PVector v = new PVector(x+randomGaussian()*0.003, y+randomGaussian()*0.003); + points.add(v); + } + } +} + +void draw() { + int point_idx = 0; // point index + for (PVector p : points) { + // map floating point coordinates to screen coordinates + float xx = map(p.x, -6.5, 6.5, 0, width); + float yy = map(p.y, -6.5, 6.5, 0, height); + + // select color from palette (index based on noise) + int cn = (int)(100*pal.length*noise(point_idx))%pal.length; + stroke(pal[cn], 15); + point(xx, yy); //draw + + // placeholder for vector field calculations + float n = TWO_PI * noise(p.x,p.y); + PVector v = new PVector(n,n); + + // v is vector from the field + //PVector v = new PVector(0.1, 0.1); + + p.x += vector_scale * v.x; + p.y += vector_scale * v.y; + + // go to the next point + point_idx++; + } + time += 0.001; +}