心形图案



#include <GL/glaux.h>
int main(int argc, char** argv){
    
    auxInitDisplayMode (AUX_SINGLE | AUX_RGBA);
    auxInitPosition (0, 0, 500, 500);
    auxInitWindow(argv[0]);
    
    glClearColor(0.0,0.0,0.0,0.5);//magenta
    // glClearDepth(0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    // specify the point size in pixel.
    // non-antialiasing defaultly.
    glPointSize(2.0);
    
    //print a heart on the screen
    //the heart formula is x^2 + ((y - pow(x^2),1/3))^2 = 1
    double x = -1.0;
    double y1 = 0.0;
    double y2 = 0.0;
    
    // scale the canvas
    glScalef(0.5,0.5,0.5);
    // red color
    glColor3f(1.0,0.0,0.0);
    
    //start paint.
    glBegin(GL_POINTS);
    for (x = (double)-1;x<(double)1;x=x+(double)0.01) {
        
        y1 = pow(x*x,(double)1/(double)3) + pow(1-x*x,(double)1/(double)2);
        y2 = pow(x*x,(double)1/(double)3) - pow(1-x*x,(double)1/(double)2);
        
        glVertex2d(x,y1);
        glVertex2d(x,y2);   
       
    }
    
    glEnd();
    
    //must add this to flush the buffer, so we can see the new picture.
    glFlush();
    Sleep(10000);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值