Exemple #1
0
// 主函数
int main( int argc, char* argv[] ) {
    int i, ms_x = -1024, ms_y = -1024, exitflag = 0;
    int fps = 60;
    double dtime;

    int mode = preinit( argc, argv ); // 记录初始化模式
    if ( mode < 0 ) return 0;

    randomize(); // 初始化随机种子
    initgraph( -1, -1 ); // 打开图形窗口,以全屏模式

    showmouse( mode );
    sc_width = getwidth();
    sc_heigh = getheight();

    // 初始化所有星星
    for ( i = 0; i < g_max; i++ ) {
        InitStar( i );
        star[i].x = randomf();
    }
    // 绘制星空,按任意键或移动鼠标退出
    setfont( 12, 6, "宋体" );
    setrendermode( RENDER_MANUAL );
    dtime = fclock();
    while ( kbmsg() ) getkey();

    for ( ; !exitflag && is_run() && kbmsg() == 0; delay_fps( fps ) ) { //每秒画120帧,kbhit(1)是获取键盘任意键的消息,详见pdf
        // 如果有鼠标消息
        while ( mousemsg() ) {
            mouse_msg msg = getmouse();
            if ( ms_x <= -1024 ) {
                ms_x = msg.x;
                ms_y = msg.y;
            }
            // 处理鼠标,移动超出范围就退出
            if ( mode == 0 ) { // 仅全屏模式才处理鼠标
                int x = msg.x, y = msg.y;
                x -= ms_x;
                y -= ms_y;
                if ( x * x + y * y > 400 ) exitflag = 1;
            }
        }
        // 显示星星
        double dt = 1.0 / fps; //fclock() - dtime;
        dtime += dt;
        for ( int i = 0; i < g_max; i++ ) {
            MoveStar( i, dt );
        }
        // 显示FPS
        {
            char str[60];
            sprintf( str, "%8.2f FPS", getfps());
            outtextxy( 0, 0, str ); //显示fps
        }
    }
    closegraph(); // 关闭图形窗口
    return 0;
}
Exemple #2
0
/////////////////////////////////////////////////
// 主函数
/////////////////////////////////////////////////
int main(int argc, char* argv[])
{
    // 初始化绘图窗口及颜色
    setinitmode(0x005, 0, 0);
    if (argc < 2)
    {
        MessageBoxW(NULL, L"本屏幕保护程序无配置", L"JuliaSet", MB_OK);
        return 0;
    }
    else if (stricmp(argv[1], "/p") == 0)
    {
        HWND hwnd;
        sscanf(argv[2], "%d", &hwnd);
        attachHWND(hwnd);
        setinitmode(0x107, 0, 0);
    }
    else if (stricmp(argv[1], "/s"))
    {
        MessageBoxW(NULL, L"本屏幕保护程序无配置", L"JuliaSet", MB_OK);
        return 0;
    }

    //initgraph(320, 240);
    initgraph(-1, -1);

    randomize();
    showmouse(0);
    FlushMouseMsgBuffer();
    while(kbhit()) getch();

    //InitColor();
    InitLog();
    g_w = getwidth(NULL);
    g_h = getheight(NULL);
    g_st = (state*)malloc(g_w * g_h * sizeof(state));
    COMPLEX c = {0.262, 0.002}, z = {0, 0};
    double r = 1.5, d = g_w / (double)g_h, rotate = 0, sr = sin(rotate), cr = cos(rotate);
    init_st(g_w, g_h);
    int n_update = 0;
    double ftime = fclock();
    {
        double dc = 64, dca = 128, db = 16;
        col_r = randomf() * dc + db;
        col_g = randomf() * dc + db;
        col_b = randomf() * dc + db;
        col_ar = randomf() * dca;
        col_ag = randomf() * dca;
        col_ab = randomf() * dca;
        rotate = randomf() * 360;
        sr = sin(rotate), cr = cos(rotate);
    }
    setrendermode(RENDER_MANUAL);
    for (int loop = 1; kbmouhit() == 0; ++loop)
    {
        int ret;
        if (loop <= 4)
        {
            ret = JDraw(c, z.re - r * d, z.im - r, z.re + r * d, z.im + r, sr, cr);
            if (loop == 4)
            {
                g_udlist.swap();
                for(int y=0; y<g_h; y++)
                {
                    for(int x=0; x<g_w; x++)
                    {
                        if (g_st[y * g_w + x].ed == 0)
                        {
                            g_udlist.push(x, y);
                        }
                    }
                }
                g_udlist.swap();
            }
        }
        else
        {
            static int t = 0;
            ret = JDrawA(c, z.re - r * d, z.im - r, z.re + r * d, z.im + r);
            if (clock() - t > 30)
            {
                delay(1);
                t = clock();
            }
        }
        if (g_updatepoint == 0)
        {
            n_update++;
        }
        else
        {
            n_update = 0;
        }
        if (0)
        {
            char str[500];
            sprintf(str, "%d %d %f %f", g_w, g_h, r, d);
            outtextxy(0, 0, str);
        }
        if (ret == 0 || n_update > 8 || loop > 1000)
        {
            loop = 0;
            if (g_mi[0][0] == 0)
            {
                delay(1);
                memset(pMap, 0, BF_W * BF_H * sizeof(state));
                g_udlist.clear();
                for (int i = 0; i < BF_W; ++i)
                {
                    addpoint(i, 0);
                    addpoint(i, BF_H - 1);
                }
                for (int i = 0; i < 4; )
                {
                    if (MDraw(-1.9, -1.2, 0.5, 1.2) == 0)
                    {
                        ++i;
                    }
                    else
                    {
                        i = 0;
                    }
                    if (kbmouhit()) return 0;
                }
            }
            double dc = 64, dca = 128, db = 16;
            col_r = randomf() * dc + db;
            col_g = randomf() * dc + db;
            col_b = randomf() * dc + db;
            col_ar = randomf() * dca;
            col_ag = randomf() * dca;
            col_ab = randomf() * dca;
            rotate = randomf() * 360;
            sr = sin(rotate), cr = cos(rotate);
            do
            {
                c.re = randomf() * 2.4 - 1.9;
                c.im = randomf() * 2.4 - 1.2;
                int ir = (int)((c.re - (-1.9)) / (0.5 - (-1.9)) * BF_W);
                int im = (int)((c.im - (-1.2)) / (1.2 - (-1.2)) * BF_H);
                if (g_mi[im][ir] >= 16)
                {
                    break;
                }
            } while (1);
            init_st(g_w, g_h);
            n_update = 0;
            if (fclock() - ftime < 3)
            {
                delay_ms((int)((3 - (fclock() - ftime)) * 1000));
            }
            else
            {
                delay(1);
            }
            ftime = fclock();
        }
    }

    closegraph();
    return 0;
}