跳动的爱心
#include<iostream>
#include<cmath>
#include<Windows.h>
using namespace std;
//关键公式(x^2+y^2-1)^3-x^2*y^3=0,小于零的时候在心形内部,大于零的时候在外部
void big_heart(){
double x_1,y_1,m_1,n_1;
for(y_1=1.5;y_1>-1.5;y_1-=0.1){
for(x_1=-1.5;x_1<=1.5;x_1+=0.05){
m_1=x_1*x_1+y_1*y_1-1;
n_1=pow(m_1,3)-pow(x_1,2)*pow(y_1,3);
n_1<0? cout<<'x': cout<<' ';
}
Sleep(100);
cout<<endl;
}
}
void big_heart_2(){
double x_1,y_1,m_1,n_1;
for(y_1=1.5;y_1>-1.5;y_1-=0.1){
for(x_1=-1.5;x_1<=1.5;x_1+=0.05){
m_1=x_1*x_1+y_1*y_1-1;
n_1=pow(m_1,3)-pow(x_1,2)*pow(y_1,3);
n_1<0? cout<<'x': cout<<' ';
}
cout<<endl;
}
}
void small_heart(){
double x,y,m,n;
for(y=3.0;y>-3.0;y-=0.2){
for(x=-3.0;x<=3.0;x+=0.1){
m=x*x+y*y-1;
n=pow(m,3)-pow(x,2)*pow(y,3);
n<0? cout<<'x': cout<<' ';
}
cout<<endl;
}
}
HANDLE han = GetStdHandle(-11);
void hide(){
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible = 0;
cursor.dwSize = 1;
SetConsoleCursorInfo(han,&cursor);
}
int main(){
hide();
system("color C");
big_heart();
int a=1;
while(1){
system("cls");
if(a%2==0){
small_heart();
Sleep(400);
}else{
big_heart_2();
Sleep(100);
}
a++;
}
return 0;
}
表白
#include<stdio.h>
#include<math.h>
#include<windows.h>
#include<time.h>
#define U 0.1
#define V 0.053
void SetColor(unsigned short ForeColor,unsigned short BackGroundColor)
{
HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hCon,(ForeColor%16)|(BackGroundColor%16*16));
}
int main()
{
int i,s=0,t,a=10,b=11,c=12,d=13,e=14;
int z[] = {32,32,206,210,207,178,187,182,196,227,33,32,32};
float x,y;
srand(time(NULL));
for(y=1.3;y>=-1.1;y-=U)
{
for(x=-2;x<1.4;x+=V)
{
if((((x*x+y*y-1)*(x*x+y*y-1)*(x*x+y*y-1)-x*x*y*y*y)<=0))
{
if(y>=1.3-10*U||y<=1.3-11*U)
{
s++;
if(s%4==1){SetColor(a,0);printf("l");}
if(s%4==2){SetColor(e,0);printf("o");}
if(s%4==3){SetColor(c,0);printf("v");}
if(s%4==0){SetColor(d,0);printf("e");}
}
else
{
for(i = 0;i < 42;i++)
{
if(i<=14||i>=28)
{
s++;
if(s%4==1){SetColor(a,0);printf("l");}
if(s%4==2){SetColor(e,0);printf("o");}
if(s%4==3){SetColor(c,0);printf("v");}
if(s%4==0){SetColor(d,0);printf("e");}
}
else
{
SetColor(b,0);
printf("%c", z[i-15]);
Sleep(50);
}
}
break;
}
}
else
printf(" ");
Sleep(1);
}
printf("\n");
}
printf("按任意键继续!");
getchar();
while(1)
{
system("cls");
t=a;a=b;b=c;c=d;d=e;e=t;
for(y=1.3;y>=-1.1;y-=U)
{
for(x=-2;x<1.4;x+=V)
{
if((((x*x+y*y-1)*(x*x+y*y-1)*(x*x+y*y-1)-x*x*y*y*y)<=0))
{
if(y>=1.3-10*U||y<=1.3-11*U)
{
s++;
if(s%4==1){SetColor(a,0);printf("l");}
if(s%4==2){SetColor(b,0);printf("o");}
if(s%4==3){SetColor(c,0);printf("v");}
if(s%4==0){SetColor(d,0);printf("e");}
}
else
{
for(i = 0;i < 42;i++)
{
if(i<=14||i>=28)
{
s++;
if(s%4==1){SetColor(a,0);printf("l");}
if(s%4==2){SetColor(b,0);printf("o");}
if(s%4==3){SetColor(c,0);printf("v");}
if(s%4==0){SetColor(d,0);printf("e");}
}
else
{
SetColor(e,0);
printf("%c", z[i-15]);
}
}
break;
}
}
else
printf(" ");
}
printf("\n");
}
Sleep(1000);
system("cls");
}
}