• Remix
  • Share
  • New Entry

  • O

  • /
  • Ring world (dark side ver. )

on 30 Nov 2023
  • 7
  • 18
  • 0
  • 0
  • 1337
drawframe(1);
Write your drawframe function below
function drawframe(f)
% Ring world...but ruled by the dark side
persistent H H2 H3 U
if f==1
rng(2,'v4')
ax = axes;
% % % % Make the ring % % % %
r=6; % Radius
N=60; % Number of edge-pixels on base unit
U=8; % Rotating by 1/8 of a circle
% Add texture to ring. Make it tech-y
R=zeros(N,N);
R(randi(N^2, 3))=1;
k1=ones(N/2)/10;
k2=k1;
k2(2:end-1,2:end-1)=0; % Kernel for glowing lights
RL=conv2(R,k2,'same'); % Glowing lights
R=conv2(R,k1,'same'); % Surface
% Tiling
R=repmat(R,[1,U])+1;
RL=repmat(RL,[1,U]);
% Fix seams. Expendable code.
R=s(R,N);
RL=s(RL,N);
RB=(R-1)/2;
RL=RL./RL;
% Notch to fit the land in...
NH=N/2;
NW=floor(N/6);
R(NH-NW+1:NH+NW, :)=0;
% Make our angles
l=@(x)linspace(0,2*pi,x);
ag1=l(N)';
a=l(N*U);
c=cos(a);
v=sin(a);
% Ring torus
b=erf(R.*cos(ag1)*5)+RB; % Make it square-ish
z=R.*sin(ag1);
x=b.*c+r*c;
y=b.*v+r*v;
% Here comes the fleet
H=hgtransform('pa',ax);
surf(x,y,z,'pa',H);
hold on;
H2=hgtransform('pa',ax);
surf(x,y,z,'pa',H2);
H3=hgtransform('pa',ax);
surf(x,y,z,'pa',H3);
material([0,.1,.6,3]);
surf(x,y,z,RL.*cat(3,.9,0,0),'AmbientS',1,'pa',H);
surf(x,y,z,RL.*cat(3,.3,0,0),'AmbientS',1,'pa',H2);
surf(x,y,z,RL.*cat(3,.5,0,0),'AmbientS',1,'pa',H3);
shading flat
% Add stars
x=randn(3,900);
x=x./vecnorm(x)*20;
scatter3(x(1,:),x(2,:),x(3,:),rand(900,1)*20,rand(900,1)*[1,1,1],'.');
% Axis / camera etc.
shading flat
axis equal off;
light('position',[0,0,10]);
light('position',[0,0,-20]);
lighting('gouraud');
shading flat
set(gcf,'color','k');
camproj('perspective')
camva(50);
campos([0 4 -2]);
camtarget([0 10 -2]);
end
set(H,'Ma', makehgtform('translate',[0 .8 0],'zrotate',-(f-1)*pi/4/48));
set(H2,'Ma',makehgtform('translate',[-120 300+f/30 -80],'zrotate',-(f-1)*pi/4/48));
set(H3,'Ma',makehgtform('translate',[50 150+f/50 5],'zrotate',(f-1)*pi/4/48));
end
% Extra functions:
% Seam joiner
function g=s(g, N)
d=g(N, :)/2+g(1, :)/2;
g(1:4, :) = d.*ones(4,1);
g(end-3:end, :) = d.*ones(4,1);
end
Animation
Remix Tree