'2d simplex noise global simx_f2 global simx_g2 dim global simx_perm(511),simp_gx(7),simp_gy(7) simx_perm_data: data 151,160,137,91,90,15,131,13 data 201,95,96,53,194,233,7,225 data 140,36,103,30,69,142,8,99 data 37,240,21,10,23,190,6,148 data 247,120,234,75,0,26,197,62 data 94,252,219,203,117,35,11,32 data 57,177,33,88,237,149,56,87 data 174,20,125,136,171,168,68,175 data 74,165,71,134,139,48,27,166 data 77,146,158,231,83,111,229,122 data 60,211,133,230,220,105,92,41 data 55,46,245,40,244,102,143,54 data 65,25,63,161,1,216,80,73 data 209,76,132,187,208,89,18,169 data 200,196,135,130,116,188,159,86 data 164,100,109,198,173,186,3,64 data 52,217,226,250,124,123,5,202 data 38,147,118,126,255,82,85,212 data 207,206,59,227,47,16,58,17 data 182,189,28,42,223,183,170,213 data 119,248,152,2,44,154,163,70 data 221,153,101,155,167,43,172,9 data 129,22,39,253,19,98,108,110 data 79,113,224,232,178,185,112,104 data 218,246,97,228,251,34,242,193,238 data 210,144,12,191,179,162,241 data 81,51,145,235,249,14,239,107 data 49,192,214,31,181,199,106,157 data 184,84,204,176,115,121,50,45 data 127,4,150,254,138,236,205,93 data 222,114,67,29,24,72,243,141 data 128,195,78,66,215,61,156,180 simp_grad: data 1,1, -1,1, 1,-1, -1,-1 data 1,0, -1,0, 0,1, 0,-1 simx_f2=0.5*(sqr(3)-1) simx_g2=(3-sqr(3))/6 restore simx_perm_data for i=0 to 255 read v simx_perm(i)=v 'doubled to avoid index wrap simx_perm(i+256)=v next i restore simp_grad for i=0 to 7 read simp_gx(i),simp_gy(i) next i sub noise2d(xin,yin,result) 'skew input space to the simplex grid s=(xin+yin)*simx_f2 i=floor(xin+s) j=floor(yin+s) t=(i+j)*simx_g2 'distance from cell origin, unskewed x0=xin-(i-t) y0=yin-(j-t) 'which of the two triangles are we in? if x0>y0 then i1=1 j1=0 else i1=0 j1=1 end if 'offsets for the other two corners x1=x0-i1+simx_g2 y1=y0-j1+simx_g2 x2=x0-1+2*simx_g2 y2=y0-1+2*simx_g2 'hashed gradient indices (and 255 wraps, and 7 picks a gradient) ii=i and 255 jj=j and 255 gi0=simx_perm(ii +simx_perm(jj )) and 7 gi1=simx_perm(ii+i1+simx_perm(jj+j1)) and 7 gi2=simx_perm(ii+1 +simx_perm(jj+1 )) and 7 n0=0 :n1=0 :n2=0 'corner 0 contribution t0=0.5-x0*x0-y0*y0 if t0>0 then t0=t0*t0 n0=t0*t0*(simp_gx(gi0)*x0+simp_gy(gi0)*y0) end if 'corner 1 t1=0.5-x1*x1-y1*y1 if t1>0 then t1=t1*t1 n1=t1*t1*(simp_gx(gi1)*x1+simp_gy(gi1)*y1) end if 'corner 2 t2=0.5-x2*x2-y2*y2 if t2>0 then t2=t2*t2 n2=t2*t2*(simp_gx(gi2)*x2+simp_gy(gi2)*y2) end if 'scale to roughly -1..1 result=70*(n0+n1+n2) end sub 'user's function that actually draw cells of the world '(in) l,t = left and top position in world-cell-coords '(in) (w,h) = with and height dimension in world-cell-coords 'it will ask to draw horizontal or vertical lines from the world sub inf_world(l,t,w,h) bg 3 'another idea is to generate on the fly what to draw 'here using a simplex noise generator n=0 if w>h then 'drawing an horizontal line for x=0 to w-1 call noise2d((l+x)*0.11,t*0.11,n) p=floor((n+1)*0.5*6) p=clamp(p,0,6) pal p cell l+x,t,1 next x else if winfw then 'world is bigger than the view l=infl*infs r=(infr+1)*infs-infw 'prevent to past beyond if infxr then infx=r else 'world is small than the view, center it infx=-(infw-infpw)/2 end if 'in y axis if infph>infh then 'world is bigger than the view t=inft*infs b=(infb+1)*infs-infh if infyb then infy=b else 'world is small than the view, center it infy=-(infh-infph)/2 end if call inf_scroll(infx,infy) goto inf_prepare inf_prepare: 'rectangle of the view, the portion of the visible world 'a.k.a.: view position in world-cell-coords infpl=int(infx/infs)-infco infpt=int(infy/infs)-infco infpr=int((infx+infw)/infs)+infco infpb=int((infy+infh)/infs)+infco return inf_draw: 'render missing world cells at left if infplinfl then dec infcl if infcr-infcl>=64 then dec infcr call inf_world(infcl,infct,1,infcb-infct+1) end if 'render missing cells at right if infpr>infcr and infcr=64 then inc infcl call inf_world(infcr,infct,1,infcb-infct+1) end if 'render missing cells at top if infptinft then dec infct if infcb-infct>=64 then dec infcb call inf_world(infcl,infct,infcr-infcl+1,1) end if 'render missing cells at bottom if infpb>infcb and infcb=64 then inc infct call inf_world(infcl,infcb,infcr-infcl+1,1) end if return #1:MAIN PALETTES 09023700090136010901350109013401 09013301090131010901300108012F01 #2:DEFAULT CHARACTERS 00000000000000000000000000000000 0000000000000000FFFFFFFFFFFFFFFF 006C7E36120000000000121212000000 00247E3F367E3F120000001B12001B12 00083E3F1E3F1F040000000710011704 0062753A142E57230000113204081123 001C3E3A7E773A1D00000A021013001D 00181C3C180000000000040C18000000 000C1E3C38180C060000060C08000006 0030180C0E1E3C180000000002060C18 0000241A7E3F2C120000000200270812 0000181C7E3F1C0C000000040027040C 00000000181C3C180000000000040C18 000000007E3F000000000000003F0000 0000000000181C0C000000000000040C 00060F1E3C787020000003060C183020 003C7E7F777F3F1E000018110119031E 00183C1C1C1C7E3F000004040404003F 003C7E3F1E3C7E3F00001833060C003F 003C7E3F06673F1E000018330001031E 0066777F3F0707030000110139010103 007E7F7C3E077F3E00001F003801033E 001C3E7C7E773F1E00000E001811031E 007E3F0F1E3C381800003903060C0818 003C7E3F7E773F1E000018031811031E 003C7E3F1F673F1E000018011901031E 000000180C180C00000000000C000C00 000000180C183C18000000000C000C18 00000C1E3C180C06000000060C000006 0000007E3F7E3F00000000003F003F00 000030180C1E3C180000000000060C18 003C7E3F1E0C180C00001833060C000C 003C7E7F7F773C1E000018111117001E 00183C7E7F7F77330000001801191133 007C7E7F7E777F3E000018031811033E 003C7E7370763F1E000018131010031E 00787C76777F7E3C000010101113063C 007E7F787C707E3F00001F001C10003F 007E7F787C70703000001F001C101030 003C7E7E77773F1E00001E101111031E 0066777F7F7777330000110119111133 003C1E1C1C1C3C1E000006040404001E 001E0F0707673F1E000009010101031E 00667F7E7C7C76330000130604101033 0060707070707E3F000010101010003F 0042677F7F7F77330000010101191133 0066777F7F7777330000010111111133 003C7E7777773F1E000018111111031E 007C7E7F7E707030000018031E101030 003C7E777B7D3E1F000018111111001F 007C7E7F7E7C76330000180306101033 003E7F3C1E077F3E00001F001801033E 007E3F1C1C1C1C0C000027040404040C 0066777777773F1E000011111111031E 00667777773F1E0C000011111103060C 0066777F7F7F73210000110101193121 00663F1E3C7E77330000030600181133 0066773F1E1C1C0C000011030604040C 007E3F1E3C787E3F000033060C18003F 003C3E3838383C1E00000E080808001E 006030180C0603010000000000000101 003C1E0E0E0E3E1E000012020202021E 00183C7E330000000000001833000000 0000000000007E3F000000000000003F #3:CITY BG 00007005000300030003000300031003 10030003000300030003000300031003 10030003000300030003000310030003 00030003000300030003100300030003 10030003000300030003000300030003 00030003000310031003000300030003 00030003100300030003000300030003 0003100309030A032003210301000100 0100010009030A032003210329032203 29032A0309030A032003210329032A03 290309030A0320032103220309030A03 29032A03200321032203290309030A03 200321032903220329032A0309030A03 2003210329032A03290309030A032003 2103220319031A033003310301003203 3903010019031A033003310339033203 39033A0319031A033003310339033A03 390319031A0330033103320319031A03 39033A03300331033203390319031A03 300331033903320339033A0319031A03 3003310339033A03390319031A033003 310332033E033E0301003E033E033E03 3E033E033E033E033E033E033E033E03 3E033E033E033E033E033E033E033E03 3E033E033E033E033E033E033E033E03 3E033E033E033E033E033E033E033E03 3E033E033E033E033E033E033E033E03 3E033E033E033E033E033E033E033E03 3E033E033E033E033E033E033F033F03 3E033E033E033E033E033E033F033F03 3E033E033E033E033E033E033E033E03 3F033E033E033E033E033F033E033E03 3E033E033E033E033F033F033E033E03 3E033E033F033F033E033E033E033E03 3E033E033E033E033F033E033E033E03 3E033F03000300030003000300031003 10030003000300030003000300031003 10030003000300030003000310030003 00030003000300030003100300030003 10030003000300030003000300030003 00030003000310031003000300030003 00030003100300030003000300030003 0003100309030A032003210301000100 0100010009030A032003210329032203 29032A0309030A032003210329032A03 290309030A0320032103220309030A03 29032A03200321032203290309030A03 200321032903220329032A0309030A03 2003210329032A03290309030A032003 2103220319031A033003310301003203 3903010019031A033003310339033203 39033A0319031A033003310339033A03 390319031A0330033103320319031A03 39033A03300331033203390319031A03 300331033903320339033A0319031A03 3003310339033A03390319031A033003 310332033E033E0301003E033E033E03 3E033E033E033E033E033E033E033E03 3E033E033E033E033E033E033E033E03 3E033E033E033E033E033E033E033E03 3E033E033E033E033E033E033E033E03 3E033E033E033E033E033E033E033E03 3E033E033E033E033E033E033E033E03 3E033E033E033E033E033E033F033F03 3E033E033E033E033E033E033F033F03 3E033E033E033E033E033E033E033E03 3F033E033E033E033E033F033E033E03 3E033E033E033E033F033F033E033E03 3E033E033F033F033E033E033E033E03 3E033E033E033E033F033E033E033E03 3E033F03