// Seung Joon Choi // http://epicure.graffity.net // epicure@hanmail.net // 2005.10.14. //----------------------- int sl_width; int sl_height; PImage canvas; float[] hmap; //----------------------- float sss = 0; int kkk = 0; color SL(float s, float t) { float r = 1 - dist(0.5, 0.5, sss*0.01, sss*0.01); float vs = sin(3*TWO_PI * s); float vt = sin(3*TWO_PI * t); float check = vs*vt > 0 ? 1 : 0; float theta = atan2(0.5 - t, 0.5 - s); //s = s + 0.2 *sin(sss * 0.01 * PI) *cos(5*PI * t); //t = t + 0.2 *cos(sss * 0.01 * PI) *sin(5*PI * s); float dx = 0.5 - s; float dy = 0.5 - t; float a = r * 0.5; float k = 0.25; float g = k*k / (dx*dx + dy*dy - a*a); float r2 = abs(g); float v = check - r2*cos(TWO_PI*r2 + 6*theta+sss); return color(sss * 0.01, v, v, v * 0.05); } float SLH(float s, float t) { float v = 0; float v1 = s + 0.1 * cos(4 * PI * t); float v2 = sin(6 * PI * v1 - PI * 0.5 + sss); float d = 1 - dist(0.5, 0.5, s, t); v = v2 * d; return v; } void buildCanvas() { noiseDetail(3, sss); canvas.loadPixels(); for(int iy = 0; iy < sl_height; iy++) for(int ix = 0; ix < sl_width; ix++) { float s = (float)ix / (float)(sl_width-1); float t = (float)iy / (float)(sl_height-1); canvas.pixels[iy * sl_width + ix] = SL(s, t); } canvas.updatePixels(); //sss += 0.0025; sss += 0.2; } void buildHeightField() { for(int iy = 0; iy < sl_height; iy++) for(int ix = 0; ix < sl_width; ix++) { float s = (float)ix / (float)(sl_width-1); float t = (float)iy / (float)(sl_height-1); hmap[iy * sl_width + ix] = SLH(s, t); } } void drawHField(float max_h) { float v = 0; fill(0.5, 1, 0.2); float sz = 80; float off_x = sl_width * 0.5; float off_y = sl_height * 0.5; for(int iy = 0; iy < sl_height - 1; iy++) { /* beginShape(QUAD_STRIP); texture(canvas); for(int ix = 0; ix < sl_width; ix++) { float s = (float)ix / (float)(sl_width-1); float t = (float)iy / (float)(sl_height-1); v = hmap[iy * sl_width + ix]; normal(0, 0, 1); vertex((ix - off_x) * sz, (iy - off_y) * sz, v * 30, s, t); v = hmap[(iy + 1) * sl_width + ix]; normal(0, 0, 1); vertex((ix - off_x) * sz, (iy + 1 - off_y) * sz, v * 30, s, t); } endShape(); */ beginShape(QUAD_STRIP); for(int ix = 0; ix < sl_width; ix++) { v = hmap[iy * sl_width + ix]; normal(0, 0, 1); vertex((ix - off_x) * sz, (iy - off_y) * sz, v * max_h); v = hmap[(iy + 1) * sl_width + ix]; normal(0, 0, 1); vertex((ix - off_x) * sz, (iy + 1 - off_y) * sz, v * max_h); } endShape(); } }