Using Dev-C + +, EGE graphics library, write a small program for music playback, picture display and text bullet screen.

visual stdio code is not installed on the computer. So use dev-C + + to write a small program to make your girlfriend ha...
1.for text
2.for music:
2.for pictures:

visual stdio code is not installed on the computer. So use dev-C + + to write a small program to make your girlfriend happy. Suitable for beginners to practice c + +, full of sense of achievement, so don't spray if you don't like it.

It is rare for dev-c + + to use EGE graphics library, and there are few tutorials, so I will post a note on EGE graphics library in the future. Software download Compiler with ege image library DevCpp.exe - Internet document resources - CSDN Download.

First, let's talk about the logic and key points of the program.

Anxious students can directly look at the source code

logic

1. First, the text is presented according to a fixed track.

2. Text and pictures are displayed at the same time, and background music is played at the same time. (divided into two parts, extract the contents from the two arrays)

3. The title text is fixed, and the text information is displayed in the same line like a bullet screen. After all the contents are displayed, the text will be displayed in multiple lines at the same time. The program then loops through program three.

4. The segmentation of each part of the program is divided according to the count of currently playing photos.

main points

1.for text

Text track display

First, use a binary array to define the number of text and the size of the storage array

char buff[46][20] = {
     "This is,
     "My letter",
     "In your eyes",
     "My letter",
     "In your arms",
     "In winter,
     "Inside the hot milk tea",
     "So hot",
     "So implicit",

·······

}

Then use a two-dimensional array to represent the track:

  Execution code: (pay attention to text color and size)

for (int i = 0; i < 46; i++) { int height = 20 ; //Text height //settextcolor(red); setcolor(EGERGB(rand() % 255, rand() % 255, rand() % 255)); //Sets the color of the text setfont(height, 0, "Regular script"); //Set text width and font outtextxy(arr[i].x, arr[i].y, buff[i]);//Track coordinates and content Sleep(100); }

Text barrage flow

Define an array with static variables. I don't know why I use a > b? 0:1 cannot be executed in the compiler, so I use conditional judgment statements.

Here is to modify the x coordinate of text output.

After displaying a barrage, and then reporting another barrage, it is realized by reading the contents of a two-dimensional array

static int num_flag = 0; static int i = 780; if (i >= -100) { i -= 2; } else { i = 800; num_flag++; if (num_flag > TEXT_NUM - 1) { num_flag = 1; endflag = 1; } } #if switch setcolor(EGERGB(rand() % 200, rand() % 255, rand() % 255)); setfont(40, 0, "Song typeface"); outtextxy(i, 210, text[num_flag]); Sleep(10);

2.for music:

First save music in MP3 format.

#include "mmsystem.h" #pragma comment(lib,"winmm.lib") / / static

Play songs and switch songs

mciSendString("open mymusic1.mp3", NULL, NULL, NULL);//open mciSendString("play mymusic1.mp3", NULL, NULL, NULL);//play
//Play from music 1 to music 2 mciSendString("play mymusic1.mp3", NULL, NULL, NULL);//play mciSendString("pause mymusic1.mp3", NULL, NULL, NULL);//play mciSendString("open mymusic2.mp3", NULL, NULL, NULL);//open mciSendString("play mymusic2.mp3", NULL, NULL, NULL);//play

It should be noted here that these pairs of code must be executed in pairs to realize the function. In addition, the path of mp3 file is not strictly required.

2.for pictures:

Add: some students do not know the relationship between screen coordinates

  The red coordinates are the coordinates defined in the function for each character. The distance between the two coordinates is determined by defining the font size.

There is a concept that the source file can only be obtained. What is displayed on the screen is the size of another image format. We pasted the picture in the original format on another picture, so as to complete the scaling of the picture. Specifically, I refer to this blog post.

Original link: https://blog.csdn.net/qq_39151563/article/details/104342530

About picture header files

#include <windows.h>

definition:

be careful     screen_img = newimage(250, 270);         // The displayed image defines the zoom size
         sour_img = newimage(); // File loaded pictures

PIMAGE screen_img; PIMAGE sour_img;
void picture1() { screen_img = newimage(250, 270); //Show pictures sour_img = newimage(); //File loaded pictures char name[100] = ; sprintf(name, "C:\\Users\\Administrator\\Documents\\Tencent Filesgraph_programe\\picture1\\%d.jpg", id); if (id >= PICT_NUM1) { id = 1; } else { id++; } // (id > PICT_NUM) ? 1 : (id++); getimage(sour_img, name); int tempWidth = getwidth(sour_img), tempHeight = getheight(sour_img); putimage(screen_img, 0, 0, 250, 270, sour_img, 0, 0, tempWidth, tempHeight); putimage(290, 310, screen_img); delimage(sour_img); sour_img = NULL; delimage(screen_img); screen_img = NULL; }

It is necessary to say here

1. Forced conversion of picture name. The path must be strict. Replace \ \.

sprintf(name, "C:\\Users\\Administrator\\Documents\\Tencent Files\\1335328142\\FileRecv\\graph_programe\\picture1\\%d.jpg", id);

id is incremented until the total number of pictures starts again. Here, the pictures are renamed in numerical order, such as "1.jpg" ·····················································································.

2. File image acquisition

getimage(sour_img, name);//(defined parameters, picture path and name)

3. Display

putimage(screen_img, 0, 0, 250, 270, sour_img, 0, 0, tempWidth, tempHeight);

Corresponding to (declared display picture variable, 0, 0, display picture zoom size, width, zoom size and height, declared source picture variable, 0, 0, source file width, source file height);

The red and blue matching here shows their corresponding relationship.

putimage(290, 310, screen_img);// Print the presentation file (x starting point, y starting point).

int tempWidth = getwidth(sour_img), tempHeight = getheight(sour_img);//Source file size acquisition putimage(screen_img, 0, 0, 250, 270, sour_img, 0, 0, tempWidth, tempHeight); putimage(290, 310, screen_img);//Print presentation file
Source code
#Include < graphics. H > / / graphical interface library #include "stdio.h" #include <windows.h> #include <conio.h> //memset #define WINDOW_WIDTH 800 #define WINDOW_HEIGHT 800 #include "mmsystem.h" #pragma comment(lib,"winmm.lib") / / static //Text coordinates struct Point { int x, y; }; #define switch 1 //Text specific coordinates Point arr[] = { { 395, 268 }, { 406, 222 }, { 416, 193 }, { 441, 162 }, { 468, 133 }, { 500, 117 }, { 537, 105 }, { 577, 107 }, { 617, 120 }, { 649, 146 }, { 666, 173 }, { 680, 211 }, { 683, 247 }, { 680, 293 }, { 675, 338 }, { 660, 385 }, { 640, 440 }, { 616, 484 }, { 588, 529 }, { 557, 573 }, { 530, 610 }, { 493, 645 }, { 460, 675 }, { 422, 696 }, { 381, 676 }, { 350, 654 }, { 320, 626 }, { 292, 606 }, { 257, 570 }, { 230, 540 }, { 200, 500 }, { 180, 470 }, { 160, 430 }, { 140, 390 }, { 126, 342 }, { 117, 293 }, { 120, 250 }, { 133, 203 }, { 160, 170 }, { 200, 140 }, { 240, 130 }, { 280, 135 }, { 312, 146 }, { 340, 170 }, { 360, 195 }, { 375, 230 } }; //Define the number and length of the array as the defined type length char buff[46][20] = { "love you", "Qin", "When angry", "Like a stinky pig", "I want you close to my shoulder", "When parting", "Remember to look at me", "Remember to think about me", "Because I", "Want you to be happy", "Want to be happy", "Time and memory", "This winter", "Fallen leaves are autumn", "My little tail", "Remember to miss me~", "Picturesque and poetic", "Looking back", "Live hard", "Try to grow up", "This is", "My letter", "In Your Eyes ", "My letter", "In your arms", "In winter", "Inside the hot milk tea", "So hot", "So implicit", "Please approach", "myself", "Hug", "The warmth and coldness of life", "Sublimate it", "Our communication", "Get rid of secular", "A little restrained", "Look back", "Only us", "It's the cutest", "Remember me", "First kiss", "At that time", "Only myself", "And yourself", "Qin" }; volatile int id = 1; void picture1(); void picture2(); void pictureb(); void picturend(); //Contains the connector file. sleep function int main() { initgraph(WINDOW_WIDTH, WINDOW_HEIGHT, SHOWCONSOLE); //Initialization window /*--------------------------------Show persistent text-------------------------------*/ #if switch for (int i = 0; i < 46; i++) { int height = 20 ; //Text height //settextcolor(red); setcolor(EGERGB(rand() % 255, rand() % 255, rand() % 255)); //Sets the color of the text setfont(height, 0, "Regular script"); //Set text width and font outtextxy(arr[i].x, arr[i].y, buff[i]); // picture(); Sleep(100); } #endif /*----------------------------------------------------------------------*/ /*--------------------------------Turn on the music-------------------------------*/ mciSendString("open mymusic1.mp3", NULL, NULL, NULL);//open mciSendString("play mymusic1.mp3", NULL, NULL, NULL);//play while (1) { cleardevice(); static int pict = 0; pict++; if (pict <= 46) { #if switch for (int i = 0; i <= 46; i++) { int height = 20 ; //Text height setcolor(EGERGB(rand() % 255, rand() % 255, rand() % 255)); //Sets the color of the text setfont(height, 0, "Regular script"); //Set text width and font outtextxy(arr[i].x, arr[i].y, buff[i]); } picture1(); Sleep(300); #endif } else if (pict == 47) { #if switch setcolor(EGERGB(rand() % 255, rand() % 255, rand() % 255)); //Sets the color of the text setfont(40, 0, "Regular script"); //Set text width and font outtextxy(150, 170, "The big Alcoa show is over"); outtextxy(150, 210, "Come and see us"); mciSendString("play mymusic1.mp3", NULL, NULL, NULL);//play mciSendString("pause mymusic1.mp3", NULL, NULL, NULL);//play Sleep(10); mciSendString("open mymusic2.mp3", NULL, NULL, NULL);//open mciSendString("play mymusic2.mp3", NULL, NULL, NULL);//play pictureb(); Sleep(1500); cleardevice(); } else if (pict < 90) { static int n = 0; for (int i = 0; i <= 46; i++) { int height = 20 ; //Text height setcolor(EGERGB(rand() % 255, rand() % 255, rand() % 255)); //Sets the color of the text setfont(height, 0, "Regular script"); //Set text width and font outtextxy(arr[i].x, arr[i].y, buff[(i + n) % 47]); } picture2(); Sleep(300); n++; cleardevice(); #endif } else { picturend(); // Sleep(8800); } } // } #define PICT_NUM1 46 #define PICT_NUM2 22 PIMAGE screen_img; PIMAGE sour_img; void picture1() { screen_img = newimage(250, 270); //Show pictures sour_img = newimage(); //File loaded pictures char name[100] = ; sprintf(name, "C:\\Users\\Administrator\\Documents\\Tencent Files\\1335328142\\FileRecv\\graph_programe\\picture1\\%d.jpg", id); if (id >= PICT_NUM1) { id = 1; } else { id++; } // (id > PICT_NUM) ? 1 : (id++); getimage(sour_img, name); int tempWidth = getwidth(sour_img), tempHeight = getheight(sour_img); putimage(screen_img, 0, 0, 250, 270, sour_img, 0, 0, tempWidth, tempHeight); putimage(290, 310, screen_img); delimage(sour_img); sour_img = NULL; delimage(screen_img); screen_img = NULL; } void picture2() { screen_img = newimage(250, 270); //Show pictures sour_img = newimage(); //File loaded pictures char name[100] = ; sprintf(name, "C:\\Users\\Administrator\\Documents\\Tencent Files\\1335328142\\FileRecv\\graph_programe\\picture2\\%d.jpg", id); if (id >= PICT_NUM2) { id = 1; } else { id++; } // (id > PICT_NUM) ? 1 : (id++); getimage(sour_img, name); int tempWidth = getwidth(sour_img), tempHeight = getheight(sour_img); putimage(screen_img, 0, 0, 250, 270, sour_img, 0, 0, tempWidth, tempHeight); putimage(290, 310, screen_img); delimage(sour_img); sour_img = NULL; delimage(screen_img); screen_img = NULL; } PIMAGE screen_img1; void pictureb() { screen_img1 = newimage(250, 270); //Show pictures screen_img = newimage(250, 270); sour_img = newimage(); //File loaded pictures char name[100] = ; sprintf(name, "C:\\Users\\Administrator\\Documents\\Tencent Files\\1335328142\\FileRecv\\graph_programe\\picture2\\b2.jpg"); // (id > PICT_NUM) ? 1 : (id++); getimage(sour_img, name); int tempWidth = getwidth(sour_img), tempHeight = getheight(sour_img); putimage(screen_img, 0, 0, 250, 270, sour_img, 0, 0, tempWidth, tempHeight); putimage(150, 310, screen_img); sprintf(name, "C:\\Users\\Administrator\\Documents\\Tencent Files\\1335328142\\FileRecv\\graph_programe\\picture2\\b1.jpg"); // (id > PICT_NUM) ? 1 : (id++); getimage(sour_img, name); int tempWidth1 = getwidth(sour_img), tempHeight1 = getheight(sour_img); putimage(screen_img1, 0, 0, 250, 270, sour_img, 0, 0, tempWidth, tempHeight); putimage(400, 310, screen_img1); delimage(sour_img); sour_img = NULL; delimage(screen_img); screen_img = NULL; } #define TEXT_NUM 20 char text[TEXT_NUM][100] = { "You said, "the life you yearn for is a cat, a dog and three meals for two people~"", "What about now~Have you thought about it", "You say, "bad temper is left to close people“", "So we are close to each other", "The high school teacher said: you can learn a lot from the other half", "What have I learned?", "Why is it family affection, why is it love, and then love and hate are clear", "Don't be shy, don't be soft, show your love to the public", "Jean, what do you think you are like", "Say you're not cute. Cats like to hold you in their arms", "Say you're cute, decisive and clear-cut", "What are you like?", "In winter, like the first snow, the wind and rain suddenly drop, but the quilt is hot", "Set aside your own view of right and wrong, set aside your own view of what I am", "The rest is the wandering voice", "The rest is the way I like you~", "I wish self-discipline will bring you confidence", "I wish: love you as before", "At the beginning, there was mutual admiration and mutual awe", "At first, there is self-confidence, sunshine, and a pounding heartbeat" }; int endflag = 0; void picturend() { setcolor(EGERGB(255, 0, 128)); setfont(100, 0, "Song typeface"); outtextxy(250, 110, "L"); outtextxy(350, 110, "@"); setfont(100, 0, "Song typeface"); outtextxy(450, 110, "X"); static int num_flag = 0; static int i = 780; if (i >= -100) { i -= 2; } else { i = 800; num_flag++; if (num_flag > TEXT_NUM - 1) { num_flag = 1; endflag = 1; } } #if switch setcolor(EGERGB(rand() % 200, rand() % 255, rand() % 255)); setfont(40, 0, "Song typeface"); outtextxy(i, 210, text[num_flag]); Sleep(10); #endif int j; { if (endflag == 1) for (j = 0; j < TEXT_NUM - 1; j++) { setcolor(EGERGB(rand() % 200, rand() % 255, rand() % 255)); setfont(20, 0, "Song typeface"); outtextxy(100, 250 + j * 20, text[j]); Sleep(1800); } } cleardevice(); // } }

Multiple pictures will be used in this article. If you don't want to name them one by one, run the following python script

import os class BatchRename(): ''' Batch rename picture files in folders ''' def __init__(self): self.path = 'I:\c_test\graph_programe\picture2' #Folder path where pictures are stored def rename(self): filelist = os.listdir(self.path) total_num = len(filelist) i = 1 for item in filelist: if item.endswith('.jpg'): #The picture format is jpg src = os.path.join(os.path.abspath(self.path), item) dst = os.path.join(os.path.abspath(self.path),str(i) + '.jpg') #Set new picture name try: os.rename(src, dst) print ("converting %s to %s ..." % (src, dst)) i = i + 1 except: continue print ("total %d to rename & converted %d jpgs" % (total_num, i)) if __name__ == '__main__': demo = BatchRename() demo.rename()
Effect display:

Send it to your girlfriend or confess bravely. I wish you happiness~

7 November 2021, 12:25 | Views: 4183

Add new comment

For adding a comment, please log in
or create account

0 comments