Ask how to use python/pythonturtle to draw a "heart?

Source: Internet
Author: User
Python is just getting started. I think pythonturtle is really cute ~ I tried to draw a "heart", but I thought the method was too stupid & gt; & lt; I 'd like to ask my friends, is there any other way to draw a "heart" in python/pythonturtle? When I started python, I thought python turtle was really cute ~ I tried to draw a "heart", but I thought the method was too stupid> <I want to ask my friends, is there any other way to draw a "heart" in python/python turtle?
Reply content:

from turtle import *def curvemove():    for i in range(200):        right(1)        forward(1)color('red','pink')        begin_fill()left(140)forward(111.65)curvemove()left(120)curvemove()forward(111.65)end_fill()done()
From turtle import * From turtle import *
Pensize (1)
Color ('black', 'red ')
Speed (2)
Up ()
Goto (-12,100)
Down ()
Begin_fill ()
Left (90)
Circle (1, 120,180)
Circle (360, 70.529)
Left (0, 38.942)
Circle (360, 70.529)
Circle (1, 120,180)
End_fill ()
Up ()
Goto (-250,-150)
Down ()

from pylab import*t=linspace(0,2*pi,100)x=sin(2*t) + 2*sin(t)y=-cos(2*t)-2*cos(t)fill(x,y,'r')show()
The heart is not painted, but there is a rose I forgot to post the code before, and now I want to add it. I forgot to post the code before, and now I want to add it.
For I in range (1 ):
Def paint (ang, r, ang2): # drawing function
Turtle. penup ()
Turtle. setheading (ang)
Turtle. pendown ()
Turtle. circle (r, ang2)


Import turtle
Turtle. speed (9)
Turtle. color ("white") # Set
Turtle. pensize (7)
Turtle. penup ()
Turtle. goto (50,-50)
Turtle. pendown ()
Turtle. dot (200, "pink") # Draw background
Turtle. penup ()
Turtle. goto (50, 86.6)
Ang =-1, 150
R = 300.
Ang2 = 46
For j in range (21): # Loop

Paint (ang, r, ang2) # draw an arc
Ang2-= 25
Paint (ang + ang2 + 25, r,-ang2) # Roll Back
Ang2 + = 25
Ang + = 66
R = r * 0.9


The idea is: draw an arc, roll back about 1/3, turn, reduce the radius, draw an arc... keep repeating...

Video Portal Python Rose _ life

Remind me of the code-based student. I read your documents. It seems that you and I have selected the same elective course from the same school. But I have handed in this assignment, so you can ask me if you don't understand it.
The instructor will beat you up.
(Too many □') Too many characters. No one can trust me for 35 reasons. I will give you some ideas ~ However, I may not be able to help you in the last exam weeks...
-------------- 15.12.31 -----------------

import sysimport math def frange(start, end, step=1.0):if step > 0:while start < end:yield start start += stepelif step < 0:while start > end:yield start start += stepelse:raise ValueError('range() step must not be zero')def f(x, y, z):a = x*x + 9.0/4*y*y + z*z - 1 return a*a*a - x*x*z*z*z - 9.0/80*y*y*z*z*z def h(x, z):for y in frange(1.0, 0.0, -0.001):if f(x, y, z) <= 0:return y return 0.0if __name__ == '__main__':for z in frange(1.5, -1.5, -0.1):for x in frange(-1.5, 1.5, 0.05):v = f(x, 0, z)if v <= 0:y0 = h(x, z)ny = 0.01nx = h(x + ny, z) - y0                                 nz = h(x, z + ny) - y0 nd = 1.0/math.sqrt(nx*nx+ny*ny+nz*nz)d = (nx + ny - nz)*nd*0.5 + 0.5sys.stdout.write('.:-=+*#%@'[int(d*5)])else:sys.stdout.write(' ')sys.stdout.write('\n')
Use python matplotlib to draw a Cartesian heart-shaped line
Import numpy as np Import numpy as np
Import pylab as plt
From matplotlib import colors

A = [[] for I in range (1000)]

I = 0
While I <1000:
J = 0
While j <1000:
X =-1.8 + 0.003 * I
Y =-1.4 + 0.0028 * j
Z = y ** 2 + (-x-(y ** 2) ** 0.33333) ** 2
If z <= 1:
A [I]. append (0.9)
Else:
A [I]. append (0.0)
J = j + 1
I = I + 1

Cmap = colors. ListedColormap (['white', 'pink'])

Im = plt. imshow (a, cmap = cmap, interpolation = "bicubic ")
Plt. show ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.