当前位置:网站首页>80% of the people answered incorrectly. Does the leaf on the apple logo face left or right?
80% of the people answered incorrectly. Does the leaf on the apple logo face left or right?
2022-07-07 23:56:00 【Ali Yiyang】
Everyone should know about Apple Mobile , But you can tell what it really is logo Do you ? This paper mainly introduces the application of Python Medium turtle Library control function drawing Apple logo And similar patterns , It is said that 80% All the people chose the wrong .
One 、 Effect display
Before I introduce the code , Let's first look at the implementation effect of this paper .
Choose what you think is right from the following options logo, It is said that there is 80% All the people chose the wrong , See if you can choose the right .
Two 、 Code details
Python Draw true and false logo The principle is : application turtle The library draws the outer frame and the inner frame in turn logo.
1 Import library
First, import the library to be loaded in this article , If you don't have some libraries installed , Cause the running code to report an error , Can be in Anaconda Prompt of use pip Method installation .
# -*- coding: UTF-8 -*-
''' Code usage : Draw apples logo author : Ali Yiyang official account : The code of Ali Yiyang '''
import os
import time
import pygame
import turtle as t
This article applies to fewer libraries , Only os、time、pygame and turtle Four Libraries .
os The library can set the location where files are read .
time Library is used to set the code pause time .
pygame The library is designed to make the drawing process more interesting , Added background music during drawing .
turtle Library is a drawing library , It's equivalent to giving you a brush , You can draw on the canvas with code controlled by mathematical logic .
2 Play music
Then apply pygame Library playing background music , The music of this article is 《 All I think are stars 》.
os.chdir(r'F:\ official account \58. True and false logo\ Apple ')
# Play music
print(' Play music ')
pygame.mixer.init()
pygame.mixer.music.load("CMJ - All I think are stars .mp3")
pygame.mixer.music.set_volume(0.5)
pygame.mixer.music.play(1, 10)
This part of the code is separated from the whole code , You can choose to put the code at the beginning , You can also delete . If you choose to play music , Need to be in code music.load Function to fill in the local storage address of the computer where you want to play music . Some friends have questions about this piece , For filling format, please refer to the following pictures :
3 Define drawing logo Function of
Then set the size of the drawing board , And define drawing logo Function of , Due to the different orientation of leaves , Two functions are defined according to the orientation .
t.title(' The official account of Ali ESEY code ')
t.speed(10)
#t.screensize(1000, 800)
t.setup(startx=0, starty = 0, width=800, height = 600)
def draw_logo(x, y):
t.penup()
t.goto(x, y)
t.pendown()
t.color('gray')
t.begin_fill()
t.setheading(150)
t.circle(30, 90)
# Arc on the left
t.left(10)
t.circle(50, 70)
# Lower small radian
t.circle(20, 60)
# The depression below
t.setheading(20)
t.circle(-40, 40)
# Lower small radian
t.circle(18, 60)
t.left(5)
t.circle(50, 76)
t.left(8)
t.circle(31, 91)
t.end_fill()
# Draw leaves
t.penup()
t.goto(x, y+9)
t.pendown()
t.color('gray')
t.begin_fill()
t.setheading(90)
t.circle(-20, 90)
t.setheading(-90)
t.circle(-20, 90)
t.end_fill()
def draw_logo2(x, y):
t.penup()
t.goto(x, y)
t.pendown()
t.color('gray')
t.begin_fill()
t.setheading(150)
t.circle(30, 90)
# Arc on the left
t.left(10)
t.circle(50, 70)
# Lower small radian
t.circle(20, 60)
# The depression below
t.setheading(20)
t.circle(-40, 40)
# Lower small radian
t.circle(18, 60)
t.left(5)
t.circle(50, 76)
t.left(8)
t.circle(31, 91)
t.end_fill()
# Draw leaves
t.penup()
t.goto(x, y+9)
t.pendown()
t.color('gray')
t.begin_fill()
t.setheading(180)
t.circle(-20, 90)
t.setheading(0)
t.circle(-20, 90)
t.end_fill()
Key code details :
t.pensize(width): Sets the size of the brush .
t.color(color): Set the color of the brush .
t.penup(): Lift up the brush. , It is generally used for drawing in another place .
t.goto(x,y): The brush goes to a certain position , Parameter is (x,y), Corresponding abscissa and ordinate .
t.pendown(): Put down the paintbrush , In general, and penup Use a combination of .
t.left(degree): How many degrees does the brush turn left , Degrees in parentheses .
t.right(degree): How many degrees does the brush turn right , Degrees in parentheses .
t.circle(radius,extent,steps):radius Finger radius , If it is positive , The radius is on the left side of the little turtle radius Far away , If it's negative , The radius is on the right side of the little turtle radius Far away ;extent Refers to radian ;steps Finger order .
draw logo The key is : By adjusting the circle Function to adjust the radian of the curve , Thus making logo The outline of is relatively smooth .
4 Define functions for writing text
Then define the function of writing text , It is convenient to write the title and the serial number corresponding to the picture in the specified position .
def write_1(x, y, size, ss):
t.hideturtle()
t.penup()
t.goto(x, y)
t.pendown()
t.pensize(30)
t.pencolor('black')
t.write(ss, font=('YouYuan', size, 'normal'))
x: The starting abscissa of the text .
y: The starting ordinate of the text .
size: Size of text .
ss: written words .
5 Draw the outer border and call the function to draw logo
Finally, draw the outer border and call function in turn logo, And write the serial number and title .
# Outside frame
print(' Outside frame ')
t.penup()
t.goto(200, -200)
t.pendown()
t.setheading(90)
t.color('gray')
t.forward(400)
t.setheading(180)
t.forward(400)
t.setheading(-90)
t.forward(400)
t.setheading(0)
t.forward(400)
# Draw two lines inside
print(' Draw two lines inside ')
t.penup()
t.goto(0, 200)
t.pendown()
t.setheading(270)
t.forward(400)
t.penup()
t.goto(-200, 0)
t.pendown()
t.setheading(0)
t.forward(400)
# draw logo
print(' draw logo')
#A
draw_logo(-100, 130)
#B
draw_logo(100, 130)
#C
draw_logo(-100, -70)
#D
draw_logo2(100, -70)
# Draw bite marks B
print(' Draw bite marks ')
t.penup()
t.goto(60, 128)
t.pendown()
t.setheading(-35)
t.color('white')
t.begin_fill()
t.circle(-32, 140)
t.end_fill()
# Draw bite marks D
t.penup()
t.goto(60, -72)
t.pendown()
t.setheading(-35)
t.color('white')
t.begin_fill()
t.circle(-32, 140)
t.end_fill()
# Draw bite marks C
t.penup()
t.goto(-60, -72)
t.pendown()
t.setheading(-125)
t.color('white')
t.begin_fill()
t.circle(32, 360)
t.end_fill()
# Bid No
print(' Bid No ')
write_1(-190, 10, 25, 'A')
write_1(10, 10, 25, 'B')
write_1(-190, -190, 25, 'C')
write_1(10, -190, 25, 'D')
# Write the title
print(' Write the title ')
while 1:
write_1(-160, 230, 18, ' Which option in the figure below is apple logo?')
time.sleep(1)
t.undo()
t.undo()
t.undo()
t.undo()
t.undo()
t.undo()
thus , stay Python Realize true and false apples logo The drawing logic of has been roughly explained , Interested friends can do it again .
You may be interested in :
use Python Drawing Picasso
use Python Draw a cloud of words
use Python draw 520 Eternal heart
Python Face recognition — You are the only one in my eyes
Python Draw a nice picture of the starry sky ( Aesthetic background )
【Python】 Valentine's Day confession fireworks ( With sound and text )
use Python Medium py2neo Library operation neo4j, Building the association map
Python Romantic confession source collection ( love 、 The roses 、 Photo wall 、 Advertising under the stars )
边栏推荐
- 数据分析系列 之3σ规则/依据拉依达准则来剔除异常值
- Is it safe to buy funds online?
- 【编程题】【Scratch二级】2019.03 垃圾分类
- HB 5469 combustion test method for non-metallic materials in civil aircraft cabin
- 自动化测试:Robot FrameWork框架90%的人都想知道的实用技巧
- Pypharm uses, and the third-party library has errors due to version problems
- Anaconda+pycharm+pyqt5 configuration problem: pyuic5 cannot be found exe
- P1067 [noip2009 popularity group] polynomial output (difficult, pit)
- P1055 [noip2008 popularization group] ISBN number
- Jisuan Ke - t3104
猜你喜欢
神奇快速幂
An example analysis of MP4 file format parsing
Magic fast power
【编程题】【Scratch二级】2019.03 绘制方形螺旋
HB 5469民用飞机机舱内部非金属材料燃烧试验方法
Chisel tutorial - 02 Chisel environment configuration and implementation and testing of the first chisel module
如何衡量产品是否“刚需、高频、痛点”
关于组织2021-2022全国青少年电子信息智能创新大赛西南赛区(四川)复赛的通知
c—线性表
UIC564-2 附录4 –阻燃防火测试:火焰的扩散
随机推荐
Where are you going
快速回复二极管整流特性
[path planning] use the vertical distance limit method and Bessel to optimize the path of a star
DataGuard active / standby cleanup archive settings
Go learning notes (1) environment installation and hello world
How to put recyclerview in nestedscrollview- How to put RecyclerView inside NestedScrollView?
mysql8.0 ubuntu20.4
Enumeration, simulation, and sorting
limit 与offset的用法(转载)
archery安装测试
Chisel tutorial - 05 Sequential logic in chisel (including explicit multi clock, explicit synchronous reset and explicit asynchronous reset)
Basic learning of SQL Server -- creating databases and tables with code
Jisuan Ke - t3104
Introduction to programming hardware
ROS从入门到精通(九) 可视化仿真初体验之TurtleBot3
Enterprise application demand-oriented development of human resources department, employee attendance records and paid wages business process cases
Automated testing: robot framework is a practical skill that 90% of people want to know
Pigsty:开箱即用的数据库发行版
QT creator add custom new file / Project Template Wizard
如何衡量产品是否“刚需、高频、痛点”