point arr[NUM]={{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}};
然后坐標有了,我就可以實現字符串組成心形的功能了:
intmain(){initgraph(800,800);for(int i =0; i < NUM; i++){settextcolor(RED);outtextxy(arr[i].x, arr[i].y,"yyds");Sleep(100);}
char buff[NUM][50]={"一封信","兩年未都","沒動筆","三個字","過了","幾個四季","你是有","多想逃避","來不及","問問你","我已經","錯過","相愛","的日期","那天你","消失在","人海里","你的背影","沉默的","讓人恐懼","你說的","那些問題","我回答得","很堅定","偏偏","那個時候","我最想你","我不曾","愛過你","我自己","騙自己","已經給你","寫了信","又被我","丟進海里","我不曾","愛過你","我自己","騙自己","明明覺得","自己","很冷靜","卻還","掉入","我自己","的陷阱"};intmain(){initgraph(800,800);for(int i =0; i < NUM; i++){settextcolor(RED);outtextxy(arr[i].x, arr[i].y, buff[i]);Sleep(100);}}
我想要更騷一點的,不同字符串不同顏色 添加隨機函數頭和time頭就可以
#include<time.h>#include<conio.h>intmain(){initgraph(800,800);srand(time(NULL));for(int i =0; i < NUM; i++){settextcolor(RGB(rand()%256,rand()%256,rand()%256));outtextxy(arr[i].x, arr[i].y, buff[i]);Sleep(100);}}
接下來是字符串滾動: 如何讓字體愛的魔力轉圈圈呢? 很簡單更換字符串就行,看我代碼實現理解:
while(1){for(int i =0; i < NUM; i++){settextcolor(RGB(rand()%256,rand()%256,rand()%256));outtextxy(arr[i].x, arr[i].y, buff[(i+n)%NUM]);}Sleep(500);n++;}}
while(1){for(int i =0; i < NUM; i++){cleardevice();settextcolor(RGB(rand()%256,rand()%256,rand()%256));outtextxy(arr[i].x, arr[i].y, buff[(i+n)%NUM]);}Sleep(500);n++;}}
while(1){cleardevice();for(int i =0; i < NUM; i++){settextcolor(RGB(rand()%256,rand()%256,rand()%256));outtextxy(arr[i].x, arr[i].y, buff[(i+n)%NUM]);}putimage(300,300,&img[n%8]);Sleep(500);n++;}
#include<stdio.h>#include<time.h>#include<conio.h>#include<graphics.h>#include<Windows.h>#include<mmsystem.h>//一定要加Windows頭文件#pragma comment(lib,"winmm.lib")constint NUM =46;struct point
{int x;int y;};
point arr[NUM]={{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}};char buff[NUM][50]={"一封信","兩年未都","沒動筆","三個字","過了","幾個四季","你是有","多想逃避","來不及","問問你","我已經","錯過","相愛","的日期","那天你","消失在","人海里","你的背影","沉默的","讓人恐懼","你說的","那些問題","我回答得","很堅定","偏偏","那個時候","我最想你","我不曾","愛過你","我自己","騙自己","已經給你","寫了信","又被我","丟進海里","我不曾","愛過你","我自己","騙自己","明明覺得","自己","很冷靜","卻還","掉入","我自己","的陷阱"};intmain(){initgraph(800,800);srand(time(NULL));IMAGE img[8];char temp[256];for(int i =0;i<8;i++){memset(temp,0,sizeof(char)*256);sprintf_s(temp,"image\\%d.jpg", i+1);loadimage(&img[i], temp,200,200, true);}for(int i =0; i < NUM; i++){settextcolor(RGB(rand()%256,rand()%256,rand()%256));outtextxy(arr[i].x, arr[i].y, buff[i]);Sleep(100);}//putimage(300,300,&img[0]);mciSendString("open 1.mp3",NULL,NULL,NULL);mciSendString("play 1.mp3",NULL,NULL,NULL);Sleep(3000);int n =0;while(1){cleardevice();for(int i =0; i < NUM; i++){settextcolor(RGB(rand()%256,rand()%256,rand()%256));outtextxy(arr[i].x, arr[i].y, buff[(i+n)%NUM]);}putimage(300,300,&img[n%8]);Sleep(500);n++;}}