1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| function christmas
snow=800;
h=0:0.2:25; [X,Y,Z] = cylinder(tree(h)); Z=Z*25;
treeDiffusion=rand(126,21)-0.5;
for cnt1=1:21 for cnt2=16:126 angle=atan(Y(cnt2,cnt1)/X(cnt2,cnt1)); X(cnt2,cnt1)=X(cnt2,cnt1)+cos(angle)*treeDiffusion(cnt2,cnt1); Y(cnt2,cnt1)=Y(cnt2,cnt1)+sin(angle)*treeDiffusion(cnt2,cnt1); Z(cnt2,cnt1)=Z(cnt2,cnt1)+(rand-0.5)*0.5; end end
surfl(X,Y,Z,'light')
r=(0.0430:(0.2061/50):0.2491)'; g=(0.2969:(0.4012/50):0.6981)'; b=(0.0625:(0.2696/50):0.3321)'; map=[r,g,b]; for cnt=1:6 map(cnt,:)=[77,63,5]/265; end
colormap(map) view([-37.5,4]) lighting phong shading interp axis equal axis([-10 10 -10 10 0 30]) axis off hold on title('HAPPY HOLIDAYS')
drawPresent(2,-4,0,3,3,2); drawPresent(-4,3,0,2,3,1.5); drawPresent(5,3,0,4,3,3); drawPresent(-14,-5,0,6,3,1); drawPresent(-9,-10,0,2,2,2); drawPresent(0,4,0,4,3,3); drawPresent(-6,-13,0,3,3,3);
snowX=(rand(snow,1)*25-12.5); snowY=(rand(snow,1)*25-12.5); snowZ=(rand(snow,1)*27);
plot3(snowX,snowY,snowZ,'w*') hold off end
function r=tree(h)%Gives a profile for the tree for cnt=1:length(h) if(h(cnt)==0) r(cnt)=0; end if (h(cnt)>0 && h(cnt)<=3) r(cnt)=1.5; end
if(h(cnt)>3) r(cnt)=8-(h(cnt)-3)*0.3636; end
end
end
function drawPresent(dx,dy,dz,scalex,scaley,scalez)
presentX=[0.5 0.5 0.5 0.5 0.5; 0 1 1 0 0; 0 1 1 0 0; 0 1 1 0 0; 0.5 0.5 0.5 0.5 0.5]; presentY=[0.5 0.5 0.5 0.5 0.5; 0 0 1 1 0; 0 0 1 1 0; 0 0 1 1 0; 0.5 0.5 0.5 0.5 0.5]; presentZ=[0 0 0 0 0; 0 0 0 0 0; 0.5 0.5 0.5 0.5 0.5; 1 1 1 1 1; 1 1 1 1 1];
myHandle=surf((presentX*scalex+dx),(presentY*scaley+dy), (presentZ*scalez+dz));
randColorMap(:,:,1)=repmat(rand,[5,5]); randColorMap(:,:,2)=repmat(rand,[5,5]); randColorMap(:,:,3)=repmat(rand,[5,5]);
set(myHandle,'CData',randColorMap) shading interp
end
|