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 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Roberto
le 27 Avr 2014
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 commentaires
Voir également
Catégories
En savoir plus sur Fractals dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!