Skip to content

Commit b86b785

Browse files
authored
Merge pull request #2 from zachguo/main
fix #1
2 parents 8fd0208 + e23728b commit b86b785

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

deno_lib/mod.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,18 @@ export function makeSphereSurface(
143143
);
144144
const field = new Array(circumference);
145145
for (let x = 0; x < circumference; x++) {
146-
field[x] = new Array(circumference);
147-
for (let y = 0; y < circumference; y++) {
146+
const circumferenceSemi = circumference / 2
147+
field[x] = new Array(circumferenceSemi);
148+
for (let y = 0; y < circumferenceSemi; y++) {
149+
const [nx, ny] = [x / circumference, y / circumferenceSemi];
150+
const [rdx, rdy] = [nx * TWO_PI, ny * Math.PI];
151+
const sinY = Math.sin(rdy + Math.PI);
152+
const a = TWO_PI * Math.sin(rdx) * sinY;
153+
const b = TWO_PI * Math.cos(rdx) * sinY;
154+
const d = TWO_PI * Math.cos(rdy);
148155
let value = 0.0;
149156
for (let octave = 0; octave < octaves; octave++) {
150157
const freq = frequency * Math.pow(2, octave);
151-
const [nx, ny] = [x / circumference, y / circumference];
152-
const [rdx, rdy] = [nx * TWO_PI, ny * Math.PI];
153-
const sinY = Math.sin(rdy + Math.PI);
154-
const a = TWO_PI * Math.sin(rdx) * sinY;
155-
const b = TWO_PI * Math.cos(rdx) * sinY;
156-
const d = TWO_PI * Math.cos(rdy);
157158
value += noise3(a * freq, b * freq, d * freq) *
158159
(amplitude * Math.pow(persistence, octave));
159160
}

src/mod.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,18 @@ export function makeSphereSurface(
143143
);
144144
const field = new Array(circumference);
145145
for (let x = 0; x < circumference; x++) {
146-
field[x] = new Array(circumference);
147-
for (let y = 0; y < circumference; y++) {
146+
const circumferenceSemi = circumference / 2
147+
field[x] = new Array(circumferenceSemi);
148+
for (let y = 0; y < circumferenceSemi; y++) {
149+
const [nx, ny] = [x / circumference, y / circumferenceSemi];
150+
const [rdx, rdy] = [nx * TWO_PI, ny * Math.PI];
151+
const sinY = Math.sin(rdy + Math.PI);
152+
const a = TWO_PI * Math.sin(rdx) * sinY;
153+
const b = TWO_PI * Math.cos(rdx) * sinY;
154+
const d = TWO_PI * Math.cos(rdy);
148155
let value = 0.0;
149156
for (let octave = 0; octave < octaves; octave++) {
150157
const freq = frequency * Math.pow(2, octave);
151-
const [nx, ny] = [x / circumference, y / circumference];
152-
const [rdx, rdy] = [nx * TWO_PI, ny * Math.PI];
153-
const sinY = Math.sin(rdy + Math.PI);
154-
const a = TWO_PI * Math.sin(rdx) * sinY;
155-
const b = TWO_PI * Math.cos(rdx) * sinY;
156-
const d = TWO_PI * Math.cos(rdy);
157158
value += noise3(a * freq, b * freq, d * freq) *
158159
(amplitude * Math.pow(persistence, octave));
159160
}

0 commit comments

Comments
 (0)