Diagram in VC using Graphics.h drawing (similar TC)

Source: Internet
Author: User
Tags random seed

1 www.easyx.cn Download Easyx Library

I am under the 2014, after decompression as;

2 Install according to your own VC version

3 Draw a circle in the console

#include <graphics.h>//reference graphics library # include <conio.h>void main () {     initgraph (640, 480);//Initialize drawing window     Circle (200, 200, 100); Draw Circle, Circle Center (200, 200), Radius of     getch ();//Press any key to continue     closegraph ();///Close Graphical interface}

4 Draw a block in the console

#include <graphics.h> #include <conio.h> #define PI 3.14159265void Main () {//Create a drawing window of size 800 * 600 initgraph ( 400, 300);//Set the origin (0, 0) to the center of the screen (y-axis default downward is positive) setorigin (200, 150);//Use Tibetan cyan fill background setbkcolor (0x7c5731); Cleardevice ();// Set drawing style setlinecolor (white);//Set Line color to Setlinestyle (Ps_solid | Ps_endcap_flat, 10);//Set the line style to a solid line of width 10, the end is flat setfillcolor (0x24c097);//Set the fill color to green//Draw square fillroundrect (-75,-111, 75, 39, 36, 36);//Press any key to exit _getch (); Closegraph ();}

5 stars

This is an example from the EASYX website;

Program name: Star//Compilation environment: Visual C + + 6.0,EASYX 2011 Version Jingzhe//Last update: 2009-2-22//#include <graphics.h> #include <time.h># Include <conio.h> #define Maxstar 200//stars total struct star{double x;int y;double step;int color;}; Star star[maxstar];//initialize star void Initstar (int i) {star[i].x = 0;star[i].y = rand ()% 480;star[i].step = (rand ()% 5000)/10 00.0 + 1;star[i].color = (int) (STAR[I].STEP * 255/6.0 + 0.5);//faster, brighter colors Star[i].color = RGB (Star[i].color, Star[i].colo R, Star[i].color);} Move star void MoveStar (int i) {//Erase the original star Putpixel ((int) star[i].x, star[i].y, 0);//Calculate new position star[i].x + = star[i].step;if (star[ i].x > 640) Initstar (i);//Draw New Star Putpixel ((int) star[i].x, star[i].y, Star[i].color);} Main function void Main () {srand (unsigned) time (NULL));//random seed initgraph (640, 480);//Open graphics window//Initialize All Stars for (int i=0; i<maxstar; i++) {Initstar (i); star[i].x = rand ()% 640;} Draw the sky, press any key to exit while (!kbhit ()) {for (int i=0; i<maxstar; i++) MoveStar (i); Sleep (20);}    Closegraph (); Close the graphics window}

6 screen

This is also an example from the EASYX website, demonstrating that graphics.h can also be used in WIN32 programs;

Program Name: Implementing Desktop//Compilation environment: Visual C + + 6.0/2010,easyx 20130117 (  Beta)//author: yangw80 <[email protected]>//Last modified: 2013-1-29//project type: Win32 application//#include <graphics.h>// Grab the desktop image into the *pimg object in void Capturedesktop (image *pimg) {//Get the desktop's wide-height int w = getsystemmetrics (sm_cxscreen)/2;int through the Windows API h = getsystemmetrics (sm_cyscreen)/2;//Adjust the size of the pimg resize (pimg, W, h);//Get desktop Dchdc SRCDC = GetDC (NULL);//Get the IMAGE object's D Chdc dstdc = GETIMAGEHDC (pimg);//Perform an image copy between two DCs and copy the desktop capture to the Image object BitBlt (dstdc, 0, 0, W, H, SRCDC, 0, 0, srccopy);} Main function int apientry WinMain (hinstance hinstance, hinstance hprevinstance, LPSTR lpcmdline, int ncmdshow) {//Definition IMAGE Object imag E img;//Call the function capturedesktop (&img) that crawls the desktop image;//create drawing window initgraph (500, 300);//Display the desktop image saved in the image in the window putimage (0, 0, & IMG);//press ESC to exit while (!) ( Getasynckeystate (vk_escape) & 0x8000)) Sleep (closegraph); return 0;}

7 Making a character animation

Make a character drop animation from the top of the console window;

#include <graphics.h> #include <conio.h> #include <time.h>//main function void Main () {Initgraph (400, 300);// The initialization screen is 640x480srand (Time (NULL));//Set random seed setfont (0, "Arial");//Set the letter font and size setfillstyle (BLACK);// Set clear letter Fill area color char target;//destination letter int x, y;//letter Position//main loop while (true) {target = + rand ()% 26;//produces any capital letter x = rand ()% 380;/ /Generate any drop position for (y=0; y<280; y++) {setcolor (GREEN);//Set the color of the letters OUTTEXTXY (x, y, target),//Display the letter//delay, and clear the letter sleep (x); Bar ( Y, x + +, y + 16);}} Close the graphical interface Closegraph ();}

There are some problems, the whereabouts of the letter will drag a white tail;

8 improvements

Create code in VC use the default. cpp extension directly, and do not add the. c extension.
Not all TC graphing functions are supported, and many functions become more powerful in the Easyx library, such as color, which can only support 16 colors in the past, and now supports tens of thousands of colors. There are fonts, you can use any fonts installed under Windows, and so on. Refer to help.

Above project download




Diagram in VC using Graphics.h drawing (similar TC)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.