我是靠谱客的博主 热心雪糕,最近开发中收集的这篇文章主要介绍VC6.0EasyX小玩意,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

在家太闲,编c++。

肝没了

1.MC加载动画

#include<graphics.h>
#include<conio.h>
#include<time.h>
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 <conio.h>
#include <graphics.h>
#include <time.h>
#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<number;i++){
balls[i].ball_x=rand()%600+20;
balls[i].ball_y=rand()%360+20;
for(int j=0;j<number;j++)
if(i!=j){
//³õʼ»¯ÈÃСÇò²»»áÇáÒ×Öصþ
if((balls[i].ball_x>=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<number;i++)
{
balls[i].distance[0] = 99999999;
balls[i].distance[1] = -1;
}
initgraph(640,400);
BeginBatchDraw();
while(1)
{
//»æÖÆËùÓÐСÇò
for(int i=0;i<number;i++)
{
setcolor(balls[i].coo);
setfillcolor(balls[i].coo);
fillcircle(balls[i].ball_x,balls[i].ball_y,20);
}
get_distance(balls);
knock(balls);
Sleep(2);
FlushBatchDraw();
setcolor(BLACK);
setfillcolor(BLACK);
//¸Ä±äËùÓÐСÇò×ø±ê
for(i=0;i<number;i++)
{
fillcircle(balls[i].ball_x,balls[i].ball_y,20);
balls[i].ball_x=balls[i].ball_x+balls[i].ball_vx;
balls[i].ball_y=balls[i].ball_y+balls[i].ball_vy;
if(balls[i].ball_x<=20||balls[i].ball_x>=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<number;i++)
{
for (j=0;j<number;j++)
{
if (i!=j) // ×Ô¼ººÍ×Ô¼º²»ÐèÒª±È
{
int dist2;
dist2 = (balls[i].ball_x - balls[j].ball_x)*(balls[i].ball_x - balls[j].ball_x)
+(balls[i].ball_y - balls[j].ball_y)*(balls[i].ball_y - balls[j].ball_y);
if (dist2<balls[i].distance[0])
{
balls[i].distance[0] = dist2;
balls[i].distance[1] = j;
}
}
}
}
}
void knock(struct Ball balls[number])
{
for (i=0;i<number;i++)
{
if (balls[i].distance[0]<=4*(20*20))
{
j = balls[i].distance[1];
int temp;
temp = balls[i].ball_vx; balls[i].ball_vx = balls[j].ball_vx; balls[j].ball_vx = temp;
temp = balls[i].ball_vy; balls[i].ball_vy = balls[j].ball_vy; balls[j].ball_vy = temp;
balls[j].distance[0] = 99999999; // ±ÜÃâ½»»»Á½´ÎËٶȣ¬½«Á½¸öСÇòÖØи³Öµ
balls[j].distance[1] = -1;
balls[i].distance[0] = 99999999;
balls[i].distance[1] = -1;
}
}
}

3.之前发布的夜空代码

#include <graphics.h>
#include <time.h>
#include <conio.h>
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <string>
#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/*!kbhit()*/){
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 <graphics.h>
#include <time.h>
#include <conio.h>
#include <cstdlib>
#include<iostream>
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£©"<<endl;
cin>>100-wange_size;
cout<<"²¡Ô­Êý"<<endl;
cin>>MAX;
srand( time( NULL ) );
initgraph(2200,1000);//initgraph(700,500);
draw_wangge();
for(int i=0;i<MAX;i++)
{
car2[i].color=RGB(rand()%205+50,rand()%205+50,rand()%205+50);
car2[i].x=rand()%(700/wange_size)+1;
car2[i].y=rand()%(500/wange_size)+1;;
}
for(int ii=0;ii<MAX;ii++)
{
solidrectangle(car2[ii].x*wange_size,car2[ii].y*wange_size,(car2[ii].x+1)*wange_size,(car2[ii].y+1)*wange_size);
}
while(1)
{
//delay(0.01);
BeginBatchDraw();
car_move();
for(int j=0;j<MAX;j++){
if(car2[i].x==car2[j].x&&car2[i].y==car2[j].y){
car2[i].x=100000000;
car2[i].y=100000000;
}
}
EndBatchDraw();
}
delete [] car2;
while(1);
return 0;
}
//º¯Êý
void draw_wangge ()
{
setlinecolor(BLACK);
for(int i=1;i<=700/wange_size;i++)
line(i*wange_size,0,i*wange_size,500);
for(int j=1;j<500/wange_size;j++)
line(0,j*wange_size,700,j*wange_size);
}
void car_move(){
for(int i=0;i<MAX;i++)
{
clearrectangle(car2[i].x*wange_size+1,car2[i].y*wange_size+1,car2[i].x*wange_size+wange_size-1,car2[i].y*wange_size+wange_size-1);
int k = rand()%4+1;
if(k==1){
car2[i].x-=1;
}
else if(k == 3){
car2[i].x+=1;
}
else if(k == 2){
car2[i].y-=1;
}
else if(k == 4){
car2[i].y+=1;
}
setfillcolor(car2[i].color);
solidrectangle(car2[i].x*wange_size,car2[i].y*wange_size,car2[i].x*wange_size+wange_size,car2[i].y*wange_size+wange_size);
}
}
void solidrectangle(
int left,
int top,
int right,
int bottom
);
void delay(double s)
{
double delay = s*CLOCKS_PER_SEC;
double start = clock();
while(clock()-start<delay);
}

5.钟

#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<iostream>
#include<windows.h>
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/*RGB(240,240,240)*/);
}
//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<<ti.wHour;
cout<<":";
cout<<ti.wMinute;
cout<<":";
cout<<ti.wSecond;
secEnd_x = x + secLength * sin(secAngle);
secEnd_y = y - secLength * cos(secAngle);
minEnd_x = x + minLength * sin(minAngle);
minEnd_y = y - minLength * cos(minAngle);
hourEnd_x = x + hourLength * sin(hourAngle);
hourEnd_y = y - hourLength * cos(hourAngle);
setlinestyle(PS_SOLID, 4);
setcolor(RED);
line(x, y, secEnd_x, secEnd_y);
setlinestyle(PS_SOLID, 4);
setcolor(BLACK);
line(x, y, minEnd_x, minEnd_y);
setlinestyle(PS_SOLID, 4);
setcolor(RGB(100,100,100));
line(x, y, hourEnd_x, hourEnd_y);
FlushBatchDraw();
Sleep(1000);
setcolor(BLACK);
setlinestyle(PS_SOLID, 2);
line(x, y, secEnd_x, secEnd_y);
setlinestyle(PS_SOLID, 4);
line(x, y, minEnd_x, minEnd_y);
setlinestyle(PS_SOLID, 6);
line(x, y, hourEnd_x, hourEnd_y);
system("cls");
}
EndBatchDraw();
getch();
closegraph();
return 0;
}

6.代码雨

#include <stdio.h>
#include <windows.h>
#include <graphics.h>
#include <stdlib.h>
#include <time.h>
#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;
}

欢迎关注、评论、收藏!

允许转载

最后

以上就是热心雪糕为你收集整理的VC6.0EasyX小玩意的全部内容,希望文章能够帮你解决VC6.0EasyX小玩意所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(26)

评论列表共有 0 条评论

立即
投稿
返回
顶部