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中 ? : 三元表达式的使用介绍
Oct 09 Python
Python入门篇之数字
Oct 20 Python
Python使用django搭建web开发环境
Jun 09 Python
对Python3中的print函数以及与python2的对比分析
May 02 Python
Python3 实现串口两进程同时读写
Jun 12 Python
深入了解Django中间件及其方法
Jul 26 Python
python rsa实现数据加密和解密、签名加密和验签功能
Sep 18 Python
python 正则表达式贪婪模式与非贪婪模式原理、用法实例分析
Oct 14 Python
python基于property()函数定义属性
Jan 22 Python
Python requests上传文件实现步骤
Sep 15 Python
python实现图片,视频人脸识别(dlib版)
Nov 18 Python
Python Django ORM连表正反操作技巧
Jun 13 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
实现 win2003 下 mysql 数据库每天自动备份
2006/12/06 PHP
UTF-8正则表达式如何匹配汉字
2015/08/03 PHP
php导出生成word的方法
2015/12/25 PHP
PHP用mysql_insert_id()函数获得刚插入数据或当前发布文章的ID
2016/11/25 PHP
javascript 树控件 比较好用
2009/06/11 Javascript
JQuery插件Style定制化方法的分析与比较
2012/05/03 Javascript
javascript相等运算符与等同运算符详细介绍
2013/11/09 Javascript
javascript实现了照片拖拽点击置顶的照片墙代码
2015/04/03 Javascript
js实现简单锁屏功能实例
2015/05/27 Javascript
Jquery 垂直多级手风琴菜单附源码下载
2015/11/17 Javascript
jQuery+css实现非常漂亮的水平导航菜单效果
2016/07/27 Javascript
jquery datatable服务端分页
2016/08/31 Javascript
ES6中Math对象的部分扩展
2017/02/20 Javascript
jQuery中each方法的使用详解
2018/03/18 jQuery
详解vue微信网页授权最终解决方案
2019/06/16 Javascript
file-loader打包图片文件时路径错误输出为[object-module]的解决方法
2020/01/03 Javascript
[01:18:21]EG vs TNC Supermajor小组赛B组败者组第一轮 BO3 第一场 6.2
2018/06/03 DOTA
python+flask实现API的方法
2018/11/21 Python
在python2.7中用numpy.reshape 对图像进行切割的方法
2018/12/05 Python
pyhanlp安装介绍和简单应用
2019/02/22 Python
安装Pycharm2019以及配置anconda教程的方法步骤
2019/11/11 Python
详解python 条件语句和while循环的实例代码
2020/12/28 Python
小学班主任寄语大全
2014/04/04 职场文书
美食节策划方案
2014/05/26 职场文书
党员对照检查材料思想汇报
2014/09/16 职场文书
小学感恩节活动策划方案
2014/10/06 职场文书
元旦标语大全
2014/10/09 职场文书
2014年辅导员工作总结
2014/11/18 职场文书
财务部会计岗位职责
2015/02/03 职场文书
商务英语求职信范文
2015/03/19 职场文书
国家助学贷款承诺书
2015/04/30 职场文书
暗恋桃花源观后感
2015/06/12 职场文书
幼儿教师三分钟演讲稿
2019/06/21 职场文书
开学第一周日记(三篇范文)
2019/08/23 职场文书
MySQL 存储过程的优缺点分析
2021/05/20 MySQL
《传颂之物 虚伪的假面》BD发售宣传CM公开
2022/04/04 日漫