- /
- 
        Abduction of Happy Sheep
        on 14 Oct 2024
        
        
 
    - 31
- 330
- 1
- 6
- 1784
 Cite your audio source here (if applicable): Audio generated by MATLAB
Borrowing code from a couple of memorable minihacks from years past:
Happy Sheep by Victoria:
Cloudy bits in tractor beam by Jenny:
function drawframe(f)
    persistent T C S Sc ST zr
    if f==1 || isempty(T)
        %% Starry Night Sky
        % Borrowed from lonely lighthouse from last year
        rng(0)
        imagesc([-1 1],[0 1],(1:256)');
        colormap(gca,abyss.^2) % square to get more black, but it made the blue niftier too
        hold on
        N=120;
        si=rand(1,N); % Size and Color are related, so use same random #s
        scatter(rand(1,N)*2-1,rand(1,N),(si+.2)*40,(si*.5+.5)'.*[1 1 1],'Marker','.');
        set(gca,'pos',[0 0 1 1]);
        axis([-1 1 0 1]);
        %% Flying Saucer
        axes('pos',[0 0 1 1],'clipping','off'); % 3D axes for animation
        T=hgtransform;
        % Handy sphere
        [X,Y,Z]=sphere(50);
        % Ship body
        surface(T,X*1.5,Y*1.5,Z*.4,'FaceColor','#bbc','EdgeColor','none');
        % Glass Dome
        surface(T,X*.5,Y*.5,abs(Z),'FaceColor','#5ff','EdgeColor','none');
        zr=0; % saucer rotates - this trax where.
        lighting g
        %% Beam of Light
        C=hgtransform(T,'vis','off');
        [cX,cY,cZ] = cylinder;
        % Light Beam Cylinder
        surface(C,cX.*[.3;.9],cY.*[.3;.9],cZ*-1,'FaceColor','w','EdgeColor','none',...
                ...'FaceAlpha','interp','AlphaData',cZ+[.1;-.5]);
                'FaceAlpha','texture','AlphaData',clouds);
        alphamap(0:.01:.5);
        %% A sheep to abduct
        % Shamelessly borrow Victoria's "Happy Sheep" because it is awesome.
        S=hgtransform(T,'vis','off');
        Sc=[.05 .3 1];
        ST=hgtransform(S,'Matrix',makehgtform('scale',Sc));
        happysheep(ST);
        % Axes Decoration
        view(0, 10);
        axis([-5 5 -5 5 1 11],'off','vis3d');        
        camlight
    end
    %% Transform objects to tell a story!
    % commands are very wordy.  Shorten.
    tf=@makehgtform;
    tft=@(m)tf('translate',m);
    tfs=@(m)tf('scale',m);
    zr=zr+.2;
    tfz=@(m)tf('zrotate',zr);
    if f<21
        T.Matrix = tft([-(20-f)/2 0 9]);
    elseif f<25
        C.Visible = 'on';
        C.Matrix = tfs([1 1 (f-21)/4*10+2])*tfz();
    elseif f<73
        S.Visible = 'on';
        r=(f-73)/24;
        S.Matrix = tft([0 0 r*5]);
        ST.Matrix = tfs(Sc.*[(.8-r)*.5 1 (.8-r)*2]);
        C.Matrix = tfs([1 1 10])*tfz();
    elseif f<77
        S.Visible = 'off';
        C.Visible = 'on';
        C.Matrix = tfs([1 1 5-(f-75)/4*10])*tfz();
    else
        C.Visible = 'off';
        T.Matrix = tft([10-(96-f)/2 0 9]);
    end
end
function M=clouds()
% A short code snippet from Jenny's cloudy sky from 300char minihack.
% https://www.mathworks.com/matlabcentral/communitycontests/contests/4/entries/4211
    X=-164:.646:164;
    [~,r]=cart2pol(X,X'-60);
    M=1.5E4*abs(ifft2(r.^-1.65.*cos(6*rand(508))));
end
function happysheep(parent)
% Happy Sheep!
% By Victoria A. Sablina
% https://www.mathworks.com/matlabcentral/discussions/tips/847476-how-to-draw-a-happy-sheep-in-matlab
% Handles
    s=@sin;
    c=@cos;
    % Ellipse + Rose
    F=@(t,a,f) a(1)*f(t)+s(a(2)*t).*f(t)+a(3);
    % Angles
    t=0:.1:7;
    % Parameters
    % Head (1:2)
    % Eyes (3:6)
    % Hoofs (7:14)
    % Crown (15:16)
    % Body (17:18)
    % Tail (19:20)
    G=-13;
    P=[5 7 repmat([.1 .5],1,6) 6 4 14 9 3 3;zeros(1,14) 8 8 12 12 4 4;...
       -15 2 G 3 -17 3 -3 G 0 G 9 G 12 G -15 12 4 3 20 7];
    % Painting
    for i=1:10
        % plot(F(t,P(:,2*i-1),c),F(t,P(:,2*i),s),'LineWidth',10);
        % Use same trick, but create filled patch
        p=fill(parent,F(t,P(:,2*i-1),c),F(t,P(:,2*i),s),'w');
        p.FaceLighting = 'none';
        if any(i==(2:7))
            % Make the hooves more visible against night sky
            p.LineWidth=2.5;
            p.EdgeColor='#883';
        else
            p.LineWidth=.5;
            p.EdgeColor='#222';
        end
    end
end


 
 
             
            