心形图案函数

https://blog.csdn.net/robert_chen1988/article/details/53123462

在这里插入图片描述

当幂为小数的时候,底数不能为负

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define IOS ios::sync_with_stdio(0)
template <typename T>
inline T read(){T sum=0,fl=1;int ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')fl=-1;
for(;isdigit(ch);ch=getchar())sum=sum*10+ch-'0';
return sum*fl;}
template <typename T>
inline void write(T x) {static int sta[35];int top=0;
do{sta[top++]= x % 10, x /= 10;}while(x);
while (top) putchar(sta[--top] + 48);}
template<typename T>T gcd(T a, T b) {return b==0?a:gcd(b, a%b);}
template<typename T>T exgcd(T a,T b,T &g,T &x,T &y){if(!b){g = a,x = 1,y = 0;}
else {exgcd(b,a%b,g,y,x);y -= x*(a/b);}}
#ifndef ONLINE_JUDGE
#define debug(fmt, ...) {printf("debug ");printf(fmt,##__VA_ARGS__);puts("");}
#else
#define debug(fmt, ...)
#endif
typedef long long ll;
const ll mod = 1e9+7;
const double eps = 1e-6;

bool sgn(double p){
	return fabs(p) < eps;
}

int main() {
	#ifndef ONLINE_JUDGE
		//freopen("in.txt", "r", stdin);
		//freopen("out.txt","w",stdout);
	#endif
	char str[] = "xxxxxxxxxxxxx";
	for(double y = 4.0;y >= -3.5;y -= 0.1){
		for(double x = -3.0 ;x <= 3.0; x += 0.05){
			double p;
			if(sgn(y-2.40)&&sgn(x+0.5)){
				printf("   %s   ",str);
				x += 1.0;
				continue;
			}
			if(x==-0.0)p = y*y;
			else p = x*x + (y-pow(x*x,1.0/3))*(y-pow(x*x,1.0/3));
			char c = p <= 9.0 ? '*' : ' ';
			putchar(c);
		}puts("");
	}	
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是使用笛卡尔心形函数绘制心形图案的示例代码: ```cpp #include <QApplication> #include <QWidget> #include <QPainter> #include <QPen> #include <QBrush> #include <cmath> class Heart : public QWidget { public: Heart(QWidget *parent = 0): QWidget(parent) {} protected: void paintEvent(QPaintEvent *event) override { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); QPen pen(Qt::red, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); painter.setPen(pen); QBrush brush(Qt::red, Qt::SolidPattern); painter.setBrush(brush); painter.translate(width() / 2, height() / 2); QPainterPath path; const double pi = 3.14159265358979323846; const double a = 100; const double b = 100; const int n = 100; const double step = 2 * pi / n; for (double t = 0; t < 2 * pi; t += step) { double x = a * pow(sin(t), 3); double y = b * pow(cos(t), 3); path.lineTo(x, y); } painter.drawPath(path); } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); Heart heart; heart.resize(300, 300); heart.show(); return app.exec(); } ``` 这个示例使用笛卡尔心形函数绘制了一个红色的心形图案,你可以在 paintEvent 函数中看到绘制的具体过程。我们定义了心形函数中的两个参数 a 和 b,以及在一个周期内的点数 n,然后通过循环计算出每个点的坐标,最后使用 QPainterPath 类将这些点连接起来,得到了心形的形状。如果你想要绘制不同大小或颜色的心形,你可以修改对应的参数即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值