python画一个玫瑰和一个爱心


Posted in Python onAugust 18, 2020

节日用心准备的礼物,使用python画玫瑰和爱心,供大家参考,具体内容如下

#!/usr/bin/env python
#coding=utf-8
#女生节礼物
 
import rospy
from sensor_msgs.msg import LaserScan
import numpy
import copy
 
node_name = "Test_Maker"
 
class Test_Maker():
 def __init__(self):
  self.Define()
  rospy.Timer(rospy.Duration(0.5), self.Timer_CB1)
  rospy.Timer(rospy.Duration(0.5), self.Timer_CB2)
  rospy.Timer(rospy.Duration(0.5), self.Timer_CB3)
  rospy.Timer(rospy.Duration(0.5), self.Timer_CB4)
  rospy.spin()
 
 def Define(self):
  self.pub_scan1 = rospy.Publisher('test/test_scan1', LaserScan, queue_size=1)
  self.pub_scan2 = rospy.Publisher('test/test_scan2', LaserScan, queue_size=1)
  self.pub_scan3 = rospy.Publisher('test/test_scan3', LaserScan, queue_size=1)
  #慎用!!!!
  self.pub_scan4 = rospy.Publisher('test/test_scan4', LaserScan, queue_size=1)
 
 def Timer_CB1(self, e):
  data = LaserScan()
  data.header.frame_id = "base_link"
  data.angle_min = 0
  data.angle_max = numpy.pi*2
  data.angle_increment = numpy.pi*2 / 200
  data.range_max = numpy.Inf
  data.range_min = 0
  theta = 0
  for i in range(200):
   r = 8.* numpy.sin(5. * theta )
   data.ranges.append(copy.deepcopy(r))
   data.intensities.append(theta)
   r = 8.* numpy.sin(5. * -theta)
   data.ranges.append(copy.deepcopy(r))
   data.intensities.append(theta)
 
   theta += data.angle_increment
  data.header.stamp = rospy.Time.now()
  self.pub_scan1.publish(data)
 
 def Timer_CB2(self, e):
  data = LaserScan()
  data.header.frame_id = "base_link"
  data.angle_min = 0
  data.angle_max = numpy.pi*2
  data.angle_increment = numpy.pi*2 / 200
  data.range_max = numpy.Inf
  data.range_min = 0
  theta = 0
  for i in range(200):
   r = 8. * numpy.cos(5. * theta) + 1
   data.intensities.append(theta)
   data.ranges.append(copy.deepcopy(r))
   r = 8. * numpy.cos(5. * -theta) + 1
   data.intensities.append(theta)
   data.ranges.append(copy.deepcopy(r))
   theta += data.angle_increment
 
  data.header.stamp = rospy.Time.now()
  self.pub_scan2.publish(data)
 
 def Timer_CB3(self, e):
  data = LaserScan()
  data.header.frame_id = "base_link"
  data.angle_min = 0
  data.angle_max = numpy.pi*2
  data.angle_increment = numpy.pi*2 / 50
  data.range_max = numpy.Inf
  data.range_min = 0
  theta = 0
  for i in range(200):
   r = 2. * numpy.sin(5. * theta) + 1
   data.intensities.append(theta)
   data.ranges.append(copy.deepcopy(r))
   r = 2. * numpy.sin(5. * -theta) + 1
   data.intensities.append(theta)
   data.ranges.append(copy.deepcopy(r))
   theta += data.angle_increment
 
  data.header.stamp = rospy.Time.now()
  self.pub_scan3.publish(data)
 
 #慎用!!!!
 def Timer_CB4(self, e):
  data = LaserScan()
  data.header.frame_id = "base_link"
  data.angle_min = 0
  data.angle_max = numpy.pi*2
  data.angle_increment = data.angle_max / 200
  data.range_max = numpy.Inf
  data.range_min = 0
  theta = 0
  for i in range(200):
   r = 9. * numpy.arccos(numpy.sin(theta)) + 9
   data.ranges.append(r)
   theta += data.angle_increment
 
  data.header.stamp = rospy.Time.now()
  self.pub_scan4.publish(data)
 
if __name__ == '__main__':
 node_name = 'Test_Maker'
 rospy.init_node(node_name)
 try:
  Test_Maker()
 except rospy.ROSInterruptException:
  rospy.logerr('%s error'%node_name)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
简介Python中用于处理字符串的center()方法
May 18 Python
python中urllib.unquote乱码的原因与解决方法
Apr 24 Python
Python2和Python3中print的用法示例总结
Oct 25 Python
Python2与python3中 for 循环语句基础与实例分析
Nov 20 Python
使用Python快速制作可视化报表的方法
Feb 03 Python
PyQt5基本控件使用之消息弹出、用户输入、文件对话框的使用方法
Aug 06 Python
python3.6中@property装饰器的使用方法示例
Aug 17 Python
python多线程分块读取文件
Aug 29 Python
Python OpenCV图像指定区域裁剪的实现
Oct 30 Python
浅谈python中统计计数的几种方法和Counter详解
Nov 07 Python
python手机号前7位归属地爬虫代码实例
Mar 31 Python
python在package下继续嵌套一个package
Apr 14 Python
python爱心表白 每天都是浪漫七夕!
Aug 18 #Python
Python实现全排列的打印
Aug 18 #Python
python递归实现快速排序
Aug 18 #Python
pyqt5的QWebEngineView 使用模板的方法
Aug 18 #Python
python递归全排列实现方法
Aug 18 #Python
python使用PIL给图片添加文字生成海报示例
Aug 17 #Python
Python在for循环中更改list值的方法【推荐】
Aug 17 #Python
You might like
Discuz 模板语句分析及知识技巧
2009/08/21 PHP
详解WordPress中用于合成数组的wp_parse_args()函数
2015/12/18 PHP
解决微信授权回调页面域名只能设置一个的问题
2016/12/11 PHP
PHP微信模板消息操作示例
2017/06/29 PHP
css配合jquery美化 select
2013/11/29 Javascript
实例分析js和C#中使用正则表达式匹配a标签
2014/11/26 Javascript
js实现点击图片改变页面背景图的方法
2015/02/28 Javascript
jQuery 判断图片是否加载完成方法汇总
2015/08/10 Javascript
JS判断当前页面是否在微信浏览器打开的方法
2015/12/08 Javascript
基于slideout.js实现移动端侧边栏滑动特效
2016/11/28 Javascript
js实现刷新页面后回到记录时滚动条的位置【两种方案可选】
2016/12/12 Javascript
jQuery插件FusionCharts绘制2D双折线图效果示例【附demo源码】
2017/04/14 jQuery
微信小程序之购物车功能
2020/09/23 Javascript
vue.js 获取当前自定义属性值
2017/06/01 Javascript
nodejs使用express获取get和post传值及session验证的方法
2017/11/09 NodeJs
微信小程序获取位置展示地图并标注信息的实例代码
2019/09/01 Javascript
Python实现二分查找算法实例
2015/05/26 Python
python使用正则表达式匹配字符串开头并打印示例
2017/01/11 Python
python入门教程之识别验证码
2017/03/04 Python
python批量识别图片指定区域文字内容
2019/04/30 Python
python把ipynb文件转换成pdf文件过程详解
2019/07/09 Python
python模拟鼠标点击和键盘输入的操作
2019/08/04 Python
Sentry错误日志监控使用方法解析
2020/11/12 Python
使用Python快速打开一个百万行级别的超大Excel文件的方法
2021/03/02 Python
百联网上商城:i百联
2017/01/28 全球购物
Kate Spade澳大利亚官方网站:美国设计师手袋品牌
2019/09/10 全球购物
德国户外装备、登山运动和攀岩商店:tapir store
2020/02/12 全球购物
演讲比赛获奖感言
2014/02/02 职场文书
趣味活动策划方案
2014/02/08 职场文书
销售顾问岗位职责
2014/02/25 职场文书
体育课课后反思
2014/04/24 职场文书
团队队名口号大全
2014/06/06 职场文书
低碳环保演讲稿
2014/08/28 职场文书
培训通知
2015/04/17 职场文书
利用 SQL Server 过滤索引提高查询语句的性能分析
2021/07/15 SQL Server
Python字典的基础操作
2021/11/01 Python