-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeart3D.c
38 lines (38 loc) · 930 Bytes
/
Heart3D.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<stdio.h>
#include<windows.h>
#include<math.h>
float f(float x, float y, float z){
float a;
a=x*x+9.0f/4.0*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){
float y;
for(y=1.0f;y>=0.0f;y-=0.001f)
if(f(x,y,z)<=0.0f)
return y;
return 0.0f;
}
void heart3d(){
system("color f4");
float z,x,v,y0,ny,nx,nz,nd,d;
for(z=1.5f;z>-1.5f;z-=0.05f){
for(x=-1.5f;x<1.5f;x+=0.025f){
v=f(x,0.0f,z);
if(v<=0.0f){
y0=h(x,z);
ny=0.01f;
nx=h(x+ny,z)-y0;
nz=h(x,z+ny)-y0;
nd=1.0f/sqrtf(nx*nx+ny*ny+nz*nz);
d=(nx+ny-nz)*nd*0.5f+0.5f;
putchar(".:-=+*#%@"[(int)(d*5.0f)]);
}
else putchar(' ');
}
putchar('\n');
}
}
void main(){
heart3d();
}