Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best algorithm for a 2D Perlin Noise ?
#11
Antoni Gual saying to Jark "it's really fast"... Must be a kind of Spanish virus that crossed the Pyrenean moutains :wink:
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#12
Antoni, this virus is dangerous...

Code:
DIM Cloud%(129, 129)

RANDOMIZE TIMER
T0 = TIMER

' Init the corners
Cloud%(1, 1) = 128
Cloud%(1, 129) = 128
Cloud%(129, 1) = 128
Cloud%(129, 129) = 128

' Init the edges
FOR Rank% = 1 TO 7

Grid% = 2 ^ (7 - Rank% + 1)
nStep% = 2 ^ (Rank% - 1) + 1

FOR kx% = 1 TO nStep% - 1
x% = (kx% - 1) * Grid% + 1: y% = 1
Alt% = (Cloud%(x%, y%) + Cloud%(x% + Grid%, y%)) / 2
zNew% = INT(Alt% * (1 + (RND - .5) / (2 ^ Rank%)))
Cloud%(x% + Grid% / 2, 1) = zNew%
Cloud%(x% + Grid% / 2, 129) = zNew%
NEXT kx%

FOR ky% = 1 TO nStep% - 1
x% = 1: y% = (ky% - 1) * Grid% + 1
Alt% = (Cloud%(x%, y%) + Cloud%(x%, y% + Grid%)) / 2
zNew% = INT(Alt% * (1 + (RND - .5) / (2 ^ Rank%)))
Cloud%(1, y% + Grid% / 2) = zNew%
Cloud%(129, y% + Grid% / 2) = zNew%
NEXT ky%

NEXT Rank%


' Fill the clouds
FOR Rank% = 1 TO 7

Grid% = 2 ^ (7 - Rank% + 1)
nStep% = 2 ^ (Rank% - 1) + 1

FOR kx% = 1 TO nStep% - 1
x% = (kx% - 1) * Grid% + 1
FOR ky% = 1 TO nStep% - 1
y% = (ky% - 1) * Grid% + 1

Alt% = (Cloud%(x%, y%) + Cloud%(x% + Grid%, y%) + Cloud%(x%, y% + Grid%) + Cloud%(x% + Grid%, y% + Grid%)) / 4
Cloud%(x% + Grid% / 2, y% + Grid% / 2) = INT(Alt% * (1 + (RND - .5) / (2 ^ Rank%)))
Alt% = (Cloud%(x%, y%) + Cloud%(x% + Grid%, y%)) / 2
IF y% <> 1 THEN Cloud%(x% + Grid% / 2, y%) = INT(Alt% * (1 + (RND - .5) / (2 ^ Rank%)))
Alt% = (Cloud%(x%, y%) + Cloud%(x%, y% + Grid%)) / 2
IF x% <> 1 THEN Cloud%(x%, y% + Grid% / 2) = INT(Alt% * (1 + (RND - .5) / (2 ^ Rank%)))
Alt% = (Cloud%(x% + Grid%, y%) + Cloud%(x% + Grid%, y% + Grid%)) / 2
IF (x% + Grid%) <> 129 THEN Cloud%(x% + Grid%, y% + Grid% / 2) = INT(Alt% * (1 + (RND - .5) / (2 ^ Rank%)))
Alt% = (Cloud%(x%, y% + Grid%) + Cloud%(x% + Grid%, y% + Grid%)) / 2
IF (y% + Grid%) <> 129 THEN Cloud%(x% + Grid% / 2, y% + Grid%) = INT(Alt% * (1 + (RND - .5) / (2 ^ Rank%)))

NEXT ky%
NEXT kx%

NEXT Rank%
dt = TIMER - T0
CLS
PRINT dt
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#13
You could also change all
Code:
result= INT(anything/something)
to
Code:
result=anything\something

Integer division is faster...

Also you could precalculate an array of powers of 2... Big Grin
Antoni
Reply
#14
It's only a sphere, and I don't control everything yet, but that's a beginning...

[Image: Sphere.jpg]
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#15
I seriously need to develop an regular antialiasing routine... my smoothering filter only handles black spots.

[Image: Pcube.jpg]
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#16
:o :o :o :o :o :o :o :o :o :o :o :o :o
Antoni
Reply
#17
*jaw drops!!!!
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)