Get the App
SLTechnology News&Howtos  ›  Development  › 

How to draw moon cakes with python

Shulou Source: shulou.com Published: 2022-06-03 17:24:57 10月01日 Update

This article mainly introduces how to use python to draw moon cakes, the article is very detailed, has a certain reference value, interested friends must read it!

1. Environmental installation. Turtle comes with it, so you don't have to install it separately.

2. Create a moon cake .py file.

Import turtle

3. Define the pen function, which is a paintbrush.

T = turtle.Pen ()

4. Circle commands to draw the shape of moon cakes.

For i in range (30): # using the for loop, you can repeat the above drawing multiple times. Until it is drawn into a garden. T.begin_fill () t.forward (200) # We moved the brush t to the distance of 200 pixels in the direction of the arrow t.circle (30180) # We drew a small arc of t.goto (0) # We returned the brush t to its original position (0) t.right (0) t.right (12)

5. Color the moon cakes.

Import turtlet = turtle.Pen () t.speed (0) # to control the speed of drawing turtle.colormode (255) # tells Python that we use RGB to specify the color t.color ((0meme 0p0)) # means that the color consists of red 0 green 0 blue 0 chocolate color pure black. For i in range (30): t.begin_fill () t.forward (200) t.circle (30180) t.goto (0L0) t.right (180) t.right (12) t.end_fill () # the graphics between begin_fill () and end_fill () will fill all the contents of the article "how to draw mooncakes with python" above the color we specify. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Mooncakes colors brushes content graphics articles original not used between value location pixels interests functions guys buddies that is chocolate arcs shapes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Microsoft Shulou Information Shulou Tech Info Shulou Technology