RE: Post making contest 6.0
12-06-2017, 07:53 AM
// p.x and p.y are current coordinates
// v.x and v.y is a velocity at point p
vec2 get_velocity(vec2 p) {
vec2 v = vec2(0., 0.);
const float n = 10.;
float log2 = log(2.);
float pk = pow(2.,1.-p.x);
float c_re_top = 1. - pk*cos(p.y*log2);
float c_im_top = pk*sin(p.y*log2);
float c_bot = c_re_top*c_re_top +
c_im_top*c_im_top;
float sum1r = 0.;
float sum1i = 0.;
for (float k = 1.; k <= n; k++) {
pk = pow(k, -p.x);
if (k == 1.) {
pk = -pk;
}
float logk = log(k);
sum1r += pk * cos(p.y * logk);
sum1i += -pk * sin(p.y * logk);
}
float sum2r = 0.;
float sum2i = 0.;
for (float k = n + 1.; k <= 2.*n; k++){
pk = pow(k, -p.x);
if (k == 1.) {
pk = -pk;
}
float logk = log(k);
float ek = 0.;
for (float j = 0.; j <= n; j++) {
if (j <= k) {continue;}
float b = 1.;
for (float i = 1.; i <= n; i++) {
if (i == j) { break; }
b *= (n + 1. - i)/i;
}
ek += b;
}
sum2r += pk * cos(p.y * logk) * ek;
sum2i -= pk * sin(p.y * logk) * ek;
}
float pow2 = pow(2., -n);
float sumr = sum1r + pow2 * sum2r;
float sumi = sum1i + pow2 * sum2i;
v.x = (sumr * c_re_top - sumi * c_im_top)
/c_bot;
v.y = (sumr * c_im_top + sumi * c_re_top)
/c_bot;
return v;
}
glsl certainly has some quirks. i'll need to check this tomorrow, i'm certain i must have made a mistake in there somewhere.
// v.x and v.y is a velocity at point p
vec2 get_velocity(vec2 p) {
vec2 v = vec2(0., 0.);
const float n = 10.;
float log2 = log(2.);
float pk = pow(2.,1.-p.x);
float c_re_top = 1. - pk*cos(p.y*log2);
float c_im_top = pk*sin(p.y*log2);
float c_bot = c_re_top*c_re_top +
c_im_top*c_im_top;
float sum1r = 0.;
float sum1i = 0.;
for (float k = 1.; k <= n; k++) {
pk = pow(k, -p.x);
if (k == 1.) {
pk = -pk;
}
float logk = log(k);
sum1r += pk * cos(p.y * logk);
sum1i += -pk * sin(p.y * logk);
}
float sum2r = 0.;
float sum2i = 0.;
for (float k = n + 1.; k <= 2.*n; k++){
pk = pow(k, -p.x);
if (k == 1.) {
pk = -pk;
}
float logk = log(k);
float ek = 0.;
for (float j = 0.; j <= n; j++) {
if (j <= k) {continue;}
float b = 1.;
for (float i = 1.; i <= n; i++) {
if (i == j) { break; }
b *= (n + 1. - i)/i;
}
ek += b;
}
sum2r += pk * cos(p.y * logk) * ek;
sum2i -= pk * sin(p.y * logk) * ek;
}
float pow2 = pow(2., -n);
float sumr = sum1r + pow2 * sum2r;
float sumi = sum1i + pow2 * sum2i;
v.x = (sumr * c_re_top - sumi * c_im_top)
/c_bot;
v.y = (sumr * c_im_top + sumi * c_re_top)
/c_bot;
return v;
}
glsl certainly has some quirks. i'll need to check this tomorrow, i'm certain i must have made a mistake in there somewhere.