当前位置: 首页 > news >正文

zz手表网站南昌网站定制公司哪家好

zz手表网站,南昌网站定制公司哪家好,创建wordpress网站,电商网站策划前言 情人节到了#xff0c;写一份爱心代码给喜欢的人呀 公式 首先我们介绍下爱心的公式的参数方程#xff1a; x 16 s i n 3 ( t ) x 16sin^3(t) x16sin3(t) y 13 c o s ( t ) − 5 c o s ( 2 t ) − 2 c o s ( 3 t ) − c o s ( 4 t ) y 13cos(t) - 5cos(2t) - 2co…前言 情人节到了写一份爱心代码给喜欢的人呀 公式 首先我们介绍下爱心的公式的参数方程 x 16 s i n 3 ( t ) x 16sin^3(t) x16sin3(t) y 13 c o s ( t ) − 5 c o s ( 2 t ) − 2 c o s ( 3 t ) − c o s ( 4 t ) y 13cos(t) - 5cos(2t) - 2cos(3t) - cos(4t) y13cos(t)−5cos(2t)−2cos(3t)−cos(4t) 根据这个公式我们可以实现基本的代码 首先使用 n p . l i n s p a c e ( a , b , n u m ) np.linspace(a, b, num) np.linspace(a,b,num) 这个函数生成 a到b区间内的num个数这些数作为参数t然后生成对应xy的值 t np.linspace(0, 2 * np.pi, 100) 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, colorred) plt.title(Heart ) plt.axis(equal) # 保持坐标轴相等 plt.show()最终效果 完整代码 import matplotlib.pyplot as plt import numpy as np# 生成爱心形状的数据点 t np.linspace(0, 2 * np.pi, 100) 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, colorred) plt.title(Heart ) plt.axis(equal) # 保持坐标轴相等 plt.show()进阶 我们使用pygame创建一个界面在界面上随机生成不同颜色的爱心 初始化pygame: # 初始化 Pygame pygame.init()# 设置窗口大小 width, height 800, 600 screen pygame.display.set_mode((width, height)) pygame.display.set_caption(Random Hearts)编写绘制爱心的函数根据形参x,y确定位置color确定颜色 def draw_heart(x, y, color):# 生成爱心形状的直角坐标数据点t np.linspace(0, 2 * np.pi, 1000)heart_x x 16 * np.sin(t)**3heart_y y - (13 * np.cos(t) - 5 * np.cos(2*t) - 2 * np.cos(3*t) - np.cos(4*t))# 绘制爱心形状pygame.draw.lines(screen, color, False, list(zip(heart_x, heart_y)), 2)在主循环中一直生成随机的位置和颜色绘制pygame界面然后刷新显示 # 主循环 running True while running:for event in pygame.event.get():if event.type pygame.QUIT:running False# 随机生成爱心的位置和颜色heart_x random.randint(0, width)heart_y random.randint(0, height)heart_color (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))# 在随机位置绘制不清空的爱心draw_heart(heart_x, heart_y, heart_color)# 刷新屏幕pygame.display.flip()# 控制帧率pygame.time.Clock().tick(1)效果 完整代码 import pygame import sys import random import numpy as np# 初始化 Pygame pygame.init()# 设置窗口大小 width, height 800, 600 screen pygame.display.set_mode((width, height)) pygame.display.set_caption(Random Hearts)def draw_heart(x, y, color):# 生成爱心形状的直角坐标数据点t np.linspace(0, 2 * np.pi, 1000)heart_x x 16 * np.sin(t)**3heart_y y - (13 * np.cos(t) - 5 * np.cos(2*t) - 2 * np.cos(3*t) - np.cos(4*t))# 绘制爱心形状pygame.draw.lines(screen, color, False, list(zip(heart_x, heart_y)), 2)# 主循环 running True while running:for event in pygame.event.get():if event.type pygame.QUIT:running False# 随机生成爱心的位置和颜色heart_x random.randint(0, width)heart_y random.randint(0, height)heart_color (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))# 在随机位置绘制不清空的爱心draw_heart(heart_x, heart_y, heart_color)# 刷新屏幕pygame.display.flip()# 控制帧率pygame.time.Clock().tick(1)# 退出程序 pygame.quit() sys.exit()
http://www.tj-hxxt.cn/news/220382.html

相关文章:

  • 响应式网站需要的技术做网站对外贸有什么用
  • 与狗做网站企业网站托管常见问题
  • 广州网站设计开发公司网站主页面设计
  • 网站建设与制作培训通知cent安装wordpress
  • 如何帮公司做网站南京谁做免费网站
  • 中国镇江网站国外能下载模板的网站
  • 博兴网站建设微信公众号怎样发布wordpress
  • 省级别网站建设方案qq推广群
  • 江宁网站建设要多少钱上海工商网上公示系统
  • 怎样才能做公司的网站国外网站视频播放器
  • 85度c蛋糕房网站系统建设去掉wordpress 上一篇
  • 做个外贸网站多少钱app开发直播功能
  • 简单的网站设计开发wordpress怎么破解主题
  • 网站备案管局电话网站自助建站开发制作
  • 泛华建设集团网站局域网wordpress建站
  • 专业微网站建设网站策划书市场分析2000字
  • 鞍山市建设工程安全生产监督管理站网站南宁网站建设方案详细
  • 廊坊网站制作公司排名网络直播公司
  • 珠海专业网站建设公司哪家好宜春建设网站
  • 响应式网站建设模板下载企业网站免费推广的方法.
  • 做网站后台应该谁来做学校网站登录入口
  • 亿万网站网站设计公司皆选奇点网络
  • 八喜网站建设麻城建设局网站停办
  • 中山顺德网站建设视频教程网站模板
  • 手机自适应网站建设维护100个简单的科技小制作视频
  • 网站你懂我意思正能量晚上在线观看不用下载免费魅族外卖app开发需要多少钱
  • 无锡建设厅的官方网站合肥黄页
  • 电子商务网站建设的概要设计怎么做有趣的微视频网站
  • 公司要建设网站wordpress别名
  • 网站编辑注意问题金坛市住房和城乡建设局网站