News from this site

 Rental advertising space, please contact the webmaster if you need cooperation


+focus
focused

classification  

no classification

tag  

no tag

date  

no datas

Programmer's 520 Fancy Drawing Love Code Encyclopedia

posted on 2023-06-06 12:40     read(244)     comment(0)     like(26)     collect(5)


Disclaimer : The code is ancestral code, I don't know who is the original one, please modify it. It is mainly for couples, although I am a single dog.

1. Fancy romantic love (1)

skip love
Matlab code:

clear; clc; close all; 
% NOTICE: Your MATLAB version should be at least R2019a !

% --------------------------- functions -------------------------------
f = @(x, y, z)(x.^2 + 2.25*y.^2 + z.^2 - 1).^3 -  ...
    x.^2.* z.^3 - 0.1125*y.^2.*z.^3;
g = @(x, y, z)(sqrt(x.^2+y.^2)-2.5).^2 + z.^2 - 0.4^2;

% -------------------------- generate data ----------------------------
t = linspace(-5, 5);

[x1, y1, z1] = meshgrid(t);
[x2, y2, z2] = meshgrid(t);

val1 = f(x1, y1, z1);
val2 = g(x2, y2, z2);

[p1, v1] = isosurface(x1, y1, z1, val1, 0);
[p2, v2] = isosurface(x2, y2, z2, val2, 0);

% --------------------------- basic plot ------------------------------
figure()
subplot(1, 1, 1)

h = patch('faces',p1,'vertices',v1,'facevertexcdata',jet(size(v1,1)),...
    'facecolor','w','edgecolor','flat'); hold on;
patch('faces',p2,'vertices',v2,'facevertexcdata',jet(size(v2,1)),...
    'facecolor','w','edgecolor','flat');
grid on; axis equal; axis([-3,3,-3,3,-1.5,1.5]); view(3)
title(["$(x^2+\frac{9}{4}y^2+z^2-1)^3-x^2z^3-\frac{9}{80}y^2z^3=0$",...
    "$(\sqrt{x^2+y^2}-R)^2 +z^2 = r^2$"],'Interpreter','latex','position',[3.3,4])
warning('off');
% 请在此处进行您的演讲!% 请在此处进行您的演讲!
T = suptitle("$I\ Love\ U\ !$"); 
% 请在此处进行您的演讲!% 请在此处进行您的演讲!
set(T,'Interpreter','latex','FontSize',24)

% -------------------------- generate gif -----------------------------
pic_num = 1;
for i = 1:20
    v1 = 0.98 * v1;
    set(h, 'vertices', v1); drawnow;
    F = getframe(gcf);
    I = frame2im(F);
    [I,map]=rgb2ind(I,256);
    if pic_num == 1
        imwrite(I,map,'BeatingHeart.gif','gif','Loopcount',inf,'DelayTime',0.05);
    else
        imwrite(I,map,'BeatingHeart.gif','gif','WriteMode','append','DelayTime',0.05);
    end
    pic_num = pic_num + 1;
end
for i = 1:20
    v1 = v1 / 0.98;
    set(h, 'vertices', v1); drawnow;
    F = getframe(gcf);
    I = frame2im(F);
    [I,map] = rgb2ind(I,256);
    imwrite(I,map,'BeatingHeart.gif','gif','WriteMode','append','DelayTime',0.05);
    pic_num = pic_num + 1;
end

% ----------------------------- dynamic -------------------------------
while true
    for i = 1:20
        v1 = 0.98 * v1;
        set(h, 'vertices', v1); drawnow;
    end
    for i = 1:20
        v1 = v1 / 0.98;
        set(h, 'vertices', v1); drawnow;
    end
end
% ------------------------------- end ---------------------------

2. Fancy romantic love (2)

insert image description here
The matlab code is as follows:

%爱心1
clear all
clc
f=@(x,y,z)(x.^2+ (9./4).*y.^2 + z.^2 - 1).^3 - x.^2.*z.^3 - (9./80).*y.^2.*z.^3;
[x,y,z]=meshgrid(linspace(-3,3));
val=f(x,y,z);
[p,v]=isosurface(x,y,z,val,0);
patch('faces',p,'vertices',v,'facevertexcdata',jet(size(v,1)),'facecolor','w','edgecolor','flat');
view(3);grid on;axis equal;

3. Fancy romantic love (3)

insert image description here
python code:

# 1-1导入turtle模块进行设计
import turtle
import time


# 1-2画心形圆弧
def hart_arc():
    for i in range(200):
        turtle.right(1)
        turtle.forward(2)


def move_pen_position(x, y):
    turtle.hideturtle()  # 隐藏画笔(先)
    turtle.up()  # 提笔
    turtle.goto(x, y)  # 移动画笔到指定起始坐标(窗口中心为0,0
    turtle.down()  # 下笔
    turtle.showturtle()  # 显示画笔


love = input("请输入表白话语:")
signature = input("请签署你的名字:")
date = input("请写上日期:")

if love == '':
    love = 'I Love You'

# 1-3初始化
turtle.setup(width=800, height=500)  # 窗口(画布)大小
turtle.color('red', 'pink')  # 画笔颜色
turtle.pensize(3)  # 画笔粗细
turtle.speed(1)  # 描绘速度
# 初始化画笔起始坐标
move_pen_position(x=0, y=-180)  # 移动画笔位置
turtle.left(140)  # 向左旋转140

turtle.begin_fill()  # 标记背景填充位置

# 1-4画图和展示
turtle.forward(224)  # 向前移动画笔,长度为224
# 画爱心圆弧
hart_arc()  # 左侧圆弧
turtle.left(120)  # 调整画笔角度
hart_arc()  # 右侧圆弧
# 画心形直线( 右下方 )
turtle.forward(224)

turtle.end_fill()  # 标记背景填充结束位置

move_pen_position(x=70, y=160)  # 移动画笔位置
turtle.left(185)  # 向左旋转180
turtle.circle(-110, 185)  # 右侧圆弧
# 画心形直线( 右下方 )
# turtle.left(20)  # 向左旋转180
turtle.forward(50)
move_pen_position(x=-180, y=-180)  # 移动画笔位置
turtle.left(180)  # 向左旋转140

# 画心形直线( 左下方 )
turtle.forward(600)  # 向前移动画笔,长度为224

# 在心形中写上表白话语
move_pen_position(0, 50)  # 表白语位置
turtle.hideturtle()  # 隐藏画笔
turtle.color('#CD5C5C', 'pink')  # 字体颜色
# font:设定字体、尺寸(电脑下存在的字体都可设置)  align:中心对齐
turtle.write(love, font=('Arial', 20, 'bold'), align="center")

# 签写署名和日期
if (signature != '') & (date != ''):
    turtle.color('red', 'pink')
    time.sleep(2)
    move_pen_position(220, -180)
    turtle.hideturtle()  # 隐藏画笔
    turtle.write(signature, font=('Arial', 20), align="center")
    move_pen_position(220, -220)
    turtle.hideturtle()  # 隐藏画笔
    turtle.write(date, font=('Arial', 20), align="center")

# 1-5点击窗口关闭程序
window = turtle.Screen()
window.exitonclick()

4. Fancy Romance (4)

insert image description here

python code:

# coding=gbk
"""
作者:川川
@时间  : 2022/5/20 2:50
"""
import turtle
import random
def love(x,y):#在(x,y)处画爱心lalala
    lv=turtle.Turtle()
    lv.hideturtle()
    lv.up()
    lv.goto(x,y)#定位到(x,y)
    def curvemove():#画圆弧
        for i in range(20):
            lv.right(10)
            lv.forward(2)
    lv.color('red','pink')
    lv.speed(10000000)
    lv.pensize(1)
    #开始画爱心lalala
    lv.down()
    lv.begin_fill()
    lv.left(140)
    lv.forward(22)
    curvemove()
    lv.left(120)
    curvemove()
    lv.forward(22)
    lv.write("思思",font=("Arial",12,"normal"),align="center")
    lv.left(140)#画完复位
    lv.end_fill()

def tree(branchLen,t):
    if branchLen > 5:#剩余树枝太少要结束递归
        if branchLen<20:#如果树枝剩余长度较短则变绿
            t.color("green")
            t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5))
            t.down()
            t.forward(branchLen)
            love(t.xcor(),t.ycor())#传输现在turtle的坐标
            t.up()
            t.backward(branchLen)
            t.color("brown")
            return
        t.pensize(random.uniform((branchLen+5)/4-2,(branchLen+6)/4+5))
        t.down()
        t.forward(branchLen)
        # 以下递归
        ang=random.uniform(15,45)
        t.right(ang)
        tree(branchLen-random.uniform(12,16),t)#随机决定减小长度
        t.left(2*ang)
        tree(branchLen-random.uniform(12,16),t)#随机决定减小长度
        t.right(ang)
        t.up()
        t.backward(branchLen)

myWin = turtle.Screen()
t = turtle.Turtle()
t.hideturtle()
t.speed(1000)
t.left(90)
t.up()
t.backward(200)
t.down()
t.color("brown")
t.pensize(32)
t.forward(60)
tree(100,t)
myWin.exitonclick()

5. Fancy Romance (5)

Demo:

Front-end romantic confession

The website can be accessed:
it has been deployed to the website, and it can be accessed: https://yanghanwen.xyz/ai/
This website will not change, to the people who once loved it most. Maybe that person will never see this site of mine.

Source code:
There are too many front-end source code files, Baidu network disk download:

链接:https://pan.baidu.com/s/10ubZKHiyEGdW3qYG_UNS6Q?pwd=zgxk 
提取码:zgxk

6. Fancy Romance (6)

Demo:

Front-end confession source code

Website:
Accessible website (recommended to use a computer): https://yanghanwen.xyz/ai1/
This website will not change, and it is dedicated to the people who once loved it the most. Maybe that person will never see this site of mine.

Source code file :

链接:https://pan.baidu.com/s/1XcMeF5f3AD7sEeHaWpYEOQ?pwd=oc79 
提取码:oc79

Seven, simple love (1)

insert image description here
python code:

import matplotlib.pyplot as plt
import numpy as np
from decimal import Decimal
from decimal import getcontext
import time


def heartfunc(x, y):
    return (x ** 2 + y ** 2 - 1) ** 3 - x ** 2 * y ** 3 <= 0


def cal_pi(precision):
    getcontext().prec = precision
    return sum(1 / Decimal(16) ** k *
               (Decimal(4) / (8 * k + 1) -
                Decimal(2) / (8 * k + 4) -
                Decimal(1) / (8 * k + 5) -
                Decimal(1) / (8 * k + 6)) for k in range(precision))


def printer(text, delay=0.1314):

    for ch in text:
        print(ch, end='', flush=True)
        time.sleep(delay)


if __name__ == '__main__':
    n = 1314
    x = np.linspace(-2, 2, n)
    y = np.linspace(-2, 2, n)
    X, Y = np.meshgrid(x, y)
    plt.contourf(X, Y, heartfunc(X, Y), cmap=plt.cm.autumn)
# Colour Query https://matplattlib.org/examples/color/collormaps_reference.html
    plt.title("5201314")
    plt.show()

    loveInPi = str(cal_pi(1314))
    heart = ['5', '2', '0', '1', '3', '1', '4']
    iloveyou = "5201314"
    love = ""
    i, j = 0, 0
    while love != iloveyou:
        if loveInPi[i] == heart[j]:
            love += loveInPi[i]
            j += 1
        i += 1

8. Simple love (2)

insert image description here
python code:

# coding=gbk
"""
作者:川川
@时间  : 2022/5/20 2:46
"""
# -*- coding:utf-8 -*-
import turtle
import time


# 画爱心的顶部
def LittleHeart():
    for i in range(200):
        turtle.right(1)
        turtle.forward(2)


# 输入表白的语句,默认I Love you
love = input('请输入表白语句,默认为输入为"I Love you": ')
# 输入署名或者赠谁,没有不执行
me = input('请输入您心上人的姓名或者昵称: ')
if love == '':
    love = 'I Love you'
# 窗口大小
turtle.setup(width=800, height=500)
# 颜色
turtle.color('red', 'pink')
# 笔粗细
turtle.pensize(5)
# 速度
turtle.speed(1)
# 提笔
turtle.up()
# 隐藏笔
turtle.hideturtle()
# 去到的坐标,窗口中心为0,0
turtle.goto(0, -180)
turtle.showturtle()
# 画上线
turtle.down()
turtle.speed(1)
turtle.begin_fill()
turtle.left(140)
turtle.forward(224)
# 调用画爱心左边的顶部
LittleHeart()
# 调用画爱右边的顶部
turtle.left(120)
LittleHeart()
# 画下线
turtle.forward(224)
turtle.end_fill()
turtle.pensize(5)
turtle.up()
turtle.hideturtle()
# 在心中写字 一次
turtle.goto(0, 0)
turtle.showturtle()
turtle.color('#CD5C5C', 'pink')
# 在心中写字 font可以设置字体自己电脑有的都可以设 align开始写字的位置
turtle.write(love, font=('gungsuh', 30,), align="center")
turtle.up()
turtle.hideturtle()
time.sleep(2)
# 在心中写字 二次
turtle.goto(0, 0)
turtle.showturtle()
turtle.color('red', 'pink')
turtle.write(love, font=('gungsuh', 30,), align="center")
turtle.up()
turtle.hideturtle()
# 写署名
if me != '':
    turtle.color('black', 'pink')
    time.sleep(2)
    turtle.goto(180, -180)
    turtle.showturtle()
    turtle.write(me, font=(20,), align="center", move=True)

# 点击窗口关闭
window = turtle.Screen()
window.exitonclick()

9. About the source code

The specific text can be adjusted by yourself, and it can be run. I wish all lovers in the world will get married. When I was busy with everything for the day, it was already past two o'clock in the morning, and I suddenly remembered the days like 520, and found that I was still living alone, but I still hope that everyone cherishes what is around you. It is not easy to have someone you love, so be good Love, don't wait until you lose it to know how to cherish it, all the elements of my confession series are her alone.



Category of website: technical article > Blog

Author:evilangel

link:http://www.pythonblackhole.com/blog/article/80911/a58297c1d103deaf931a/

source:python black hole net

Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.

26 0
collect article
collected

Comment content: (supports up to 255 characters)