Skip to content

Instantly share code, notes, and snippets.

@companje
Last active March 14, 2019 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save companje/20fec9fece2d91edd31600ff86545f73 to your computer and use it in GitHub Desktop.
Save companje/20fec9fece2d91edd31600ff86545f73 to your computer and use it in GitHub Desktop.
Earth Elevation Curve

Earth % of the surface covered with water. Going from lowest point to highest point.

Progress Surface % covered with water
0.000 0.000
0.010 0.001
0.020 0.001
0.030 0.002
0.040 0.003
0.050 0.007
0.060 0.012
0.070 0.020
0.080 0.028
0.090 0.042
0.100 0.058
0.110 0.076
0.120 0.100
0.130 0.117
0.140 0.142
0.150 0.158
0.160 0.183
0.170 0.200
0.180 0.227
0.190 0.250
0.200 0.281
0.210 0.306
0.220 0.324
0.230 0.350
0.240 0.367
0.250 0.391
0.260 0.405
0.270 0.423
0.280 0.435
0.290 0.451
0.300 0.463
0.310 0.473
0.320 0.485
0.330 0.491
0.340 0.500
0.350 0.505
0.360 0.512
0.370 0.517
0.380 0.523
0.390 0.527
0.400 0.532
0.410 0.537
0.420 0.541
0.430 0.546
0.440 0.548
0.450 0.553
0.460 0.555
0.470 0.559
0.480 0.562
0.490 0.566
0.500 0.570
0.510 0.576
0.520 0.585
0.530 0.593
0.540 0.609
0.550 0.628
0.560 0.689
0.570 0.730
0.580 0.772
0.590 0.798
0.600 0.824
0.610 0.840
0.620 0.850
0.630 0.862
0.640 0.869
0.650 0.879
0.660 0.885
0.670 0.894
0.680 0.898
0.690 0.905
0.700 0.911
0.710 0.915
0.720 0.920
0.730 0.924
0.740 0.929
0.750 0.932
0.760 0.938
0.770 0.942
0.780 0.948
0.790 0.955
0.800 0.961
0.810 0.968
0.820 0.976
0.830 0.980
0.840 0.983
0.850 0.986
0.860 0.989
0.870 0.992
0.880 0.994
0.890 0.995
0.900 0.996
0.910 0.997
0.920 0.997
0.930 0.997
0.940 0.998
0.950 0.998
0.960 0.998
0.970 0.999
0.980 0.999
0.990 0.999
1.000 1.000
float lowest = -11000; //meters
float highest = 8848; //meters
float zero = .5589;
float progress = 0; //.5543 voor de 4k plaatjes
PImage heightmap, heightmap2, palette, bordermap;
PShader shader;
void setup() {
size(1024, 512, P2D);
bordermap = loadImage("borders8k.png");
heightmap = loadImage("8k-lo.png"); //zit verschil in niveau tussen 4k en 8k
heightmap2 = loadImage("8k-hi.png");
palette = loadImage("colors4k copy 9.png");
}
void draw() {
shader = loadShader("waterworld.glsl");
shader.set("progress", progress);
shader.set("palette", palette);
shader.set("heightmap", heightmap);
shader.set("heightmap2", heightmap2);
shader.set("bordermap", bordermap);
shader.set("showBitmap", true);
shader(shader);
image(heightmap, 0, 0, width, height);
resetShader();
loadPixels();
float waterArea = 0;
for (int i=0; i<width*height; i++) {
if (brightness(pixels[i])>100) waterArea++;
}
waterArea /= width*height;
println(nf(progress,0,3));
//println(nf(waterArea,0,3));
progress += .01;
if (progress>=1) exit();
}
```
uniform sampler2D heightmap;
uniform sampler2D heightmap2;
uniform sampler2D palette;
uniform sampler2D bordermap;
varying vec4 vertTexCoord;
uniform float progress;
uniform bool showBitmap;
float map(float value, float min1, float max1, float min2, float max2) {
return min2 + (value - min1) * (max2 - min2) / (max1 - min1);
}
float getElevation(vec2 xy) {
vec4 heightColor = texture2D(heightmap, vertTexCoord.st);
vec4 heightColor2 = texture2D(heightmap2, vertTexCoord.st);
return (heightColor.r * 256. + heightColor2.r) / 256.;
}
void main() {
vec4 borderColor = texture2D(bordermap, vertTexCoord.st);
float elevation = getElevation(vertTexCoord.st);
if (showBitmap) {
gl_FragColor = vec4(vec3(elevation < progress),1);
} else {
float f = elevation < progress ?
map(elevation, 0.0,progress, 0.0, 0.5) :
map(elevation, progress,1.0, 0.5, 1.0);
gl_FragColor = texture2D(palette, vec2(f,0)) + borderColor * borderColor.a;
}
}
void setup() {
size(800, 800);
background(0);
stroke(255);
}
void draw() {
noFill();
beginShape();
for (int x=0; x<width; x++) {
vertex(x, height - lut(float(x)/width) * height);
}
endShape();
}
float lut(float x) {
x = constrain(x,0,1);
float aa[] = { 0.000,0.010,0.020,0.030,0.040,0.050,0.060,0.070,0.080,0.090,0.100,0.110,0.120,0.130,0.140,0.150,0.160,0.170,0.180,0.190,0.200,0.210,0.220,0.230,0.240,0.250,0.260,0.270,0.280,0.290,0.300,0.310,0.320,0.330,0.340,0.350,0.360,0.370,0.380,0.390,0.400,0.410,0.420,0.430,0.440,0.450,0.460,0.470,0.480,0.490,0.500,0.510,0.520,0.530,0.540,0.550,0.560,0.570,0.580,0.590,0.600,0.610,0.620,0.630,0.640,0.650,0.660,0.670,0.680,0.690,0.700,0.710,0.720,0.730,0.740,0.750,0.760,0.770,0.780,0.790,0.800,0.810,0.820,0.830,0.840,0.850,0.860,0.870,0.880,0.890,0.900,0.910,0.920,0.930,0.940,0.950,0.960,0.970,0.980,0.990,1.000 };
float bb[] = { 0.000,0.001,0.001,0.002,0.003,0.007,0.012,0.020,0.028,0.042,0.058,0.076,0.100,0.117,0.142,0.158,0.183,0.200,0.227,0.250,0.281,0.306,0.324,0.350,0.367,0.391,0.405,0.423,0.435,0.451,0.463,0.473,0.485,0.491,0.500,0.505,0.512,0.517,0.523,0.527,0.532,0.537,0.541,0.546,0.548,0.553,0.555,0.559,0.562,0.566,0.570,0.576,0.585,0.593,0.609,0.628,0.689,0.730,0.772,0.798,0.824,0.840,0.850,0.862,0.869,0.879,0.885,0.894,0.898,0.905,0.911,0.915,0.920,0.924,0.929,0.932,0.938,0.942,0.948,0.955,0.961,0.968,0.976,0.980,0.983,0.986,0.989,0.992,0.994,0.995,0.996,0.997,0.997,0.997,0.998,0.998,0.998,0.999,0.999,0.999,1.000 };
for (int i=0; i<aa.length; i++) {
if (x<aa[i]) return map(x, aa[i-1], aa[i], bb[i-1], bb[i]);
}
return 1;
}
@companje
Copy link
Author

screenshot

@companje
Copy link
Author

float meters = progress < zero ? map(progress, 0, zero, lowest, 0) : map(progress, zero, 1, 0, highest);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment