Jump to content

Draw a sphere: Difference between revisions

→‎Fun with 3D noise texture: Reverted the "small changes", as they resoulted in a worse, probably incorrect picture. I might have made a mistake.
m (→‎{{header|REXX}}: change internal subroutine name. -- ~~~~)
(→‎Fun with 3D noise texture: Reverted the "small changes", as they resoulted in a worse, probably incorrect picture. I might have made a mistake.)
Line 326:
 
#define MAXD 8
int g[] = { -1, 01, -1, 1 };
/* Perlin-like noise */
inline void
Line 348:
# undef ror
for (i = len; i--; ) {
out[i] = g[h %& 3];
h />>= 32;
}
}
Line 368:
register int i, j;
int n[MAXD], o[MAXD], g[MAXD], tmp;
double s, r, t, w, ret, u[MAXD];
 
sum(s, x[j]);
Line 385:
tmp = o[i], o[i] = o[j], o[j] = tmp;
 
if ret = (w >= 0), *pr = 501;
sum(r, n[j]);
rfor (s *= (0, j = 0; j < d; j++) s += scale_un[dj]);
s *= scale_u[d];
for (j = 0; j < d; j++) u[j] = x[j] + r - n[j];
 
for (i = 0; i <= d; i++) {
for (j = 0; j < d; j++) u[j] = x[j] + r - n[j];
u[j] = x[j] + s - n[j];
 
for (rett = 0(d + 1.) / (2 * d), ij = 0; ij <= d; ij++) {
for ( t -= (d + 1.) / (2u[j] * d), u[j = 0]; j < d; j++)
if ((t -= u[j] * u[j]) <= 0) break;
}
 
if (t >= 0) {
Line 398 ⟶ 402:
hashed(n, g, d);
for (j = 0; j < d; j++)
if (g[j]) r += (g[j] == 1 ? u[j] : -u[j]);
r += u[j];
else if (g[j] == -1)
r -= u[j];
 
t *= t;
ret += r * t * t;
Line 408:
 
if (i < d) {
n[o[i]]++, u[o[i]]--;
for (js += 0; j < scale_u[d; j++) u[j] += s;
}
}
Line 417:
double get_noise2(double x, double y)
{
int i, ws;
double ws, r = 0, v[2];
 
for (i = 1, ws = 0; i <= 64128; i <<= 1) {
v[0] = x * i, v[1] = y * i;
r += noise(v, 2);
Line 431:
double get_noise3(double x, double y, double z)
{
int i, ws;
double r = 0, v[3], w, ws;
 
for (i = 1, ws = 0; i <= 832; i <<= 1) {
v[0] = x * i, v[1] = y * i, v[2] = z * i;
w = 1./sqrt(i);
Line 451:
FILE *fp;
 
ddd = atoi(v[1]);
noise_init();
 
Line 459 ⟶ 460:
for (j = 0; j < 256; j++, p++) {
x = (j - 128) / 125.;
//*p = (get_noise2(i/256., j/256.) + 1) / 6 * i;
*p = (get_noise2(i/256., j/256.) + 1) * 100;
 
z = 1- x*x - y*y;
Line 466:
 
z = sqrt(z);
 
w = get_noise3(x, y, -z);
if (w > 0) *p = 50;
 
w = get_noise3(x, y, z);
if (w < 0) continue;
 
w = (1.5w + x - y + z1) / 3.52;
w *= (1 + x - y + z) / 3.5;
if (w < 0) continuew = 0;
 
*p = w * 255;
}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.