新年的第一把🔥是佩奇,那啥是佩奇呢?爷爷(R)喊话佩奇。
爷爷:佩奇你好!我是爷爷。你看这文章能有多🔥。
佩奇:你好爷爷!我是佩奇。今年我最🔥。
爷爷:佩奇,你搁哪呢?
佩奇:你甭管我在哪!你看我这灯多亮!
爷爷:爷爷在这,还不现身,来拜个年。
佩奇:请开始你的表演。。。
启动神力,召唤“佩奇”:
通过 R绘制点图,点动成线的原理,终于召唤出“佩奇”
普及知识点:向量的合并,全局变量,函数,绘制点图。
最后:“猪”福大家,新年快乐
第一步:画脸蛋
##脸蛋
outline<- function(star, end, step){
a<- seq(from=star,to = end, by =step);pi<-3.14156;
for( t in a ) {
x<-c((t^10+1)*cos(pi/6-2*pi*(15*t/16 + 1/16)));
y<-c((t**10+1)*sin(pi/6-2*pi*(15*t/16 + 1/16)));
dx<<- c(dx, x);
dy<<- c(dy, y);}};
outline(0,1, 0.001); #生成点
plot(dx, dy);#描点
画脸蛋
第二步:画下巴
##下巴
chin<-function(star,end, step){
a<- seq(from=star,to = end, by =step);pi<-3.14156;
for( t in a ) {
x1<-c(4*t/5+1);
y1<-c(1/3*t^2+1/7);
dx<<- c(dx, x1);
dy<<- c(dy, y1);}}
chin(0,1, 0.01);#描点 plot(dx,dy);
画下巴
第三步:画鼻子,眼睛
##鼻子点
nose<- function(star, end, step){
a<- seq(from=star,to = end, by =step);pi<-3.14156;
for( t in a){
x<-c(1/4*cos(2*pi*t)+ 8/5);y<-c(sin(2*pi*t)/3+ 7/10);
x1<-c(cos(2 * pi * t) / 16 + 59 / 40);
y1<-c(sin(2 * pi * t) / 16 + 7 / 10);
x2<-c(cos(2 * pi * t) / 16 + 69 / 40);
y2<-c(sin(2 * pi * t) / 16 + 7 / 10);
dx<<-c(dx, x, x1, x2);dy<<-c(dy, y, y1, y2)}};
##眼睛点
eye<- function(star, end, step){
a<- seq(from=star,to = end, by =step);pi<-3.14156;
for( t in a){
x<-c(0.15*cos(2 * pi * t));y<-c(0.15*(sin(2 * pi * t)+5.3333));
x1<-c(0.15 * (cos(2 * pi * t)+4));y1<-c(0.15 * (sin(2 * pi * t) + 6));
x2<-c(0.05 * cos(2 * pi * t));y2<-c(0.05 * (sin(2 * pi * t) + 16));
x3<-c(0.05 * (cos(2 * pi * t)+12));y3<-c(0.05 * (sin(2 * pi * t) + 18));
dx<<-c(dx, x, x1, x2, x3);dy<<-c(dy, y, y1, y2, y3);}};
画鼻子,眼睛
第四步:画嘴巴,耳朵
##嘴巴点
mouth<- function(star, end, step){
a<- seq(from=star,to = end, by =step);pi<-3.14156;
for( t in a){x<-c(t-1/3);y<-c((t-2/5)^2);
dx<<-c(dx, x);dy<<-c(dy, y);}};
##耳朵点
ear<- function(star, end, step){
a<- seq(from=star,to = end, by =step);pi<-3.14156;
for( t in a){
x<-c((2*t**2-2*t-1) * sin((2*t+pi)/6));
y<-c(-(2*t**2-2*t-1) * cos((2*t+pi)/6));
x1<-c((2 * t ** 2 - 2 * t - 1) * sin(t/3));
y1<-c(-(2 * t ** 2 - 2 * t - 1) * cos(t/3));
dx<<-c(dx, x, x1);dy<<-c(dy, y, y1);}};
画嘴巴,耳朵
和爷爷的佩奇比一比,是不是更胜一筹呢???
爷爷的佩奇对比
最后奉上字符版佩奇,“猪”大家新年快乐