• Remix
  • Share
  • New Entry

on 1 Dec 2023
  • 10
  • 19
  • 1
  • 1
  • 859
drawframe(1);
Write your drawframe function below
function drawframe(f)
% This is Xor's AMAZING shader
% https://www.shadertoy.com/view/cstBzn
% Here is my translation to MATLAB
iRes = [1600,900];
iTime = f*3/48;
persistent fragCoord
if isempty(fragCoord)
[x,y]=meshgrid(1:iRes(1),iRes(2):-1:1);
fragCoord = cat(3,x',y');
end
im = mainImage(fragCoord);
im = imresize(im, flip(iRes), 'method', 'bilinear');
imagesc(im);
axis equal
axis off
function finalColor=mainImage( fragCoord )
finalColor = zeros(iRes(1), iRes(2), 3);
r = cat(3,iRes(1),iRes(2));
p = (fragCoord.* 2 - r)./iRes(2);
N = 24;
p(:,:,2) = p(:,:,2) + 0.5 ;
a = atan2(p(:,:,1),p(:,:,2)) + pi/2;
l = vecnorm(p,2,3).*N;
R = min(ceil(l),N);
c = [2, 4, 6];
a = a .* R;
for j = 1:3
b1 = sqrt(cos(l./N.*5 + c(j)) + 1);
b2x = clamp(a, 0., R.*pi/2.*(1-sin(iTime./0.5+R./N.*1.5*pi)))-a;
b2y = (l - R + 0.5);
b2 = cat(3,b2x,b2y);
b3 = min((0.4 - vecnorm(b2,2,3)).*iRes(2)./100, 0.7);
finalColor(:,:,j) = b1.* b3;
end
finalColor = permute(finalColor,[2 1 3]);
end
end
function result = clamp(x, lower, upper)
result = max(min(x, upper), lower);
end
Animation
Remix Tree