六一了,放松下。
Python iKun
from turtle import *
screensize(1000,1000)
speed(6)
#把衣服画出来,从右肩膀开始
#领子
penup()
goto(-141,-179)
pensize(3)
fillcolor("black")
pencolor("black")
begin_fill()
pendown()
left(1)
forward(336)
circle(-20,100)
right(30)
forward(22)
right(20)
seth(-50)
circle(-200,25)
seth(-180)
forward(420)#最下面的横线
right(95)
circle(-200,27)
left(90)
circle(-12,150)
end_fill()
#画衣服里的线
pensize(6)
pencolor("white")
penup()
goto(-148,-202)
pendown()
seth(-45)
circle(-170,35)
penup()
goto(200,-214)
pendown()
seth(230)
circle(170,32)
penup()
#领子里的线
goto(-148,-202)
pendown()
seth(-17)
forward(200)
left(15)
forward(70)
left(30)
forward(80)
left(12)
forward(30)
penup()
#拉链
goto(100,-265)
pendown()
seth(-90)
forward(100)
penup()
#############开始画头#########
fillcolor("#ffe26c")
goto(-133,-183)
begin_fill()
pendown()
pencolor("black")
pensize(3)
seth(0)
forward(204)
right(25)
forward(40)
circle(60,70)
circle(-70,30)
left(20)
circle(150,55)
seth(90)
forward(80)
penup()
#画右脸
goto(-133,-183)
pendown()
seth(150)
circle(-150,60)
seth(90)
forward(50)
circle(-240.5,171.4)
end_fill()
penup()
#画五官
#右脸蛋
goto(-50,-86)
pencolor("red")
fillcolor("red")
begin_fill()
pendown()
seth(90)
circle(60,360)
end_fill()
penup()
##########眼睛
goto(81,32)
pendown()
pencolor("black")
fillcolor("white")
pensize(4)
begin_fill()
circle(70,360)
end_fill()
begin_fill()
circle(-70,360)
end_fill()
penup()
goto(59,40)
pendown()
begin_fill()
fillcolor("black")
circle(10,360)
end_fill()
penup()
goto(202,40)
pendown()
begin_fill()
circle(10,360)
end_fill()
penup()
#####画嘴
goto(21,-44)
fillcolor("#db8b68")
pencolor("#592404")
pensize(7)
begin_fill()
pendown()
seth(30)
circle(-120,60)
circle(-44,126)
circle(-120,56)
circle(-42,115)
end_fill()
penup()
goto(28,-85)
pendown()
seth(-32)
circle(110,66)
penup()
#画左脸蛋
goto(252,-42)
pendown()
pencolor("red")
fillcolor("red")
begin_fill()
seth(-76)
circle(-100,50)
circle(-26,130)
circle(-100,46)
circle(-30,120)
end_fill()
penup()
#画左侧头发
goto(265,16)
pendown()
pencolor("#584e4f")
fillcolor("#6e676e")
begin_fill()
seth(51)
forward(56)
seth(90)
forward(75)
left(46)
forward(170)
left(28)
forward(130)
seth(180)
circle(50,180)
right(10)
forward(30)
right(45)
forward(130)
seth(9.5)
circle(-100,76)
end_fill()
penup()
####画右侧头发
goto(-208,-41)
pendown()
begin_fill()
seth(200)
forward(50)
right(99)
forward(133)
right(48)
forward(130)
right(12)
forward(100)
right(19)
forward(75)
seth(0)
forward(15)
circle(-42,160)
seth(-91)
forward(150)
seth(170)
forward(50)
left(80)
forward(30)
right(50)
forward(50)
left(11)
forward(80)
end_fill()
exitonclick()
代码解释:
这段代码使用Python的Turtle模块来绘制一个人物的头像。
代码首先导入了Turtle模块的所有内容,然后设置屏幕的尺寸和绘制速度。
接下来,通过一系列的Turtle函数调用,绘制了人物的衣服,包括领子、衣服内部的线条和拉链。然后开始绘制头部,包括头部的形状和颜色。
继续绘制五官,包括脸颊、眼睛和嘴巴。最后绘制了头发部分,包括右侧和左侧的头发形状和颜色。
最后一行的exitonclick()
函数用于在点击屏幕时退出绘图。
Matlab iKun
function kun()
timeDelay = 0.5
% figure('Color','w','Position',[487.5000 431.0000 798.5000 575.0000])
figure('Color','w')
text(-10,40,'f(只因)','FontSize',20)
hold on
axis equal
set(gca,'XLim',[-40 40],'YLim',[-15 40],'FontName','Times')
f = @(x,y) x.^2/16 + y.^2/8 - 1;
mouth1 = fimplicit(f,'-k','LineWidth',2);drawnow;pause(timeDelay)
f = @(x,y) x.^2/16 + y.^2/2 - 1;
mouth2 = fimplicit(f,'-k','LineWidth',2,'YRange',[-10 0]);drawnow;pause(timeDelay)
f = @(x,y) (x+5).^2 + (y-8).^2 - 16;
eye1 = fimplicit(f,'-k','LineWidth',2);drawnow;pause(timeDelay)
f = @(x,y) (x-4.5).^2 + (y-8).^2 - 16;
eye2 = fimplicit(f,'-k','LineWidth',2);drawnow;pause(timeDelay)
f = @(x,y) (x-6).^2 + (y-8).^2 - 1;
eye3 = fimplicit(f,'-k','LineWidth',5);drawnow;pause(timeDelay)
f = @(x,y) (x+4).^2 + (y-8).^2 - 1;
eye4 = fimplicit(f,'-k','LineWidth',5);drawnow;pause(timeDelay)
face1 = draw_offaxis_ellipse(-2,6,16,14,0,[0 pi+1.6/6*pi]);drawnow;pause(timeDelay)
face1.LineWidth = 2;
face1.Color = 'k';
face1_2 = draw_offaxis_ellipse(-2,6,16,14,0,[-1.6/6*pi 0]);drawnow;pause(timeDelay)
face1_2.LineWidth = 2;
face1_2.Color = 'k';
face2 = draw_offaxis_ellipse(-10,0,4,3,pi*0.55*pi,[0 2*pi]);drawnow;pause(timeDelay)
face2.LineWidth = 1;
face2.Color = 'r';
face3 = draw_offaxis_ellipse(10,0,3,2,-pi*0.55*pi,[0 2*pi]);drawnow;pause(timeDelay)
face3.LineWidth = 1;
face3.Color = 'r';
x = -15:0.1:12;
clothes1 = plot(x,0.5*sin(x/3+pi/6+pi/2)-4,'-k','LineWidth',2);drawnow;pause(timeDelay)
x = -13:0.1:10;
clothes2 = plot(x,0.1*sin(x/3+pi/6+pi/2)-8,'-k','LineWidth',2);drawnow;pause(timeDelay)
clothes3 = plot([clothes1.XData(1) clothes2.XData(1)],[clothes1.YData(1) clothes2.YData(1)],'-k','LineWidth',2);drawnow;pause(timeDelay)
clothes4 = plot([clothes1.XData(end) clothes2.XData(end)],[clothes1.YData(end) clothes2.YData(end)],'-k','LineWidth',2);drawnow;pause(timeDelay)
clothes5 = draw_offaxis_ellipse(-1.5,-19.5,15,18,0,[pi*3.2/4 2*pi]);drawnow;pause(timeDelay)
clothes5.LineWidth = 2;
clothes5.Color = 'k';
clothes5_2 = draw_offaxis_ellipse(-1.5,-19.5,15,18,0,[0 pi*0.2]);drawnow;pause(timeDelay)
clothes5_2.LineWidth = 2;
clothes5_2.Color = 'k';
x = -13:0.1:-5;
clothes6 = plot(x,-(x+13).^4/500-8,'-k','LineWidth',2);
x = -13.5:0.1:-5.5;
clothes7 = plot(x,-(x+13).^4/400-9,'-k','LineWidth',2);
x = 5:0.1:13;
clothes8 = plot(x-3,-(13-x).^4/500-8,'-k','LineWidth',2);drawnow;pause(timeDelay)
x = 5.5:0.1:13.5;
clothes9 = plot(x-3,-(13-x).^4/400-9,'-k','LineWidth',2);drawnow;pause(timeDelay)
clothes10 = draw_offaxis_ellipse(-13.3,-8.5,0.5,0.5,pi/3,[pi/6 pi*1.2]);drawnow;pause(timeDelay)
clothes10.LineWidth = 2;
clothes10.Color = 'k';
clothes11 = draw_offaxis_ellipse(10.5,-8.5,0.5,0.5,pi+pi/3,[pi/7 pi*1.3]);drawnow;pause(timeDelay)
clothes11.LineWidth = 2;
clothes11.Color = 'k';
basketball1 = draw_offaxis_ellipse(-12,-10,10,10,pi*0.63,[0 pi]);drawnow;pause(timeDelay)
basketball1.LineWidth = 2;
basketball1.Color = 'k';
x = -21.5:0.1:-10;
basketball2 = plot(x,-(x+22).^3/25-8,'-k','LineWidth',1.5);
basketball2_2 = plot(x,-(x+22.3).^3/25-8.3,'-k','LineWidth',1.5);drawnow;pause(timeDelay)
x = -20.5:0.1:-14;
basketball3 = plot(x,-(x+22).^2/15-5,'-k','LineWidth',1.5);
basketball3_2 = plot(x,-(x+22.3).^2/15-5.3,'-k','LineWidth',1.5);drawnow;pause(timeDelay)
x = -19.5:0.1:-14;
basketball3 = plot(x,(x+18).^2/15-4,'-k','LineWidth',1.5);drawnow;pause(timeDelay)
basketball3_2 = plot(x,(x+18.3).^2/15-4.3,'-k','LineWidth',1.5);drawnow;pause(timeDelay)
hair1 = fplot(@(x) -(abs(x+2)-5).^2/18 + 25,[-22 17]);drawnow;pause(timeDelay)
hair1.LineWidth = 3;
hair1.Color = 'k';
hair2 = fplot(@(x) -(abs(x+2)-3).^2/20 + 23,[-21 -18]);drawnow;pause(timeDelay)
hair2.LineWidth = 2;
hair2.Color = 'k';
hair2_2 = fplot(@(x) -(abs(x+2)-3).^2/20 + 23,[14 16.5]);drawnow;pause(timeDelay)
hair2_2.LineWidth = 2;
hair2_2.Color = 'k';
hair3 = fplot(@(x) -(abs(x)-4).^2/5 + 20,[2 10]);drawnow;pause(timeDelay)
hair3.LineWidth = 2;
hair3.Color = 'k';
hair4 = fplot(@(x) -(abs(x-2)-4).^2/3 + 21,[-8 -2]);drawnow;pause(timeDelay)
hair4.LineWidth = 2;
hair4.Color = 'k';
hair5 = fplot(@(x) -(abs(x+2)-3).^2/15 +19,[-19 -13]);drawnow;pause(timeDelay)
hair5.LineWidth = 2;
hair5.Color = 'k';
hair6 = plot([-22 -19],[12.5 12.7],'-k','LineWidth',2);drawnow;pause(timeDelay)
hair7 = plot([-21 -16],[10.2 10.8],'-k','LineWidth',2);drawnow;pause(timeDelay)
hair8 = plot([-19 -14],[6.2 8],'-k','LineWidth',2);drawnow;pause(timeDelay)
hair9 = plot([-8 -10],[9 13],'-k','LineWidth',2);drawnow;pause(timeDelay)
hair10 = plot([-14 -12],[8 12],'-k','LineWidth',2);drawnow;pause(timeDelay)
hair11 = plot([-10 -12],[12 12],'-k','LineWidth',2);drawnow;pause(timeDelay)
hair12 = plot([10 15.5],[12.9 12],'-k','LineWidth',2);drawnow;pause(timeDelay)
hair13 = plot([17 16.5],[14.1 11],'-k','LineWidth',2);drawnow;pause(timeDelay)
necklace1 = fplot('0.45*abs(x+1.8)-11.5',[-9.1 5.7]);drawnow;pause(timeDelay)
necklace1.LineWidth = 1;
necklace1.Color = 'k';
necklace2 = fplot('0.45*abs(x+1.8)-12',[-8.5 5.5]);drawnow;pause(timeDelay)
necklace2.LineWidth = 1;
necklace2.Color = 'k';
necklace3 = draw_offaxis_ellipse(-2,-13,1,1.5,0,[0 2*pi]);drawnow;pause(timeDelay)
necklace3.LineWidth = 3;
necklace3.Color = 'k';
end
function h = draw_offaxis_ellipse(cx,cy,a,b,theta,range)
% theta = pi/4;
% range = [0 2*pi];
t = linspace(range(1),range(2),100);
x = cos(t)*a;
y = sin(t)*b;
rotatematrix = [cos(theta) -sin(theta);sin(theta) cos(theta)];
rotatedxy = rotatematrix*[x;y];
h = plot(rotatedxy(1,:)+cx,rotatedxy(2,:)+cy);
end
这段代码定义了一个名为"kun"的函数,用于绘制一个人物的头像。
函数首先设置了一个时间延迟变量timeDelay
为0.5,并创建了一个白色背景的绘图窗口。
接下来,函数使用一系列的Turtle函数来绘制人物的头像,包括绘制嘴巴、眼睛、脸部等部分。每绘制一个部分后,通过drawnow
函数和pause
函数实现绘图的实时显示和暂停一段时间,以便观察绘制的过程。
在函数中还定义了一个名为draw_offaxis_ellipse
的辅助函数,用于绘制一个偏离轴心的椭圆。该函数接受中心坐标(cx,cy)、长轴(a)、短轴(b)、旋转角度(theta)和绘制范围(range)作为参数,并返回绘制的椭圆对象。
整个函数通过一系列的绘制函数和参数设置,完成了绘制人物头像的过程。
请注意,这段代码使用的绘图函数和参数可能涉及到某个特定的绘图库或工具包,因此无法直接在一般的Python环境中运行。要运行此代码,你可能需要查看代码的完整上下文,了解涉及的绘图库,并在相应的环境中运行。
Reference
本来挺喜欢Python的,现在更喜欢了
练习matlab两年半,画一幅浓浓学术味的只因图