- /
-
O Christmas Tree
on 1 Dec 2023
- 15
- 91
- 0
- 1
- 648
drawframe(40);
function drawframe(f)
% This is Xor's AMAZING shader
% https://www.shadertoy.com/view/7lKSzw
% Here is my translation to MATLAB
iRes = 300;
iTime = f/48*2;
persistent fragCoord
if isempty(fragCoord)
[x,y]=meshgrid(1:iRes, 1:iRes);
fragCoord = cat(3,x,flip(y,1));
end
im = mainImage(fragCoord);
im = imresize(im, [3*iRes, 3*iRes], 'method', 'bilinear');
imshow(im);
axis equal
axis off
%% magic
function finalColor = mainImage(fragCoord)
finalColor = zeros(iRes, iRes, 3);
r = cat(3,iRes,iRes);
for i=0:400
if mod(i,8) < 6
even = mod(i,2);
c = [even,1- even,0];
else
c = [1 1 1];
end
p = (fragCoord.* 2 - r)./r(:,:,2).*300 + cat(3,0,i-230)....
+ cat(3,i+mod(i,99),i/4).*cos(iTime.*0.5+cat(3,i,i+11)).*0.5;
for j = 1:3
finalColor(:,:,j) = finalColor(:,:,j) + c(j)./vecnorm(p,2,3).^2;
end
end
finalColor = sqrt(finalColor./0.1);
end
end
Animation
![](/responsive_image/300/300/0/0/0/cache/matlabcentral/communitycontests/uploaded_files/19804/animation.gif?a=true)