OK. Here's a first stab at the next challenge. Should be something for everyone here.
1. Make a random island terrain, textured with a random texture, set in an ocean textured with another random texture and a randomly textured sky above.
2. Make the ocean have waves (Nick Thompson is halfway there already).
3. Optional extra: show how recursive functions can help create a random texture.
The idea (as usual) is that everything is done in code, should be fast to set up, smooth and easy to explore and is visually interesting. Code should be short (but more than one line is probably necessary!). [External media are only allowed if (a) they are created and re-used by the program, and (b) they are essential for the relevant DBP commands (such as "set terrain heightmap").]
To give everyone a chance here's a special starting bonus: Green Gandalf's random fractal magic cloud texture generator. Feel free to use, modify or ignore it. A simple way of getting different textures is to modify the final colour components of the final bitmaps produced by my program.
` Green Gandalf's fractal magic cloud maker
` Produces a fractal image based on ideas in following website
` http://www.gameprogrammer.com/fractal.html
` n=8 gives a 256x256 bitmap
set display mode 640,480,32
set text opaque
sync on: sync rate 60: sync
set cursor 20,20
n=8: dispersion#=512: k=0
maxgrid=2^n: g=maxgrid
dim col(3,maxgrid,maxgrid) as float
dim limitedBytes(10)
for i=0 to 10
limitedBytes(i)=128
next i
im=1: gosub makeImage ` prepare initial image
set current bitmap 1
get image 1,0,0,maxgrid+1,maxgrid+1,1
if file exist("testimage.bmp") then delete file "testimage.bmp"
save image "testimage.bmp",1
end
make_bitmap:
create bitmap im,maxgrid+1,maxgrid+1
lock pixels
for i=0 to maxgrid
for j=0 to maxgrid
gosub dotij
next j
next i
unlock pixels
set current bitmap 0
cls
copy bitmap im,0
center text screen width()/2,screen height()/2,"Press any key to continue"
sync
wait key
return
dotij:
dot i,j,rgb(col(1,i,j),col(2,i,j),col(3,i,j))
return
diamond_step:
i=mid: i1=i-mid: i2=i+mid
while i<maxgrid
j=mid: j1=j-mid: j2=j+mid
while j<maxgrid
av#=(col(r,i1,j1)+col(r,i1,j2)+col(r,i2,j1)+col(r,i2,j2))/4.0
` calculate random values between -1 and 1
u#=rnd(16384)/8192.0-1.0
col(r,i,j)=av#+u#*d#`+m#
inc j,g: inc j1,g: inc j2,g
endwhile
inc i,g: inc i1,g: inc i2,g
endwhile
return
square_step:
i=0: i1=i-mid: i2=i+mid: js=0
while i<maxgrid
js=mid-js ` toggle start values of j loop
j=js: j1=j-mid: j2=j+mid
while j<maxgrid+1
av#=0
if i1<0 ` check for need to wrap around i value
inc av#,col(r,i2,j)+col(r,i2,j)
else
if i2>maxgrid
inc av#,col(r,i1,j)+col(r,i1,j)
else
inc av#,col(r,i1,j)+col(r,i2,j)
endif
endif
if j1<0 ` check for need to wrap around j value
inc av#,col(r,i,j2)+col(r,i,j2)
else
if j2>maxgrid
inc av#,col(r,i,j1)+col(r,i,j1)
else
inc av#,col(r,i,j1)+col(r,i,j2)
endif
endif
av#=av#/4
` calculate random value between -1 and 1
u#=rnd(16384)/8192.0-1.0
col(r,i,j)=av#+u#*d#+m#
col(r,maxgrid,j)=col(r,0,j) ` copy opposite edge
inc j,g: inc j1,g: inc j2,g
endwhile
inc i,mid: inc i1,mid: inc i2,mid
endwhile
return
makeImage:
` creates a fractal image loosely based on the "diamond-square algorithm"
cls
randomize timer()
for r=1 to 3 ` process each colour component separately
g=maxgrid
d#=dispersion#
for i=0 to maxgrid
for j=0 to maxgrid
col(r,i,j)=k
next j
next i
` main loop
while g>1
mid=g/2
` diamond step - calculates new diamond corners from squares
gosub diamond_step
` square step - calculates new square corners from diamonds
gosub square_step
d#=d#/2.0: m#=m#/2.0: g=g/2
endwhile
` now scale heightmap values to byte range
min#=col(r,0,0): max#=min#
for i=0 to maxgrid
for j=0 to maxgrid
u#=col(r,i,j)
if u#<min#
min#=u#
else
if u#>max# then max#=u#
endif
next j
next i
max#=256/(max#-min#)
for i=0 to maxgrid
for j=0 to maxgrid
temp=int((col(r,i,j)-min#)*max#)
` range check for byte just in case
if temp<0
col(r,i,j)=0
else
if temp>255
col(r,i,j)=255
else
col(r,i,j)=temp
endif
endif
next j
next i
next r
gosub make_bitmap
return
I'm open to suggestions for changes (within Ric's 24 hr deadline) but expect this to be close enough unless it's too close to previous challenges (feel free to use code from those if you think it helps).
Two week deadline, say 10am UK time 20 May, sound reasonable?