在家太闲,编c++。
肝没了
1.MC加载动画
#include#include #include int main(){ initgraph(500, 300); setfillcolor(RGB(60,20,0)); setbkcolor RGB(60,20,0); solidrectangle(0,0,1000,1000); int x=50; setfillcolor(RGB(0,250,0)); setlinecolor(RGB(0,150,0)); setlinestyle(PS_SOLID | PS_JOIN_BEVEL, 2); setbkmode(OPAQUE); outtextxy(230,100,"Æô¶¯ÖÐ..."); while(x<=450){ BeginBatchDraw(); solidrectangle(50,155,x,165); int xn=50; while(xn<=x){ rectangle(50,155,xn,165); xn+=25; } rectangle(xn+2,155,x,165); EndBatchDraw(); if(rand()%10>1)Sleep(rand()%1); else Sleep(rand()%300); clearrectangle(50,155,x,165); x++; } }
2.一堆彩色小球撞来撞去
#include#include #include #define number 10 //СÇò¸öÊý struct Ball{ int ball_x; int ball_y; int ball_vx; int ball_vy; int distance[2]; int coo;}; Ball balls[number]; int main(){ void get_distance(struct Ball balls[number]); void knock(struct Ball balls[number]); srand((unsigned)time(NULL)); for(int i=0;i =balls[j].ball_x-20)&&(balls[i].ball_x<=balls[j].ball_x+20)&& (balls[i].ball_y>=balls[j].ball_y-20)&&(balls[i].ball_y<=balls[j].ball_y+20)) { balls[i].ball_x=rand()%600+20; balls[i].ball_y=rand()%360+20; } } balls[i].ball_vx=1; balls[i].ball_vy=1; balls[i].coo=RGB(rand()%255,rand()%255,rand()%255); //printf("[%d,%d]n",balls[i].ball_x,balls[i].ball_y); } for (i=0;i =620) balls[i].ball_vx=-balls[i].ball_vx; if(balls[i].ball_y<=20||balls[i].ball_y>=380) balls[i].ball_vy=-balls[i].ball_vy; } } EndBatchDraw(); closegraph(); return 0; } int i,j; void get_distance(struct Ball balls[number]) { // Çó½âËùÓÐСÇòÁ½Á½Ö®¼äµÄ¾àÀëÆ½·½ for (i=0;i 3.之前发布的夜空代码
#include#include #include #include #include #include #include #define MAXSTAR 15 // ÐÇÐÇ×ÜÊý #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) struct STAR { double x; int y; double step; int color; }; STAR star[MAXSTAR]; // ³õʼ»¯ÐÇÐÇ void InitStar(int i) { star[i].x = 0; star[i].y = rand() % 480; star[i].step = (rand() % 5000) / 1000.0 + 1; star[i].color = (int)(star[i].step * 255 / 6.0 + 0.5); // ËÙ¶ÈÔ½¿ì£¬ÑÕɫԽÁÁ star[i].color = RGB(star[i].color, star[i].color, star[i].color); } // ÒÆ¶¯ÐÇÐÇ void MoveStar(int i) { // ²ÁµôÔÀ´µÄÐÇÐÇ putpixel((int)star[i].x, star[i].y, 0); putpixel((int)star[i].x+1, star[i].y, 0); putpixel((int)star[i].x+1, star[i].y+1, 0); putpixel((int)star[i].x, star[i].y+1, 0); putpixel((int)star[i].x, star[i].y, 0); putpixel((int)star[i].x+2, star[i].y, 0); putpixel((int)star[i].x+2, star[i].y+2, 0); putpixel((int)star[i].x, star[i].y+2, 0); putpixel((int)star[i].x+2, star[i].y+1, 0); putpixel((int)star[i].x+2, star[i].y+1, 0); putpixel((int)star[i].x+1, star[i].y+2, 0); putpixel((int)star[i].x+1, star[i].y+2, 0); // ¼ÆËãÐÂλÖà star[i].x += star[i].step/3; if (star[i].x > 640) InitStar(i); // »ÐÂÐÇÐÇ putpixel((int)star[i].x, star[i].y, star[i].color); putpixel((int)star[i].x+1, star[i].y, star[i].color); putpixel((int)star[i].x+1, star[i].y+1, star[i].color); putpixel((int)star[i].x, star[i].y+1, star[i].color); putpixel((int)star[i].x, star[i].y, star[i].color); putpixel((int)star[i].x+2, star[i].y, star[i].color); putpixel((int)star[i].x+2, star[i].y+2, star[i].color); putpixel((int)star[i].x, star[i].y+2, star[i].color); putpixel((int)star[i].x+2, star[i].y+1, star[i].color); putpixel((int)star[i].x+2, star[i].y+1, star[i].color); putpixel((int)star[i].x+1, star[i].y+2, star[i].color); putpixel((int)star[i].x+1, star[i].y+2, star[i].color); } // Ö÷º¯Êý int main() { int cx=GetSystemMetrics(SM_CXSCREEN); int cy=GetSystemMetrics(SM_CYSCREEN); HWND hwnd=GetForegroundWindow(); printf("initcode...n"); printf("initheadfile...n"); printf("initmain...n"); printf("initEasyX...n"); int fp=0,fps,sta=(unsigned)time(NULL); loadimage(NULL,NULL,NULL,NULL,NULL,NULL); srand((unsigned)time(NULL)); // Ëæ»úÖÖ×Ó initgraph(640, 480); printf("initgraph...n"); settextcolor(RGB(255,255,255));// ´´½¨»æÍ¼´°¿Ú // ³õʼ»¯ËùÓÐÐÇÐÇ for(int i = 0; i < MAXSTAR; i++) { InitStar(i); star[i].x = rand() % 640; } MOUSEMSG m; printf("initstar...n"); printf("startpaintn"); printf("loadtime:0.2sn"); printf("Showgraph...n"); printf("startanimationn"); SetWindowPos(hwnd,HWND_TOP,1,cy/2,cx/2,cy/2,0); while(1){ ShowWindow(GetForegroundWindow(),1); BeginBatchDraw(); fp++; for(int i = 0; i < MAXSTAR; i++) MoveStar(i); setfillcolor(RGB(255,255,200)); solidcircle(100,100,20); clearcircle(95,95,20); setfillcolor(RGB(235,235,180)); solidcircle(100,100,19); clearcircle(95,95,19); setfillcolor(RGB(200,200,145)); solidcircle(100,100,18); clearcircle(95,95,18); setfillcolor(RGB(0,40,0)); solidellipse(0,450,639,500); if(KEY_DOWN('E')){ settextcolor(RGB(255,255,255)); outtextxy(1,1,"made from Microsoft Visual C++ 6.0.0"); outtextxy(1,20,"star 0.0.81 made by Jared"); outtextxy(1,40,"Use Graphics.h Headfile --From EasyX.h"); outtextxy(1,60,"EasyX html:"); settextcolor(RGB(90,150,255)); outtextxy(1,80,"https://easyx.cn/"); settextcolor(RGB(255,255,255)); outtextxy(1,100,"Press E:Help"); outtextxy(1,120,"Press C:initgraph"); outtextxy(1,140,"Press R:closegraph"); if(MouseHit())outtextxy(1,160,"Mousehit:1"); else outtextxy(1,160,"Mousehit:0"); if(MouseHit()){ m=GetMouseMsg(); switch(m.uMsg){} } } if(KEY_DOWN('R')){ closegraph(); } if((int)time(0)-sta>=1){ fps=fp; fp=0; sta=(int)time(0); } if(KEY_DOWN('C')){ closegraph(); ShowWindow(GetForegroundWindow(),0); SetWindowPos(hwnd,HWND_TOP,1,cy/2,cx/2,cy/2,0); initgraph(640,480); } EndBatchDraw(); Sleep(20); clearrectangle(0,0,1000,1000); } closegraph(); } 4.随便编的
#include#include #include #include #include int wange_size; int MAX ; #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) void draw_wangge();//»Íø¸ñ void car_move();//³µÒƶ¯ void solidrectangle(); void delay(double);//ÑÓʱ struct car{ int x,y,color; }; car* car2= new car [MAX]; //Ö÷º¯Êý int main() { using namespace std; cout<<"ÊÓÒ°£¨2µ½100£©"< >100-wange_size; cout<<"²¡ÔÊý"< >MAX; srand( time( NULL ) ); initgraph(2200,1000);//initgraph(700,500); draw_wangge(); for(int i=0;i 5.钟
#include#include #include #include #include using namespace std; #define high 480 #define width 640 #define PI 3.14159 int main() { initgraph(width, high,SHOWCONSOLE); int x, y; x = width / 2; y = high / 2; int secLength = width / 3.8; int minLength = width / 4; int hourLength = width / 5.5; int secEnd_x, secEnd_y; int minEnd_x, minEnd_y; int hourEnd_x, hourEnd_y; float secAngle, minAngle, hourAngle; SYSTEMTIME ti; //±£´æµ±Ç°Ê±¼ä BeginBatchDraw(); while(1) { setbkcolor(RGB(200,200,200)); cleardevice(); setlinestyle(PS_SOLID, 3); setcolor(RGB(240,240,240)); circle(x, y, width / 3); int x2, y2, i; for(i = 0; i < 60; i++) { x2 = x + int(width / 3.3 * sin(PI * 2 * i / 60)); y2 = y - int(width / 3.3 * cos(PI * 2 * i / 60)); if(i % 15 == 0) bar(x2 - 5, y2 - 5, x2 + 5, y2 + 5); else if(i % 5 == 0) circle(x2, y2, 3); else circle(x2, y2, 1); } //settextstyle(32, 0, _T("Consolas")); //outtextxy(x - 110, y - width / 6, "Made in ChangSha"); //outtextxy(x - 110, y + width / 9, "Richard's Clock"); GetLocalTime(&ti); secAngle = ti.wSecond * 2 * PI / 60; minAngle = ti.wMinute * 2 * PI / 60; hourAngle = ti.wHour * 2 * PI / 12; //1Ȧ12Сʱ system("color F0"); cout< 6.代码雨
#include#include #include #include #include #define SCREEN_WIDTH 500 #define SCREEN_HEIGHT 500 #define DEF_RAIN_NUM 200//×Ö·ûÓêÊýÁ¿ÏÞÖÆ×î´ó200 //ÓêµÄÁÐÊý //Êý×ÖÓ꿪ʼµÄλÖà int g_nRainPos[DEF_RAIN_NUM] = { 0 }; //Êý×ÖÓêµÄ×Ö·û´® char g_strRain[DEF_RAIN_NUM][10] = { 0 }; //Ëæ»ú²úÉúÒ»¸ö×Öĸ char CreateRandomNum() { char nRandomNum = 0; while( 1 ) { nRandomNum = rand() % 123; //Ëæ»ú²úÉú0~122µÄÒ»¸ö×Ö·û if( ( nRandomNum >= 65 && nRandomNum <= 90 ) || nRandomNum >= 97 ) { return nRandomNum; } } } //Ëæ»ú²úÉúÊý×ÖÓêµÄ¿ªÊ¼Î»Öà void InitPos() { for( int i = 0; i < DEF_RAIN_NUM; i++ ) { g_nRainPos[i] = rand() % SCREEN_HEIGHT; } } //³õʼ»¯Êý×ÖÓê void InitNumRain() { for( int i = 0; i < DEF_RAIN_NUM; i++ ) { for( int j = 0; j < 10; j++ ) { g_strRain[i][j] = CreateRandomNum(); } } } //ÏÔʾÓê void ShowNumRain() { for( int i = 0; i < DEF_RAIN_NUM; i++ ) { //ÉèÖÃ×ÖÌåÑÕÉ« settextcolor( RGB( 150, 255, 150 ) ); //°×É« for( int j = 0; j < 10; j++ ) { outtextxy( i * 15, g_nRainPos[i] - 15 * j, g_strRain[i][j] ); settextcolor( RGB( 0, 255 - 28 * j, 0 ) ); } } for( i = 0; i < DEF_RAIN_NUM; i++ ) { g_nRainPos[i] += 15; //ÆÁĻˢкóÓêµÄλÖÃϽµ15 } for( i = 0; i < DEF_RAIN_NUM; i++ ) { if( g_nRainPos[i] - 10 * 15 >= SCREEN_HEIGHT ) { g_nRainPos[i] = 0; } } } int main() { srand((unsigned)time(NULL)); initgraph( SCREEN_WIDTH, SCREEN_HEIGHT ); InitPos(); InitNumRain(); BeginBatchDraw(); while( 1 ) { InitNumRain(); ShowNumRain(); FlushBatchDraw(); Sleep(120); //ÑÓʱ0.1Ãë cleardevice(); //Çå¿ÕÆÁÄ» } EndBatchDraw(); closegraph(); return 0; } 欢迎关注、评论、收藏!
允许转载



