C Language Print Heart shape

Source: Internet
Author: User

#include <stdio.h>

int main () {
for (float y = 1.5f; y > -1.5f; y-= 0.1f) {
for (float x = -1.5f; x < 1.5f; x + = 0.05f) {
float A = x * x + y * y-1;
Putchar (A * A * a-x * x * y * y * y <= 0.0f? ‘*‘ : ‘ ‘);
}
Putchar (' \ n ');
}
}

*********************************************************************************************

#include <stdio.h>

int main () {
for (float y = 1.5f; y > -1.5f; y-= 0.1f) {
for (float x = -1.5f; x < 1.5f; x + = 0.05f) {
float z = x * x + y * y-1;
float F = z * z * z-x * x * y * y * y;
Putchar (f <= 0.0f?) ".:-=+*#%@" [(int) (f * -8.0f)]: ');
}
Putchar (' \ n ');
}
}

*********************************************************************************************

#include <stdio.h>
#include <math.h>

Float F (float x, float y, float z) {
Float a = x * x + 9.0f/4.0f * y * y + z * z-1;
Return A * A * a-x * x * z * z * z-9.0f/80.0f * y * y * z * z * z;
}

Float h (float x, float z) {
for (float y = 1.0f; y >= 0.0f; y-= 0.001f)
if (f (x, Y, z) <= 0.0 f)
return y;
return 0.0f;
}

Int Main () {
for (float z = 1.5f; z > -1.5f; z-= 0.05f) {
for (float x = -1.5f; x < 1.5f; x + = 0.0 25f) {
Float v = f (x, 0.0f, z);
if (v <= 0.0f) {
Float y0 = h (x, z);
Float ny = 0.01f;
Float NX = h (x + NY, z)-y0;
Float NZ = h (x, z + NY)-y0;
Float nd = 1.0F/SQRTF (NX * NX + NY * NY + NZ * NZ);
Float D = (nx + ny-nz) * nd * 0.5f + 0.5f;
Putchar (".:-=+*#%@" [(int) (d * 5.0f)]);
}
Else
Putchar (');
}
Putchar (' \ n ');
}
}

*********************************************************************************************

#ifdef _msc_ver
#define _crt_secure_no_warnings
#endif
#include <stdio.h>
#include <math.h>

float f (float x, float y, float z) {
float A = x * x + 9.0f/4.0f * y * y + z * z-1;
Return a * A * a-x * x * z * z * z-9.0f/80.0f * y * y * z * z * z;
}

Float h (float x, float z) {
for (float y = 1.0f; y >= 0.0f; y-= 0.001f)
if (f (x, Y, z) <= 0.0f)
return y;
return 0.0f;
}

int main () {
file* fp = fopen ("heart.ppm", "w");
int SW = +, SH = 512;
fprintf (FP, "p3\n%d%d\n255\n", SW, SH);
for (int sy = 0; sy < sh; sy++) {
float z = 1.5f-sy * 3.0f/sh;
for (int sx = 0; sx < SW; sx++) {
float x = sx * 3.0F/SW-1.5F;
Float v = f (x, 0.0f, z);
int r = 0;
if (v <= 0.0f) {
float y0 = h (x, z);
float NY = 0.001f;
float NX = h (x + NY, z)-y0;
float NZ = h (x, z + NY)-y0;
float nd = 1.0F/SQRTF (NX * NX + NY * NY + NZ * NZ);
Float D = (nx + ny-nz)/SQRTF (3) * nd * 0.5f + 0.5f;
R = (int) (d * 255.0f);
}
fprintf (FP, "%d 0 0", R);
}
FPUTC (' \ n ', FP);
}
Fclose (FP);
}

*********************************************************************************************

#include <stdio.h>
#include <math.h>
#include <windows.h>
#include <tchar.h>

float f (float x, float y, float z) {
float A = x * x + 9.0f/4.0f * y * y + z * z-1;
Return a * A * a-x * x * z * z * z-9.0f/80.0f * y * y * z * z * z;
}

Float h (float x, float z) {
for (float y = 1.0f; y >= 0.0f; y-= 0.001f)
if (f (x, Y, z) <= 0.0f)
return y;
return 0.0f;
}

int main () {
HANDLE o = GetStdHandle (std_output_handle);
_tchar buffer[25][80] = {_t (')};
_tchar ramp[] = _t (".:-=+*#%@");

for (float t = 0.0f;; t + = 0.1f) {
int sy = 0;
float s = sinf (t);
float A = S * S * s * s * 0.2f;
for (float z = 1.3f; z > -1.2f; z-= 0.1f) {
_tchar* p = &buffer[sy++][0];
float TZ = Z * (1.2f-a);
for (float x = -1.5f; x < 1.5f; x + = 0.05f) {
FLOAT tx = x * (1.2f + a);
Float v = f (TX, 0.0f, TZ);
if (v <= 0.0f) {
float y0 = h (TX, TZ);
float NY = 0.01f;
float NX = h (TX + NY, TZ)-y0;
float NZ = h (TX, TZ + NY)-y0;
float nd = 1.0F/SQRTF (NX * NX + NY * NY + NZ * NZ);
Float D = (nx + ny-nz) * nd * 0.5f + 0.5f;
*p++ = ramp[(int) (d * 5.0f)];
}
Else
*p++ = ";
}
}

for (sy = 0; sy < sy++) {
COORD COORD = {0, sy};
SetConsoleCursorPosition (o, coord);
Writeconsole (o, Buffer[sy], +, NULL, 0);
}
Sleep (33);
}
}

C Language Print Heart shape

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.