1 /* XPaint-image */
2 
3 #include <Xpaint.h>
4 #include <Xpaint3d.h>
5 
6 /* Draw heart */
7 
heart(point p,double x,double y)8 void heart(point p, double x, double y)
9 {
10 double a, b, s, t;
11 
12    t = fabs(x);
13    if (t<M_PI/2) s = 1; else s = -1;
14 
15    a = sqrt(1-y*y);
16    b = 1 - 0.9 * s * pow( pow(sin(t) , 1-0.18*a*a*t) - 1 , 2);
17    p[0] = a * ( b * cos(x) + 1);
18    p[1] = 1.2 * a * b * sin(x);
19    p[2] = 0.8 * y - 0.3 ;
20 
21 }
22 
ImageCreate()23 Image * ImageCreate()
24 {
25    Image * image;
26    unsigned char * p;
27    int x, y, i, j;
28 
29    width = 640;
30    height = 480;
31 
32    x_1 = -2; x_2 = 2;
33    y_1= -1.5; y_2 = 1.5;
34    z_1 = -1.5; z_2 = 1.5;
35 
36    light_x = -0.3; light_y = -0.5; light_z = -1.1;
37 
38    create_3d_buffer();
39 
40    rotation_angles(90, 0, 0);
41    translation(0, -0.5, 0);
42 
43    surface(heart, -M_PI, M_PI, 300, -1, 1, 120);
44 
45    image = ImageNew(width, height);
46 
47    for (y = 0; y < height; y++) {
48        for (x = 0; x < width; x++) {
49            p = ImagePixel(image, x, y);
50            i = x+y*width;
51            if (luminosity[i]) {
52               p[0] = luminosity[i]>>8;
53               p[1] = p[0];
54               p[2] = p[0]/3;
55            } else {
56               p[0] = 255;
57               p[1] = 255;
58               p[2] = 255;
59            }
60        }
61    }
62 
63    free_3d_buffer();
64    return image;
65 }
66