• Remix
  • Share
  • New Entry

on 9 Nov 2023
  • 10
  • 75
  • 0
  • 1
  • 591
drawframe(1);
p = 1×12
1 5 9 13 17 21 25 29 33 37 41 45
Write your drawframe function below
function drawframe(f)
persistent s n h X d %variables persist over frames so that the same random numbers can be called on each frame
p=[1:4:48]
if ismember(f,p)
if f==1
s=500; % image size in pixels
n=40; %number of stars - some drawn outside display
h=120; %image size in units
X=linspace(-h,h,s);
%pregenerate star positions and sizes (these don't change
d(:,1)=randi(h*1.5,n,1)-h*1.5/2;
d(:,2)=randi(h*1.5,n,1)-h*1.5/2;
d(:,3)=randi(10,n,1)+2; %controls number of spokes on each star
c=rand(n,1)*0.7+0.3; %some stars will be brighter than others
d(:,4)=(rand(n,1)/10+0.9).*c; %stars will have subtly different hues
d(:,5)=(rand(n,1)/10+0.9).*c;
d(:,6)=(rand(n,1)/10+0.9).*c;
end
%generate stars
b=zeros(s,s,3);
for k=1:n
a=zeros(s,s);
%specify centre coordinate of each star and create matrix of angles and radii to use as filters
[t,r]=cart2pol(X+d(k,1)+rand(1,1),X'+d(k,2)+rand(1,1));
r2=((abs(r-max(r(:)))).^(40.*rand(1,1)+50));
%specify radius of star centre
%use angle matrix for spokes and radii matrix (to some random power) for
%radius of star spokes. Specify random integer number of star spokes.
a=sin(t*(d(k,3)+randi(4))).*r2; %creates size and spokes of star
a=(a./max(a(:))); %rescale to range between 0 and 1
%add star centre
a(r<1)=1; %creates central disc
%randomly jitter star RGB values to create some colour variance
v=(.5*rand(1,1)+.5);
b(:,:,1)=b(:,:,1)+a.*d(k,4)*v;
b(:,:,2)=b(:,:,2)+a.*d(k,5)*v;
b(:,:,3)=b(:,:,3)+a.*d(k,6)*v;
end
image(b)
camva(3.5)
end
end
Animation
Remix Tree