Anonymous user
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,
/* Perlin-like noise */
inline void
Line 348:
# undef ror
for (i = len; i--; ) {
out[i] = g[h
h
}
}
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;
s *= scale_u[d];
for (j = 0; j < d; j++) u[j] = x[j] + r - n[j];▼
for (i = 0; i <= d; i++) {
u[j] = x[j] + s - n[j];
if
}
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]);
t *= t;
ret += r * t * t;
Line 408:
if (i < d) {
n[o[i]]++
}
}
Line 417:
double get_noise2(double x, double y)
{
int i, ws;
double
for (i = 1, ws = 0; i <=
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
for (i = 1, ws = 0; i <=
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.;
z = 1- x*x - y*y;
Line 466:
z = sqrt(z);
▲ if (w > 0) *p = 50;
w = get_noise3(x, y, z);
if (w < 0) continue;▼
w = (
w *= (1 + x - y + z) / 3.5;
*p = w * 255;
}
|