Found it
// Project: land
// Created: 2018-02-16
// show all errors
// ***************************************************************************************************
// Ken Perlin's Simplex Noise 2D. AGK Version.
// Ported from Stefan Gustavson's Java implementation
// (http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf)
// 2015.02.03
// AGK reference https://forum.thegamecreators.com/thread/213532
// Thank you Thank you
SetErrorMode(2)
SetVSync(1)
// set window properties
SetWindowTitle( "land" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
global world
// Set window properties
Global w as integer = 100
Global h as integer =100
Global z as float = 5
SetWindowTitle( "NoiseTest" )
SetWindowSize( 800, 600, 1 )
// Set display properties
SetVirtualResolution( 800, 600 )
SetOrientationAllowed( 1, 1, 1, 1 )
// Initialize simplex noise
#constant mapx=100
#constant mapy=100
global blocks as integer[mapx,mapy,mapx] // x, y, z
global perlinmap as integer[mapx,mapy,256]
NoiseInit()
map=CreateSprite(generateperlinimage())
yy=0
for xx=0 to mapx-1
for zz=0 to mapy-1
blocks[xx,yy,zz] = CreateObjectBox(1,1,1)
SetObjectPosition(blocks[xx,yy,zz],xx,perlinmap[xx,zz,0],zz)
if perlinmap[xx,zz,0]=0 then SetObjectColor(blocks[xx,yy,zz],0,0,255,255)
if perlinmap[xx,zz,0]=1 then SetObjectColor(blocks[xx,yy,zz],68,235,214,255)
if perlinmap[xx,zz,0]=2 then SetObjectColor(blocks[xx,yy,zz],255,255,0,255)
if perlinmap[xx,zz,0]>3 then SetObjectColor(blocks[xx,yy,zz],0,255,0,255)
// if perlinmap[xx,zz,0]=4 then SetObjectColor(blocks[xx,yy,zz],255,255,255,255)
// if perlinmap[xx,zz,0]=5 then SetObjectColor(blocks[xx,yy,zz],255,255,255,255)
next
next
SetCameraRange(1,.01,1000)
cx#=getobjectx(blocks[mapx/2,0,0]):cy#=getobjecty(blocks[0,0,0])+40:cz#=getobjectz(blocks[0,0,0])-60
do
SetCameraPosition(1,cx#,cy#,cz#)
// inc cx#,
// inc cy#,.1
// inc cz#,.1
if GetRawKeyState(37) then dec cx#,.5
if GetRawKeyState(39) then inc cx#,.5
if GetRawKeyState(38)
dec cz#,.5
// dec cy#,.5
endif
if GetRawKeyState(40) then inc cz#,.5
if GetRawKeyState(83) then dec cy#,.5
if GetRawKeyState(87) then inc cy#,.5
if GetRawKeyState(69) then RotateCameraLocalX(1,1)
if GetRawKeyState(67) then RotateCameraLocalX(1,-1)
if GetRawKeyPressed(27) then end
print(GetRawLastKey())
sync()
loop
function generateperlinimage()
// Generate image from memblock
size = w * h * 4 + 12
mem = CreateMemblock(size)
SetMemblockInt(mem,0,w)
SetMemblockInt(mem,4,h)
SetMemblockInt(mem,8,32)
offset as integer = 12
a as float, b as float
a = 5.0
b = 2.0
for y = 0 to h - 1
for x = 0 to w - 1
a = a + 0.0001
b = b + 0.002
// Try out these two noise methods
//noise = 255.0*Noise2D(x/10.0,y/10.0)
noise = 255.0*Noise2D(x/100.0,y/100.0)
noise = abs(noise)
perlinmap[x,y,0]=noise/10
//clouds
if noise>200
SetMemblockByte(mem, offset, noise)
SetMemblockByte(mem, offset+1, noise)
SetMemblockByte(mem, offset+2, noise)
SetMemblockByte(mem, offset+3, 255)
endif
//greenary
if noise>150 and noise<=200
SetMemblockByte(mem, offset, 0)
SetMemblockByte(mem, offset+1, noise)
SetMemblockByte(mem, offset+2, 0)
SetMemblockByte(mem, offset+3, 255)
endif
//sand
if noise>100 and noise<=150
SetMemblockByte(mem, offset, noise)
SetMemblockByte(mem, offset+1, noise)
SetMemblockByte(mem, offset+2, 0)
SetMemblockByte(mem, offset+3, 255)
endif
// water
if noise<=100
SetMemblockByte(mem, offset, 0)
SetMemblockByte(mem, offset+1, 0)
SetMemblockByte(mem, offset+2, noise)
SetMemblockByte(mem, offset+3, 255)
endif
offset = offset + 4
next
next
map=CreateImageFromMemblock(mem)
endfunction map
// interopolation for RGB
// send in colorfrom
// colorto - this maybe sky color
// t - time it takes so this could be travelling down to earth
/*
to be converted
public static Color LerpRGB (Color a, Color b, float t)
{
return new Color
(
a.r + (b.r - a.r) * t,
a.g + (b.g - a.g) * t,
a.b + (b.b - a.b) * t,
a.a + (b.a - a.a) * t
);
}
*/
// ***************************************************************************************************
// Ken Perlin's Simplex Noise 2D. AGK Version.
// Ported from Stefan Gustavson's Java implementation
// (http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf)
// 2015.02.03
// AGK reference https://forum.thegamecreators.com/thread/213532
// Thank you Thank you
#constant PN3DF2 = 0.5*(sqrt(3.0)-1.0)
#constant PN3DG2 = (3.0-sqrt(3.0))/6.0
Type sPNVECTOR
x as float
y as float
z as float
endtype
Global PNHash as integer[512]
Global PNGrad3 as sPNVECTOR[256]
Function NoiseInit()
Local n as integer, rn as integer
For n=0 To 255
PNHash[n] = n
Next n
For n=0 To 255
rn=Random(0, 255)
PNHash.swap(n,rn)
Next n
For n=0 To 255
PNHash[256 + n] = PNHash[n]
Next n
PNHash[511] = PNHash[0]
For n=0 To 15
PNGrad3[n * 16 + 0].x = 1 : PNGrad3[n * 16 + 0].y = 1 : PNGrad3[n * 16 + 0].z = 0
PNGrad3[n * 16 + 1].x = -1 : PNGrad3[n * 16 + 1].y = 1 : PNGrad3[n * 16 + 1].z = 0
PNGrad3[n * 16 + 2].x = 1 : PNGrad3[n * 16 + 2].y = -1 : PNGrad3[n * 16 + 2].z = 0
PNGrad3[n * 16 + 3].x = -1 : PNGrad3[n * 16 + 3].y = -1 : PNGrad3[n * 16 + 3].z = 0
PNGrad3[n * 16 + 4].x = 1 : PNGrad3[n * 16 + 4].y = 0 : PNGrad3[n * 16 + 4].z = 1
PNGrad3[n * 16 + 5].x = -1 : PNGrad3[n * 16 + 5].y = 0 : PNGrad3[n * 16 + 5].z = 1
PNGrad3[n * 16 + 6].x = 1 : PNGrad3[n * 16 + 6].y = 0 : PNGrad3[n * 16 + 6].z = -1
PNGrad3[n * 16 + 7].x = -1 : PNGrad3[n * 16 + 7].y = 0 : PNGrad3[n * 16 + 7].z = -1
PNGrad3[n * 16 + 8].x = 0 : PNGrad3[n * 16 + 8].y = 1 : PNGrad3[n * 16 + 8].z = 1
PNGrad3[n * 16 + 9].x = 0 : PNGrad3[n * 16 + 9].y = -1 : PNGrad3[n * 16 + 9].z = 1
PNGrad3[n * 16 + 10].x = 0 : PNGrad3[n * 16 + 10].y = 1 : PNGrad3[n * 16 + 10].z = -1
PNGrad3[n * 16 + 11].x = 0 : PNGrad3[n * 16 + 11].y = -1 : PNGrad3[n * 16 + 11].z = -1
PNGrad3[n * 16 + 12].x = 1 : PNGrad3[n * 16 + 12].y = 1 : PNGrad3[n * 16 + 12].z = 0
PNGrad3[n * 16 + 13].x = -1 : PNGrad3[n * 16 + 13].y = 1 : PNGrad3[n * 16 + 13].z = 0
PNGrad3[n * 16 + 14].x = 0 : PNGrad3[n * 16 + 14].y = -1 : PNGrad3[n * 16 + 14].z = 1
PNGrad3[n * 16 + 15].x = 0 : PNGrad3[n * 16 + 15].y = -1 : PNGrad3[n * 16 + 15].z = -1
Next n
endfunction
function Noise2D(xin as float, yin as float)
local n0 as float, n1 as float, n2 as float, s as float, t as float, x0 as float, y0 as float, xs as float, ys as float
local i as integer, j as integer, i1 as integer, j1 as integer, i2 as integer, j2 as integer, gi0 as integer, gi1 as integer, gi2 as integer
local x1 as float, y1 as float, x2 as float, y2 as float, x3 as float, y3 as float, t0 as float, t1 as float, t2 as float
s = (xin + yin) * PN3DF2
xs = xin + s
i = floor(xs)
ys = yin + s
j = floor(ys)
t = (i + j) * PN3DG2
x0 = xin - (i - t)
y0 = yin - (j - t)
if x0>y0
i1=1
j1=0
else
i1=0
j1=1
endif
x1 = x0 - i1 + PN3DG2
y1 = y0 - j1 + PN3DG2
x2 = x0 - 1.0 + 2.0 * PN3DG2
y2 = y0 - 1.0 + 2.0 * PN3DG2
i = i && 255
j = j && 255
gi0 = PNHash[i + PNHash[j]] && 15
gi1 = PNHash[i + i1 + PNHash[j + j1]] && 15
gi2 = PNHash[i + 1 + PNHash[j+ 1]] && 15
t0 = 0.5 - x0*x0-y0*y0
if t0<0
n0 = 0.0
else
t0 = t0 * t0
n0 = t0 * t0 * (PNGrad3[gi0].x * x0 + PNGrad3[gi0].y * y0)
endif
t1 = 0.5 - x1*x1-y1*y1
if t1<0
n1 = 0.0
else
t1 = t1 * t1
n1 = t1 * t1 * (PNGrad3[gi1].x * x1 + PNGrad3[gi1].y * y1)
endif
t2 = 0.5 - x2*x2-y2*y2
if t2<0
n2 = 0.0
else
t2 = t2 * t2
n2 = t2 * t2 * (PNGrad3[gi2].x * x2 + PNGrad3[gi2].y * y2)
endif
endfunction 70.0 * (n0 + n1 + n2)