如何用c语言绘制一个空心的红色爱心
double dx=-2;
double dy=-2;
for(dx=-1.5;dx<1.5;dx+=0.001)
{
for(dy=-1.5;dy<1.5;dy+=0.001)
{
double temp=pow((pow(dx,2.0)+pow(dy,2.0)-1.0),3.0)-pow(dx,2.0)*pow(dy,3.0);
if(temp<=0&&temp>=-1)//空心心型坐标
{
//取dx,dy的值
}
}
}
心型的线粗细可以调节temp的值范围控制
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
extern "C" HWND WINAPI GetConsoleWindow();
void HideTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = FALSE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
void ShowTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = TRUE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
int main() {
HWND hwnd;
HDC hdc;
HFONT hfont;
wchar_t wc[2];
system("color F0");
system("cls");
HideTheCursor();
hwnd = GetConsoleWindow();
hdc = GetDC(hwnd);
hfont = CreateFont(200,0,0,0,0,0,0,0,GB2312_CHARSET ,0,0,0,0,"宋体");
SelectObject(hdc,hfont);
wc[0]=0xD83Eu;
wc[1]=0xDD0Du;
SetTextColor(hdc,RGB(255,0,0));
TextOutW(hdc,10,10,wc,2);
DeleteObject(hfont);
ReleaseDC(hwnd,hdc);
getch();
system("color 07");
system("cls");
ShowTheCursor();
return 0;
}