赞
踩
最后制作的效果图
制作的代码,写的比较乱,后面还有皮卡丘动画,有需要可以私我。
def tree(n,l): pd()#下笔 #阴影效果 t = cos(radians(heading()+45))/8+0.25 pencolor(t,t,t) pensize(n/2) forward(l)#画树枝 if n>0: b = random()*15+10 #右分支偏转角度 c = random()*15+10 #左分支偏转角度 d = l*(random()*0.25+0.7) #下一个分支的长度 #右转一定角度,画右分支 right(b) tree(n-1,d) #左转一定角度,画左分支 left(b+c) tree(n-1,d) #转回来 right(c) else: #画叶子 right(90) n=cos(radians(heading()-45))/4+0.5 begin_fill() pencolor(n, n * 0.8, n * 0.8) color(n, n * 0.8, n * 0.8) circle(4) end_fill() left(90) #添加0.3倍的飘落叶子 if(random()>0.7): pu() #飘落 t = heading() an = 240+random()*40 setheading(an) dis = int(800*random()*0.5 + 400*random()*0.3 + 200*random()*0.2) forward(dis) setheading(t) #画叶子 pd() right(90) n = cos(radians(heading()-45))/4+0.5 pencolor(n*0.5+0.5,0.4+n*0.4,0.4+n*0.4) circle(2) left(90) pu() #返回 t=heading() setheading(an) backward(dis) setheading(t) pu() backward(l)#退回 def petal(m): # 树下花瓣 for i in range(m): n = cos(radians(heading() - 45)) / 4 + 0.5 a = 600- 1200 * random() b = 30 - 60 * random() up() forward(b) left(90) forward(a) down() # 淡珊瑚色 color(n, n * 0.8, n * 0.8) circle(2) up() backward(a) right(90) backward(b) def getPosition(x, y): t.setx(x) t.sety(y) print(x, y) if __name__ == '__main__': bgcolor(0.5, 0.5, 0.5) # 背景色 screensize(850, 800) t.setup(850, 800) ht() # 隐藏turtle speed(0) # 速度 1-10渐进,0 最快 tracer(1, 0) pu() # 抬笔 backward(100) left(90) # 左转90度 pu() # 抬笔 getPosition(0, -300) tree(12, 100) # 递归7层 petal(1000) width, height = 800, 600 #转换背景 t.bgcolor("black") t.delay(0) # 这里要设为0,否则很卡 t = Turtle(visible=False, shape='circle') print('画背景') t.pencolor("white") t.fillcolor("white") t.penup() t.setheading(-90) t.goto(width / 2, randint(-height / 2, height / 2)) stars = [] for i in range(200): star = t.clone() s = random() / 3 star.shapesize(s, s) star.speed(int(s * 10)) star.sety(width / 2 + randint(1, width)) star.setx(randint(-height / 2, height / 2)) star.showturtle() stars.append(star) for i in range(1, 100): for star in stars: star.sety(star.ycor() - 3 * star.speed()) if star.xcor() < -width / 2: star.hideturtle() star.sety(width / 2 + randint(1, width)) star.setx(randint(-height / 2, height / 2)) star.showturtle() clearscreen()
1.可修复性
编程所得的画面,所有的图案都是可修改可拷贝的,且不会有任何影响。而手绘的画作,一旦落笔,可修复性就很差了,不免会出现“一个墨点毁了一幅画”的情况。
2.顺序性
码绘可以选择先绘制任何图形,再通过移动代码的位置改变它们的遮挡关系。而在手绘的过程中,不得不先总体确定有哪些图案先绘制,或需要保留完整性,以及剩余图案的分布和位置。
3.素材选择性
以颜色为例,RGB的三个数值,囊括了所有可视颜色。而在手绘的颜色工具相比之下则少得多。
4.重复性
对于有规律可循的图形,编程绘画便很有优势,恰当地使用循环、嵌套等语句,简单的一些函数便可以减少很多工作量。相比而言手绘则更加按部就班,且绘制重复图案时不可避免会有微小的差异。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。