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读写ini文件示例(python读写文件)
Mar 25 Python
Python生成验证码实例
Aug 21 Python
python基于隐马尔可夫模型实现中文拼音输入
Apr 01 Python
浅析AST抽象语法树及Python代码实现
Jun 06 Python
Python中easy_install 和 pip 的安装及使用
Jun 05 Python
Python字符编码与函数的基本使用方法
Sep 30 Python
Python Json序列化与反序列化的示例
Jan 31 Python
Python网络爬虫神器PyQuery的基本使用教程
Feb 03 Python
详解python多线程、锁、event事件机制的简单使用
Apr 27 Python
修改python plot折线图的坐标轴刻度方法
Dec 13 Python
Python逐行读取文件中内容的简单方法
Feb 26 Python
keras实现VGG16 CIFAR10数据集方式
Jul 07 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
PHP Array交叉表实现代码
2010/08/05 PHP
PHP安全配置详细说明
2011/09/26 PHP
PHP 登录记住密码实现思路
2013/05/07 PHP
php注册审核重点解析(数据访问)
2017/05/23 PHP
详解PHP队列的实现
2019/03/14 PHP
Prototype PeriodicalExecuter对象 学习
2009/07/19 Javascript
MooTools 1.2中的Drag.Move来实现拖放
2009/09/15 Javascript
Javascript实现仿WebQQ界面的“浮云”兼容 IE7以上版本及FF
2011/04/27 Javascript
jQuery操作 input type=checkbox的实现代码
2012/06/14 Javascript
jQuery链式操作如何实现以及为什么要用链式操作
2013/01/17 Javascript
javascript ie6兼容position:fixed实现思路
2013/04/01 Javascript
有关于JS构造函数的重载和工厂方法
2013/04/07 Javascript
js中点击空白区域时文本框与隐藏层的显示与影藏问题
2013/08/26 Javascript
通过JS来动态的修改url,实现对url的增删查改
2014/09/01 Javascript
JavaScript判断IE版本型号
2015/07/27 Javascript
JavaScript知识点总结(四)之逻辑OR运算符详解
2016/05/31 Javascript
javaScript基础详解
2017/01/19 Javascript
200行代码实现blockchain 区块链实例详解
2018/03/14 Javascript
VUE v-model表单数据双向绑定完整示例
2019/01/21 Javascript
JS基于对象的链表实现与使用方法示例
2019/01/31 Javascript
layui异步加载table表中某一列数据的例子
2019/09/16 Javascript
json_decode 索引为数字时自动排序问题解决方法
2020/03/28 Javascript
[26:50]2018完美盛典DOTA2表演赛
2018/12/17 DOTA
Python实现list反转实例汇总
2014/11/11 Python
在Python下使用Txt2Html实现网页过滤代理的教程
2015/04/11 Python
windows及linux环境下永久修改pip镜像源的方法
2016/11/28 Python
Python读取MRI并显示为灰度图像实例代码
2018/01/03 Python
python实现txt文件格式转换为arff格式
2018/05/31 Python
python中的句柄操作的方法示例
2019/06/20 Python
python用类实现文章敏感词的过滤方法示例
2019/10/27 Python
Html5监听手机摇一摇事件的实现
2019/11/07 HTML / CSS
党员承诺书范文
2014/05/19 职场文书
2015教师个人工作总结范文
2015/03/31 职场文书
欠条范文
2015/07/03 职场文书
python实现会员信息管理系统(List)
2022/03/18 Python
阿里云k8s服务升级时502错误 springboot项目应用
2022/04/09 Servers