Valentine's Day is coming, teach you how to use code to express!

You still have a big red bag of five yuan and twenty cents?

Have you ever thought about why someone else's boyfriend

Can I always dump you eight hundred blocks?
When the standard way of "expensive flowers + romantic candlelight dinner" has already fallen into the rut, as a programmer, shouldn't we have our own exclusive romance?

Do you use code to express your love, or base64 to encrypt your advertisement to her, or use her name as the domain name to write her own website?

"The best code I've ever written is the one you promised to be my girlfriend. "

You can't flirt all by one mouth

Gifts must be heartless and thoughtful!

To learn Python

Get it done. Move it!

Welfare time

(1) Static heart

  import matplotlib.pyplot as plt

    import numpy as np

    t=np.arange(0,2*np.pi,0.1)

    x=16*np.sin(t)**3

    y=13*np.cos(t)-5*np.cos(2*t)-2*np.cos(3*t)-np.cos(4*t)

    plt.plot(x,y,color="red")

    plt.show()

The operation result is:

(2) Dynamic heart

  import turtle

from turtle import *

def curvemove():

    for i in range(200):

        right(1)

        forward(1)

turtle.title("Invite people's Day")#Set title for image

turtle.pensize(width=5)#stroke width

color("red","pink")#Brush color and fill color

begin_fill()

left(140)#Rotate 140 degrees counterclockwise

turtle.speed(1)#Line speed

forward(111.65)#Forward travel 111.65

curvemove()#Call the curvemove function

left(120)

curvemove()

turtle.speed(1)

forward(111.65)

end_fill()

turtle.up()#Stop drawing

left(230)

forward(75)

turtle.write("I LOVE YOU ",align="Center",font=("Arial", 16, "normal"))

done()

The operation result is:

(3) One line code drawing heart

print('\n'.join([''.join([('AndyLove'[(x-y)%8]if((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<=0 else' ')for x in range(-30,30)])for y in range(15,-15,-1)]))

The operation result is:

(4) Rose

Valentine's day, the essential thing is roses, so use Python to draw a rose.
① Define canvas and brush

import turtle
def initialization():
    turtle.setup(width=0.9, height=0.9)
    turtle.speed(10)

② First, draw the pistil

   def flower():

        turtle.goto(0, 200)

        turtle.fillcolor("red")

        turtle.begin_fill()

        turtle.circle(10, 180)

        turtle.circle(25, 110)

        turtle.left(50)

        turtle.circle(60, 45)

        turtle.circle(20, 170)

        turtle.right(24)

        turtle.fd(30)

        turtle.left(10)

        turtle.circle(30, 110)

        turtle.fd(20)

        turtle.left(40)

        turtle.circle(90, 70)

        turtle.circle(30, 150)

        turtle.right(30)

        turtle.fd(15)

        turtle.circle(80, 90)

        turtle.left(15)

        turtle.fd(45)

        turtle.right(165)

        turtle.fd(20)

        turtle.left(155)

        turtle.circle(150, 80)

        turtle.left(50)

        turtle.circle(150, 90)

        turtle.end_fill()

③ Sketch the petals on the left

  def peta1():

        turtle.left(150)

        turtle.circle(-90, 70)

        turtle.left(20)

        turtle.circle(75, 105)

        turtle.setheading(60)

        turtle.circle(80, 98)

        turtle.circle(-90, 40)

④ Sketch the petals on the right

  def peta2():

        turtle.left(180)

        turtle.circle(90, 40)

        turtle.circle(-80, 98)

        turtle.setheading(-83)

⑤ Sketch the left leaf on the branch

   def leaf1():

        turtle.fd(30)

        turtle.left(90)

        turtle.fd(25)

        turtle.left(45)

        turtle.fillcolor("green")

        turtle.begin_fill()

        turtle.circle(-80, 90)

        turtle.right(90)

        turtle.circle(-80, 90)

        turtle.end_fill()

        turtle.right(135)

        turtle.fd(60)

        turtle.left(180)

        turtle.fd(85)

        turtle.left(90)

        turtle.fd(80)

⑥ Draw the right leaf on the branch

 def leaf2():

        turtle.right(90)

        turtle.right(45)

        turtle.fillcolor("green")

        turtle.begin_fill()

        turtle.circle(80, 90)

        turtle.left(90)

        turtle.circle(80, 90)

        turtle.end_fill()

        turtle.left(135)

        turtle.fd(60)

        turtle.left(180)

        turtle.fd(60)

        turtle.right(90)

        turtle.circle(200, 60)
 if __name__ == '__main__':

        initialization()

        flower()

        peta1()

        peta2()

        leaf1()

        leaf2()

The operation result is:

I have sorted out some interesting things and some materials about Java interview by myself. Interested friends can click to get: Welfare time

Write at the end:

Those who have been married and have a partner called a boyfriend or girlfriend should have a festival, a gift and a sense of ceremony. No boyfriend or girlfriend, single dogs are catching up with the time and expressing their love to the right people.

Last and last;

Happy Valentine's day to all of you.

Published 7 original articles, praised 0, visited 16
Private letter follow

Tags: Python Java

Posted on Thu, 13 Feb 2020 02:39:34 -0500 by Whear