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
0 件のコメント
回答 (1 件)
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,'.') ;
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!