How do i create a basic pattern of stars like a triangle shape using loops, array addressing, input and output commands and conditional statements

3 次查看(过去 30 天)
I tried using loops to do this but i couldnt get it to work very well but it is just a basic triangle shape with 5 rows

回答(1 个)

Roberto
Roberto 2014-4-27
Try using probability functions for fractals... have a look in to this code and adapt it to draw whatever you want (as long as is a fractal like stars!!):
t(:,:,1) = [0 0 ;0 .16] ;
t(:,:,2) = [.85 0.04 ;-.04 .85] ;
t(:,:,3) = [.2 -.26 ;.23 .22] ;
t(:,:,4) = [-.15 0.28 ;.26 .24] ;
s(:,:,1) = [0 ;0] ;
s(:,:,2) = [ 0 ; 1.6] ;
s(:,:,3) = [ 0 ; 1.6] ;
s(:,:,4) = [ 0 ; .44] ;
lim = [.01 .86 .93 1];
n = input('Points: ');
x = zeros(2,n);
for i= 2 : n
u = rand(1) ;
[j] = find(lim >= u, 1) ;
x(:,i) = t(:,:,j)* x(:,i-1)+s(:,:,j);
end
y = x(2,:) ;
x = x(1,:) ;
figure ;
plot(x,y,'.') ;

类别

Help CenterFile Exchange 中查找有关 Fractals 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by