Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Matlab to draw a lovely Jack-o'- lantern

Shulou Source: shulou.com Published: 2022-06-01 11:53:58 10月03日 Update

This article mainly introduces how to use Matlab to draw a lovely pumpkin, the text is very detailed, has a certain reference value, interested friends must read!

Effect and Principle

The effects are as follows:

Adjust the data and change it to triangular eyes:

principle

The pumpkin body function comes from a graph of Zhiyou [Nine Chapters Algorithm], which is roughly a piecewise function of the melon body and handle, and then rotates around the z axis to get a curved surface. I have made fine adjustments to the values. The original image and the original data:

implementation method

Here I deliberately kept the grid to make the pumpkin look a little bit like a rag doll.(You can also rewrite it according to your own preferences, such as setting 'EdgeColor' to 'none' and lighting it up.)

% construct grid [t,p]=meshgrid(linspace(0,2*pi,200),linspace(0,pi-.05,200));% bivariate piecewise function foutline=@(t,p)(p.14).* (cos(20.* t)+70).* (p.* (pi-p+.1)).^. 2;% spherical coordinates converted to X,Y,Zh=cos(p).* foutline(t,p);R=sin(p).* foutline(t,p);R=R;X=cos(t).* R;Y=sin(t).* R;% Color matrix construction CMap=ones([size(t),3]);tMap=ones(size(t));c1=[253,158,3]./ 255;c2=[76,103,86]./ 255;for i=1:3 tMap(:,:)=c1(i); tMap(p50&maskX130&maskY45&maskX90&maskY85&maskX90&maskY45&maskX90&maskY80&maskX90&maskY45&maskX90&maskY-35))=1;% mask(maskX>45&maskX90&maskY80&maskX90&maskY45&maskX90&maskY80&maskX90&maskY

Tags: Pumpkin function mouth coordinates sphere grid color small one cute light source content principle effect data surface matrix article original body code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno Apple vpn Linux