craze4you
Junior Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору ребят, никто не поможет адаптировать этот алгоритм для матлаба? должно быть просто, но что-то совсем нифига не работает. Код: FUNCTION Voss_RandomAdditions, N ; generate Voss fractional Browninan motion in two dimension. ; see"Fractals" by Jen Feder page 180 ; R. F. Voss, "Random Fractal Forgeries", in "Fundimental Algorithms for Computer Graphics", ; editor R. A. Earnshaw, NATO ASI Series F, Computer and System Sciences, Vol 17, 1985. ; This uses the Successive Random Additions algorithm rather than the Successive Random Displacement ; algorithm which Voss shows to be non-stationary. ;****** NOTE FUDGE NOTE FUDGE ******************* ; The lines: ; IF i EQ 7 THEN Var = Var*0.9 ; IF i EQ 8 THEN Var = Var*0.85 ; IF i EQ 9 THEN Var = Var*0.5 ; have been added in two places to correct the high frequency rise present in the Voss spectrum ;****** NOTE FUDGE NOTE FUDGE ******************* nX = 2^N ; size of 2-D region modelled X = FLTARR(nX+1,nX+1) ; this will hold the fractal surface H = 1.0/3.0 ; dimension of surface is 3-H Var = 1.0 ; variance of largest scale STD = SQRT(Var) L = 2^N ; L is the largest scale computer so far LD2 = L/2 ; L/2 is the scale currently being computed nL = 1 IDxL = [0] IDxLD2 = [LD2] IDxLPL = [L] IDxLnX = [ 0 , L ] FOR i = 0 , N-1 DO BEGIN ;************************************************************* ;** Stage 1: calculate the values at square centres ** ;************************************************************* ; i.e we know A and are calculating B in A A ; B ; A A ; Do all the interior centre interpolation points FOR iLy = 0 , nL-1 DO $ X[IDxLD2,LD2+iLy*L] = 0.25*( X[IDxL,iLy*L] + X[IDxLPL,iLy*L] + X[IDxL,iLy*L+L] + X[IDxLPL,iLy*L+L] ) + STD*RANDOMN(SEED,nL) ; Update the previously calculated points FOR iLy = 0 , nL DO $ X[IDxLnX,iLy*L] = X[IDxLnX,iLy*L] + STD*RANDOMN(SEED,nL+1) Var = Var * SQRT(0.5)^(2.0*H) ; adjust variance ; IF i EQ 7 THEN Var = Var*0.9 ; IF i EQ 8 THEN Var = Var*0.85 ; IF i EQ 9 THEN Var = Var*0.5 STD = SQRT(Var) ;***************************************************************** ;** Stage 2: calculate the values around square centres ** ;***************************************************************** ; i.e we know A and B and are calculating C in ACA ; CBC ; ACA ; The complexity comes from dealing with C's on the outer edge of the region ; Do all the boundary interpolation points ; Top and bottom X[IDxLD2,0] = 0.5*( X[IDxL,0 ] + X[IDxLPL,0 ] ) + STD*RANDOMN(SEED,nL) X[IDxLD2,nX] = 0.5*( X[IDxL,nX] + X[IDxLPL,nX] ) + STD*RANDOMN(SEED,nL) ; Left and right X[0 ,IDxLD2] = 0.5*( X[0 ,IDxL] + X[0 ,IDxLPL] ) + STD*RANDOMN(SEED,nL) X[nX,IDxLD2] = 0.5*( X[nX,IDxL] + X[nX,IDxLPL] ) + STD*RANDOMN(SEED,nL) ; Do all the C's inside the region FOR iLy = 1 , nL-1 DO $ X[IDxLD2,iLy*L] = 0.25*( X[IDxL,iLy*L] + X[IDxLPL,iLy*L] + X[IDxLD2,iLy*L-LD2] + X[IDxLD2,iLy*L+LD2] ) + STD*RANDOMN(SEED,nL) IF i GT 0 THEN BEGIN IDxL = IDxL[1:nL-1] FOR iLy = 0 , nL-1 DO $ X[IDxL,LD2+iLy*L] = 0.25*( X[IDxL,iLy*L] + X[IDxL,iLy*L+L] + X[IDxL-LD2,LD2+iLy*L] + X[IDxLD2,LD2+iLy*L] ) + STD*RANDOMN(SEED,nL) ENDIF ;***************************************************** ;** Halve the scale for the next iteration ** ;***************************************************** L = L/2 LD2 = LD2/2 nL = nL*2 IDxL = INDGEN(nL)*L IDxLD2 = IDxL + LD2 IDxLPL = IDxL + L IDxLnX = [ IDxL , nX ] ; Update the previously calculated points FOR iLy = 0 , nL DO $ X[IDxLnX,iLy*L] = X[IDxLnX,iLy*L] + STD*RANDOMN(SEED,nL+1) Var = Var * SQRT(0.5)^(2.0*H) ; adjust variance ; IF i EQ 7 THEN Var = Var*0.9 ; IF i EQ 8 THEN Var = Var*0.85 ; IF i EQ 9 THEN Var = Var*0.5 STD = SQRT(Var) ENDFOR RETURN, X END | |