1. Fractal Landscapes
- Posted by Michael Packard <lgp at EXO.COM> Feb 05, 1998
- 778 views
- Last edited Feb 06, 1998
This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. Send mail to mime at docserver.cac.washington.edu for more info. --655872-198744418-886746114=:3995 Fractal nuts: Here's something. This computes a 2d fractal height map for a landscape and displays and overhead view and quickie 3dish view. color.gif is the color palette. Land.gif is a sample image. When it gets done X[x][y] is the matrix of heights. maxlevel determines the size of the matrix N=(2^maxlevel)+1 -------------------------------------------- --Fractal Landscape Generator version .1 -- --Copyright 1997 Lord Generic Productions -- -------------------------------------------- include get.e include machine.e include image.e include graphics.e include pic_load.e atom seed,Arand,Nrand,GaussAdd,GaussFac --atom x,y sequence X integer maxlevel,addition,i,N --stage, integer D,d atom sigma,H,delta,max,min ------------------------------------------- --initization of Gaussian random thingy Nrand=4 Arand=1000 seed=1234 GaussAdd=sqrt(3*Nrand) GaussFac=2*GaussAdd/(Nrand * Arand) --set_rand(seed) ------------------------------------------ function Gauss() atom sum sum=0 for i = 1 to Nrand do sum=sum+rand(Arand) end for return(GaussFac * sum - GaussAdd) end function ------------------------------------------- function f3(atom delta, atom x0, atom x1, atom x2) atom y,z z=Gauss() y=(x0+x1+x2)/3+delta*Gauss() return(y) end function -------------------------------------------- function f4(atom delta, atom x0, atom x1, atom x2, atom x3) atom y,z z=Gauss() y=(x0+x1+x2+x3)/4+delta*Gauss() return(y) end function --------------------------------------------- maxlevel=7 --initial parameters sigma=2.0 H=.5 addition=1 --------------------------------------------- atom k min=time() N=power(2,maxlevel)+1 delta=sigma X=repeat(0,N) for o=1 to N do X[o]=repeat(0,N) end for X[1][1]=delta*Gauss() X[1][N]=delta*Gauss() X[N][1]=delta*Gauss() X[N][N]=delta*Gauss() D=N-1 d=D/2 for stage= 1 to maxlevel do -- going from grid type I to type II delta = delta * power(.5,.5*H) -- interpolate and offset points for x=d+1 to N-d+1 by D do for y=d+1 to N-d+1 by D do X[x][y]=f4(delta,X[x+d][y+d],X[x+d][y-d],X[x-d][y+d],X[x-d][y-d]) end for end for --displace other points also if necessary if addition then for x=1 to N+1 by D do for y=1 to N+1 by D do X[x][y]=X[x][y] + delta * Gauss() end for end for end if -- going from grid type II to type I delta= delta*power(.5,.5*H) -- interpolate and offset boundary grid points for x = d+1 to N-d+1 by D do X[x][1]=f3(delta,X[x+d][1],X[x-d][1],X[x][d]) X[x][N]=f3(delta,X[x+d][N],X[x-d][N],X[x][N-d]) X[1][x]=f3(delta,X[1][x+d],X[1][x-d],X[d][x]) X[N][x]=f3(delta,X[N][x+d],X[N][x-d],X[N-d][x]) end for --interpolate and offset interior grid points for x = d+1 to N-d by D do for y = D+1 to N-d by D do X[x][y] = f4(delta, X[x][y+d], X[x][y-d], X[x+d][y], X[x-d][y]) end for end for for x = D+1 to N-d by D do for y = d+1 to N-d+1 by D do X[x][y] = f4(delta, X[x][y+d], X[x][y-d], X[x+d][y], X[x-d][y]) end for end for if addition then for x=1 to N by D do for y=1 to N by D do X[x][y]=X[x][y] + delta * Gauss() end for end for for x=d+1 to N-d+1 by D do for y=d+1 to N-d+1 by D do X[x][y]=X[x][y] + delta * Gauss() end for end for end if D=D/2 d=floor(d/2) end for max=time()-min puts(1,"time: ") ?(max) --this tells how long it took to generate ?(length(X)*length(X)) min=255 max=0 for x= 1 to N do for y= 1 to N do k = X[x][y] if k!=0 then k=((k/5)*128)+50 end if if k<1 then k=1 end if X[x][y]=floor(k) if floor(k)<min then min=floor(k) end if if floor(k)>max then max=floor(k) end if end for end for puts(1,"min: ") ?(min) puts(1,"max: ") ?(max) i=wait_key() i = graphics_mode(19) sequence temp temp=read_gif("color.gif") --this gets the palette all_palette(temp[1]/4) display_image({0,0},temp[2]) atom color display_image({0,0},X) for x=1 to N do for y=1 to N do if x=1 or x=N or y=1 or y=N then color=150 else color=X[x][y] end if if color>255 then color=255 end if y]/10+1}}) pixel(color,{180+y-(x/5),50+(x/2)-X[x][y]/20}) end for end for i=wait_key() if i='m' then i=save_screen(0,"land.bmp") end if ---------------------------------------------- --655872-198744418-886746114=:3995
2. Re: Fractal Landscapes
- Posted by Lee woo seob <wslee at HHI.CO.KR> Feb 07, 1998
- 760 views
At 10:21 PM 98/02/05 -0800, you wrote: >Fractal nuts: >Here's something. This computes a 2d fractal height map for a landscape >and displays and overhead view and quickie 3dish view. >color.gif is the color palette. Land.gif is a sample image. > Wow! your's is really a 'something'... professional works... i want to know if your code could be modified to generate SEAMLESS image(top/bottom, left/right). i remember that a codes generating simple 2-d lanscape was once posted on this maillist(several months ago). at that time, the quality of the image generated was not very good, however, it generated top/bottom, left/right seamless image. Bye! from Lee woo seob.
3. Re: Fractal Landscapes
- Posted by Michael Packard <lgp at EXO.COM> Feb 06, 1998
- 767 views
On Sat, 7 Feb 1998, Lee woo seob wrote: > Wow! your's is really a 'something'... professional works... Thanx. > i want to know if your code could be modified to generate SEAMLESS > image(top/bottom, left/right). i remember that a codes generating > simple 2-d lanscape was once posted on this maillist(several months ago). > at that time, the quality of the image generated was not very good, > however, it generated top/bottom, left/right seamless image. A strict fractal image couldn't be seamless because of the nature of fractals, but the fractal data could be massaged once generated. You'd have to mark off a transition area all the way around and average the heights in that area with their couterparts on the other side to smooth the transition. Either that or mirror the data which looks funny at high altitudes. Normally I use Seamless Welder in the Kai Power Tools to make my images seamless. For landscapes I usually just create a bigger data set and use parts of it. I'm now tinkering with the 3d perspective stuff. I'm using the standard 3d projection transform on the points to see how horrible the compute time will be. The next stuff I'll put up will draw polygons, so you can see the detail differences various maxlevel settings will give you. Should be really slow I imagine. Then I'll re-develop the quickie 2d transforms which should be an order of magnitude faster. If someone can write an assembly routine for the 3d rotation transform, let me know. Michael Packard Lord Generic Productions