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实现连接mongodb的方法
May 08 Python
Python运算符重载用法实例
May 28 Python
python 简单的绘图工具turtle使用详解
Jun 21 Python
python+matplotlib实现鼠标移动三角形高亮及索引显示
Jan 15 Python
Python多重继承的方法解析执行顺序实例分析
May 26 Python
Python实现删除排序数组中重复项的两种方法示例
Jan 31 Python
谈一谈基于python的面向对象编程基础
May 21 Python
django最快程序开发流程详解
Jul 19 Python
python批量修改ssh密码的实现
Aug 08 Python
python web框架中实现原生分页
Sep 08 Python
在Ubuntu中安装并配置Pycharm教程的实现方法
Jan 06 Python
Python+OpenCV实现在图像上绘制矩形
Mar 21 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的安全策略
2006/10/09 PHP
windwos下使用php连接oracle数据库的过程分享
2014/05/26 PHP
ThinkPHP框架设计及扩展详解
2014/11/25 PHP
PHP实现的Redis多库选择功能单例类
2017/07/27 PHP
JQuery获取样式中的background-color颜色值的问题
2013/08/20 Javascript
js window.open弹出新的网页窗口
2014/01/16 Javascript
IE下通过a实现location.href 获取referer的值
2014/09/04 Javascript
jquery调取json数据实现省市级联的方法
2015/01/29 Javascript
JavaScript正则表达式中的ignoreCase属性使用详解
2015/06/16 Javascript
JS仿京东移动端手指拨动切换轮播图效果
2020/04/10 Javascript
多种方式实现js图片预览
2016/12/12 Javascript
jQuery EasyUI tree增加搜索功能的实现方法
2017/04/27 jQuery
浅谈事件冒泡、事件委托、jQuery元素节点操作、滚轮事件与函数节流
2017/07/22 jQuery
vue打包后显示空白正确处理方法
2017/11/01 Javascript
用vue-cli开发vue时的代理设置方法
2018/09/20 Javascript
使用Vuex解决Vue中的身份验证问题
2018/09/28 Javascript
10行代码实现微信小程序滑动tab切换
2018/12/28 Javascript
vue elementUI table表格数据 滚动懒加载的实现方法
2019/04/04 Javascript
JavaScript鼠标悬停事件用法解析
2020/05/15 Javascript
vue实现在线学生录入系统
2020/05/30 Javascript
[01:22]DOTA2神秘商店携大量周边降临完美大师赛
2017/11/07 DOTA
python http接口自动化脚本详解
2018/01/02 Python
Python计算库numpy进行方差/标准方差/样本标准方差/协方差的计算
2018/12/28 Python
使用TensorFlow对图像进行随机旋转的实现示例
2020/01/20 Python
PyTorch中Tensor的数据统计示例
2020/02/17 Python
Python基于requests实现模拟上传文件
2020/04/21 Python
Python如何将函数值赋给变量
2020/04/28 Python
浅谈pytorch中torch.max和F.softmax函数的维度解释
2020/06/28 Python
python爬虫beautifulsoup库使用操作教程全解(python爬虫基础入门)
2021/02/19 Python
Blue Nile台湾:钻石珠宝商,订婚首饰、结婚戒指和精品首饰
2017/11/24 全球购物
麦德龙官方海外旗舰店:德国麦德龙超市
2017/12/23 全球购物
Java面试题:Java类的Main方法如果是Private将会怎么样
2016/08/18 面试题
涉外经济法专业毕业生推荐信
2013/11/24 职场文书
制衣厂各岗位职责
2013/12/02 职场文书
运动会稿件50字
2014/02/17 职场文书
2015年学校教务处工作总结
2015/05/11 职场文书