我是靠谱客的博主 整齐魔镜,最近开发中收集的这篇文章主要介绍python的turtle画曲线_用c++的opencv实现以前的python的turtle曲线绘制,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#include #include#include

#define _USE_MATH_DEFINES#include

using namespacecv;

cv::Mat s_Mat;int s_width = 600;int s_height = 400;int s_world_origin_x = 0;int s_world_origin_y = 0;int s_colorR = 0;int s_colorG = 0;int s_colorB = 0;int s_penSize = 1;

cv::Point localPointToCVPoint(int x, inty)

{return cv::Point(s_world_origin_x + x, s_height - 1 - (s_world_origin_y +y));

}void setUp(int width, intheight)

{

s_Mat= cv::Mat(height, width, CV_8UC3, cv::Scalar(255, 255, 255));

s_width=width;

s_height=height;

}void setWorldOrigin(int x, inty)

{

s_world_origin_x=x;

s_world_origin_y=y;

}void setPenSize(intsize)

{

s_penSize=size;

}void setColor(int colorR, int colorG, intcolorB)

{

s_colorR=colorR;

s_colorG=colorG;

s_colorB=colorB;

}void drawLine(int x0, int y0, int x1, inty1)

{

cv::line(s_Mat, localPointToCVPoint(x0,y0), localPointToCVPoint(x1, y1),

cv::Scalar(s_colorB, s_colorG, s_colorR),

s_penSize);

}void drawText(const cv::String& textStr, int x, inty)

{

cv::putText(s_Mat, textStr, localPointToCVPoint(x, y),

cv::FONT_HERSHEY_SIMPLEX,0.5,

cv::Scalar(s_colorB, s_colorG, s_colorR), s_penSize);

}void drawXAxis(float x0, float y0, float axTailLength, float arrowWidth, floatarrowHeight)

{

drawLine(x0, y0, x0+ axTailLength +arrowHeight, y0);int halfw = arrowWidth * 0.5;

drawLine(x0+ axTailLength, y0 - halfw, x0 + axTailLength, y0 +halfw);

drawLine(x0+ axTailLength, y0 - halfw, x0 + axTailLength +arrowHeight, y0);

drawLine(x0+ axTailLength, y0 + halfw, x0 + axTailLength +arrowHeight, y0);

drawText("X", x0 + axTailLength +arrowHeight, y0);

}void drawYAxis(float x0, float y0, float axTailLength, float arrowWidth, floatarrowHeight)

{

drawLine(x0, y0, x0, y0+ axTailLength +arrowHeight);float halfw = arrowWidth*0.5;

drawLine(x0- halfw, y0 + axTailLength, x0 + halfw, y0 +axTailLength);

drawLine(x0- halfw, y0 + axTailLength, x0, y0 + axTailLength +arrowHeight);

drawLine(x0+ halfw, y0 + axTailLength, x0, y0 + axTailLength +arrowHeight);

drawText("Y", x0, y0 + axTailLength +arrowHeight);

}intmain()

{

setUp(500, 400);

setWorldOrigin(100, 150);

drawXAxis(-20, 0, 350, 10, 10);

drawYAxis(0, -20, 200, 10, 10);int n = 100;double dsi = (2.0 * M_PI) / double(n);

std::vectorptsX;

std::vectorptsY;for (int i = 0; i <= n; i++)

{double si = dsi * double(i);

ptsX.push_back(int(si*40.0));double sinsi =sin(si);

ptsY.push_back(int(sinsi*100.0));

}

setColor(0, 180, 0);

setPenSize(2);for (int i = 1; i <= n; i++)

{

drawLine(ptsX[i- 1], ptsY[i - 1], ptsX[i], ptsY[i]);

}

cv::imshow("turle similar", s_Mat);

cv::waitKey();return 0;

}

最后

以上就是整齐魔镜为你收集整理的python的turtle画曲线_用c++的opencv实现以前的python的turtle曲线绘制的全部内容,希望文章能够帮你解决python的turtle画曲线_用c++的opencv实现以前的python的turtle曲线绘制所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部