Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.64 KB | None | 0 0
  1. #ifdef __cplusplus
  2. #include <cstdlib>
  3. #else
  4. #include <stdlib.h>
  5.  
  6. #endif
  7. #include <SDL/SDL.h>
  8. #include <math.h>
  9. #define pi 3.1415926536
  10. #include <time.h>
  11. #include <iostream>
  12. #include <fstream>
  13. using namespace std;
  14.  
  15. SDL_Surface *screen;
  16. int width = 512;
  17. int height = 340;
  18. char const* tytul = "GKiM2019 - Lab 10 - Wójcik Krystian";
  19.  
  20. SDL_Color paleta[256];
  21. int ileKolorow = 0;
  22.  
  23. struct YCbCr {
  24. float y;
  25. float cb;
  26. float cr;
  27. };
  28.  
  29. struct HSV {
  30. float h;
  31. float s;
  32. float v;
  33. };
  34.  
  35. void setPixel(int x, int y, Uint8 R, Uint8 G, Uint8 B);
  36. SDL_Color getPixel (int x, int y);
  37.  
  38. void czyscEkran(Uint8 R, Uint8 G, Uint8 B);
  39.  
  40. void Linia(int x1, int y1, int x2, int y2, Uint8 R, Uint8 G, Uint8 B);
  41. void Okrag(int x, int y, int r, Uint8 R, Uint8 G, Uint8 B);
  42. void Elipsa(int x, int y, int a, int b, Uint8 R, Uint8 G, Uint8 B);
  43. YCbCr RGBtoYCbCr(SDL_Color rgb);
  44. SDL_Color YCbCrtoRGB(YCbCr ycbcr);
  45. SDL_Color HSVtoRGB(HSV hsv);
  46. HSV RGBtoHSV(SDL_Color rgb);
  47. void Funkcja1();
  48. void Funkcja2();
  49. void Funkcja3();
  50. void Funkcja4();
  51. void Funkcja5();
  52. void Funkcja6();
  53. void Funkcja7();
  54. void Funkcja8();
  55. void Funkcja9();
  56.  
  57. bool porownajKolory(SDL_Color k1, SDL_Color k2){
  58. bool wynik = true;
  59. if(k1.r != k2.r) wynik=false;
  60. if(k1.g != k2.g) wynik=false;
  61. if(k1.b != k2.b) wynik=false;
  62. return wynik;
  63. }
  64.  
  65. int dodajKolor(SDL_Color kolor){
  66. cout<<ileKolorow<<": ["<<
  67. (int)kolor.r<<", "<<(int)kolor.g<<", "<<(int)kolor.b<<"]"<<endl;
  68.  
  69. paleta[ileKolorow] = kolor;
  70. ileKolorow++;
  71. return (ileKolorow-1);
  72. }
  73.  
  74. int sprawdzKolor(SDL_Color kolor){
  75. int wynik = -1;
  76.  
  77. if(ileKolorow>0){
  78. for(int k=0; k<ileKolorow;k++){
  79. if(porownajKolory(kolor, paleta[k])){
  80. wynik = k;
  81. }
  82. }
  83. }
  84. if(wynik<0){
  85. wynik = dodajKolor(kolor);
  86. }
  87.  
  88. return wynik;
  89. }
  90.  
  91. void Funkcja1() {
  92.  
  93. ileKolorow = 0;
  94. SDL_Color kolor;
  95.  
  96. for(int y =0; y<(height/2); y++){
  97. for(int x =0; x<(width/2); x++){
  98. kolor = getPixel(x, y);
  99. sprawdzKolor(kolor);
  100. }
  101. }
  102.  
  103. SDL_Flip(screen);
  104. }
  105.  
  106.  
  107. void Funkcja2() {
  108.  
  109. SDL_Color kolor;
  110. Uint16 szerokosc = width/2;
  111. Uint16 wysokosc = height/2;
  112. Uint8 wartosc = 0;
  113. cout<<"Zapisujemy za pomoca cout plik obrazek.bin"<<endl;
  114. ofstream wyjscie("obrazek.bin");
  115. wyjscie<<"KW"<<szerokosc<<wysokosc;
  116. for(int y=0;y<wysokosc;y++){
  117. for(int x=0; x<szerokosc; x++){
  118. kolor = getPixel(x, y);
  119. wartosc = sprawdzKolor(kolor);
  120. wyjscie<<wartosc;
  121. }
  122. }
  123. wyjscie.close();
  124.  
  125. SDL_Flip(screen);
  126. }
  127.  
  128. void Funkcja3() {
  129.  
  130. SDL_Color kolor;
  131. Uint16 szerokosc = width/2;
  132. Uint16 wysokosc = height/2;
  133. Uint8 kolory = ileKolorow;
  134. Uint8 wartosc = 0;
  135.  
  136. char identyfikator[] = "KW";
  137. cout<<"Zapisujemy za pomoca write plik obrazek.bin"<<endl;
  138. ofstream wyjscie("obrazek2.bin", ios::binary);
  139. wyjscie.write((char*)&identyfikator, sizeof(char)*2);
  140. wyjscie.write((char*)&szerokosc, sizeof(Uint16));
  141. wyjscie.write((char*)&wysokosc, sizeof(Uint16));
  142. wyjscie.write((char*)&kolory, sizeof(Uint8));
  143.  
  144. for(int y=0;y<wysokosc;y++){
  145. for(int x=0; x<szerokosc; x++){
  146. kolor = getPixel(x, y);
  147. wartosc = sprawdzKolor(kolor);
  148. wyjscie.write((char*)&wartosc, sizeof(Uint8));
  149. }
  150. }
  151. wyjscie.close();
  152.  
  153. SDL_Flip(screen);
  154. }
  155.  
  156. void Funkcja4() {
  157.  
  158. SDL_Color kolor;
  159. Uint8 wartosc;
  160. Uint16 szerokosc;
  161. Uint16 wysokosc;
  162. Uint8 kolory;
  163. char identyfikator[] = " ";
  164.  
  165. cout<<"Odczytujemy za pomoca read plik obrazek2.bin" << endl;
  166. ifstream wejscie("obrazek2.bin", ios::binary);
  167.  
  168. wejscie.read((char*)&identyfikator, sizeof(char)*2);
  169. wejscie.read((char*)&szerokosc, sizeof(Uint16));
  170. wejscie.read((char*)&wysokosc, sizeof(Uint16));
  171. wejscie.read((char*)&kolory, sizeof(Uint8));
  172.  
  173. cout<<"Parametry: "<<endl;
  174. cout<<"Identyfikator: "<<identyfikator<<endl;
  175. cout<<"Szerokosc: "<<szerokosc<<endl;
  176. cout<<"Wysokosc: "<<wysokosc<<endl;
  177. cout<<"Kolory: "<<(int)kolory<<endl;
  178.  
  179. for(int y=0;y<wysokosc;y++){
  180. for(int x=0; x<szerokosc; x++){
  181. wejscie.read((char*)&wartosc, sizeof(Uint8));
  182. kolor = paleta[wartosc];
  183. setPixel(x+(width/2), y, kolor.r, kolor.g, kolor.b);
  184. }
  185. }
  186.  
  187. SDL_Flip(screen);
  188. }
  189.  
  190.  
  191. void Funkcja5() {
  192.  
  193. //...
  194.  
  195. SDL_Flip(screen);
  196. }
  197.  
  198.  
  199. void Funkcja6() {
  200.  
  201. //...
  202.  
  203. SDL_Flip(screen);
  204. }
  205.  
  206.  
  207. void Funkcja7() {
  208.  
  209. //...
  210.  
  211. SDL_Flip(screen);
  212. }
  213.  
  214.  
  215. void Funkcja8() {
  216.  
  217. //...
  218.  
  219. SDL_Flip(screen);
  220. }
  221.  
  222.  
  223. void Funkcja9() {
  224.  
  225. //...
  226.  
  227. SDL_Flip(screen);
  228. }
  229.  
  230.  
  231. void Linia(int x1, int y1, int x2, int y2, Uint8 R, Uint8 G, Uint8 B) {
  232. setPixel(x1,y1,R,G,B);
  233. setPixel(x2,y2,R,G,B);
  234. // zmienne pomocnicze
  235. int d, dx, dy, ai, bi, xi, yi;
  236. int x = x1, y = y1;
  237. // ustalenie kierunku rysowania
  238. if (x1 < x2)
  239. {
  240. xi = 1;
  241. dx = x2 - x1;
  242. }
  243. else
  244. {
  245. xi = -1;
  246. dx = x1 - x2;
  247. }
  248. // ustalenie kierunku rysowania
  249. if (y1 < y2)
  250. {
  251. yi = 1;
  252. dy = y2 - y1;
  253. }
  254. else
  255. {
  256. yi = -1;
  257. dy = y1 - y2;
  258. }
  259. // pierwszy piksel
  260. setPixel(x, y, R, G, B);
  261. // oś wiodąca OX
  262. if (dx > dy)
  263. {
  264. ai = (dy - dx) * 2;
  265. bi = dy * 2;
  266. d = bi - dx;
  267. // pętla po kolejnych x
  268. while (x != x2)
  269. {
  270. // test współczynnika
  271. if (d >= 0)
  272. {
  273. x += xi;
  274. y += yi;
  275. d += ai;
  276. }
  277. else
  278. {
  279. d += bi;
  280. x += xi;
  281. }
  282. setPixel(x, y, R, G, B);
  283. }
  284. }
  285. // oś wiodąca OY
  286. else
  287. {
  288. ai = ( dx - dy ) * 2;
  289. bi = dx * 2;
  290. d = bi - dy;
  291. // pętla po kolejnych y
  292. while (y != y2)
  293. {
  294. // test współczynnika
  295. if (d >= 0)
  296. {
  297. x += xi;
  298. y += yi;
  299. d += ai;
  300. }
  301. else
  302. {
  303. d += bi;
  304. y += yi;
  305. }
  306. setPixel(x, y, R, G, B);
  307. }
  308. }
  309. SDL_Flip(screen);
  310. }
  311.  
  312. void RysujOkrag(int x0, int y0, int x, int y, Uint8 R, Uint8 G, Uint8 B){
  313. setPixel(x+x0, y+y0, R, G, B);
  314. setPixel(y+x0, x+y0, R, G, B);
  315. setPixel(y+x0, -x+y0, R, G, B);
  316. setPixel(x+x0, -y+y0, R, G, B);
  317. setPixel(-x+x0, -y+y0, R, G, B);
  318. setPixel(-y+x0, -x+y0, R, G, B);
  319. setPixel(-y+x0, x+y0, R, G, B);
  320. setPixel(-x+x0, y+y0, R, G, B);;
  321. }
  322.  
  323.  
  324. void Okrag(int x0, int y0, int r, Uint8 R, Uint8 G, Uint8 B) {
  325. int x =0;
  326. int y=r;
  327. int d = 3-2*r;
  328.  
  329. while (x <= y){
  330. if (d<0){
  331. d=d+4*x+6;
  332. RysujOkrag(x0, y0, x, y, R, G, B);
  333. } else{
  334. d=d+4*(x-y)+10;
  335. y--;
  336. RysujOkrag(x0, y0, x, y, R, G, B);
  337. }
  338. x++;
  339. }
  340. SDL_Flip(screen);
  341. }
  342.  
  343. void Elipsa(int x, int y, int a, int b, Uint8 R, Uint8 G, Uint8 B) {
  344. int xc = 0,
  345. yc = b;
  346. int aa = a * a,
  347. aa2 = aa + aa,
  348. bb = b * b,
  349. bb2 = bb + bb;
  350. int d = bb - aa * b + (aa / 4),
  351. dx = 0,
  352. dy = aa2 * b;
  353.  
  354. while (dx < dy) {
  355. setPixel (x - xc,y - yc, R, G, B);
  356. setPixel (x - xc,y + yc, R, G, B);
  357. setPixel (x + xc,y - yc, R, G, B);
  358. setPixel (x + xc,y + yc, R, G, B);
  359. if (d > 0){
  360. yc = yc-1;
  361. dy -= aa2;
  362. d -= dy;
  363. }
  364. xc =xc+1;
  365. dx += bb2;
  366. d += bb + dx;
  367. }
  368. d += (3 * ((aa - bb) / 2) - (dx + dy) / 2);
  369.  
  370. while (yc >= 0) {
  371. setPixel (x - xc,y - yc, R, G, B);
  372. setPixel (x - xc,y + yc, R, G, B);
  373. setPixel (x + xc,y - yc, R, G, B);
  374. setPixel (x + xc,y + yc, R, G, B);
  375. if (d < 0) {
  376. xc =xc+1;
  377. dx += bb2;
  378. d += (bb + dx);
  379. }
  380. yc = yc-1;
  381. dy -= aa2;
  382. d += aa - dy;
  383. }
  384. SDL_Flip(screen);
  385. }
  386.  
  387. YCbCr RGBtoYCbCr(SDL_Color rgb) {
  388. YCbCr ycbcr;
  389.  
  390. ycbcr.y = 0.299 * rgb.r + 0.587*rgb.g + 0.114*rgb.b;
  391. ycbcr.cb = 128 - 0.168736 * rgb.r - 0.331264*rgb.g + 0.5*rgb.b;
  392. ycbcr.cr = 128 + 0.5 * rgb.r - 0.418688*rgb.g - 0.081312*rgb.b;
  393.  
  394. return ycbcr;
  395. }
  396.  
  397. float normalizacja(float wartosc) {
  398. float wynik = wartosc;
  399. if (wartosc > 255) wartosc = 255;
  400. if (wartosc < 0) wartosc = 0;
  401. return wartosc;
  402. }
  403.  
  404. SDL_Color YCbCrtoRGB(YCbCr ycbcr) {
  405. SDL_Color rgb;
  406. int R, G, B;
  407.  
  408. R = ycbcr.y + 1.402*(ycbcr.cr-128);
  409. G = ycbcr.y - 0.344136*(ycbcr.cb-128) - 0.714136*(ycbcr.cr-128);
  410. B = ycbcr.y + 1.772*(ycbcr.cb-128);
  411.  
  412. R = normalizacja(R);
  413. G = normalizacja(G);
  414. B = normalizacja(B);
  415.  
  416. rgb = {.r=R, .g=G, .b=B};
  417. return rgb;
  418. }
  419.  
  420. HSV RGBtoHSV(SDL_Color rgb) {
  421. HSV hsv;
  422. unsigned char rgbMin, rgbMax;
  423.  
  424. rgbMin = rgb.r < rgb.g ? (rgb.r < rgb.b ? rgb.r : rgb.b) : (rgb.g < rgb.b ? rgb.g : rgb.b);
  425. rgbMax = rgb.r > rgb.g ? (rgb.r > rgb.b ? rgb.r : rgb.b) : (rgb.g > rgb.b ? rgb.g : rgb.b);
  426.  
  427. hsv.v = rgbMax;
  428. if (hsv.v == 0) {
  429. hsv.h = 0;
  430. hsv.s = 0;
  431. return hsv;
  432. }
  433.  
  434. hsv.s = 255.0*(rgbMax-rgbMin)/hsv.v;
  435.  
  436. if (hsv.s == 0) {
  437. hsv.h = 0;
  438. return hsv;
  439. }
  440.  
  441. if (rgbMax == rgb.r) {
  442. hsv.h = 0 + 43.0*(rgb.g-rgb.b)/(rgbMax-rgbMin);
  443. }
  444. else if (rgbMax == rgb.g) {
  445. hsv.h = 85 + 43.0*(rgb.b-rgb.r)/(rgbMax-rgbMin);
  446. }
  447. else {
  448. hsv.h = 171 + 43.0*(rgb.r-rgb.g)/(rgbMax-rgbMin);
  449. }
  450.  
  451. if (hsv.h>255) hsv.h-=255;
  452. if (hsv.h<0) hsv.h+=255;
  453.  
  454. hsv.s = normalizacja(hsv.s);
  455. hsv.v = normalizacja(hsv.v);
  456.  
  457. return hsv;
  458. }
  459.  
  460.  
  461. SDL_Color HSVtoRGB(HSV hsv) {
  462. SDL_Color rgb;
  463. int R, G, B;
  464.  
  465. if (hsv.h < 0) hsv.h += 255;
  466. if (hsv.h > 255) hsv.h -= 255;
  467. hsv.s = normalizacja(hsv.s);
  468. hsv.v = normalizacja(hsv.v);
  469.  
  470. unsigned char region, p, q, t;
  471. double h;
  472. unsigned int s, v, reszta;
  473.  
  474. if (hsv.s == 0) {
  475. R = hsv.v;
  476. G = hsv.v;
  477. B = hsv.v;
  478. }
  479.  
  480. h = hsv.h;
  481. s = hsv.s;
  482. v = hsv.v;
  483.  
  484.  
  485. region = h / 43;
  486. reszta = (h - (region * 43) ) * 6;
  487.  
  488. p = (v * (255 - s)) >> 8;
  489. q = (v * (255 - ((s * reszta) >> 8 ))) >> 8;
  490. t = (v * (255 - ((s * (255 - reszta)) >> 8 ))) >> 8;
  491.  
  492. switch (region) {
  493. case 0:
  494. R = v; G = t; B = p;
  495. break;
  496. case 1:
  497. R = q; G = v; B = p;
  498. break;
  499. case 2:
  500. R = p; G = v; B = t;
  501. break;
  502. case 3:
  503. R = p; G = q; B = v;
  504. break;
  505. case 4:
  506. R = t; G = p; B = v;
  507. break;
  508. default:
  509. R = v; G = p; B = q;
  510. break;
  511. }
  512. rgb = {R, G, B};
  513. return rgb;
  514. }
  515.  
  516.  
  517. void setPixel(int x, int y, Uint8 R, Uint8 G, Uint8 B)
  518. {
  519. if ((x>=0) && (x<width) && (y>=0) && (y<height))
  520. {
  521. /* Zamieniamy poszczególne składowe koloru na format koloru piksela */
  522. Uint32 pixel = SDL_MapRGB(screen->format, R, G, B);
  523.  
  524. /* Pobieramy informację ile bajtów zajmuje jeden piksel */
  525. int bpp = screen->format->BytesPerPixel;
  526.  
  527. /* Obliczamy adres piksela */
  528. Uint8 *p1 = (Uint8 *)screen->pixels + (y*2) * screen->pitch + (x*2) * bpp;
  529. Uint8 *p2 = (Uint8 *)screen->pixels + (y*2+1) * screen->pitch + (x*2) * bpp;
  530. Uint8 *p3 = (Uint8 *)screen->pixels + (y*2) * screen->pitch + (x*2+1) * bpp;
  531. Uint8 *p4 = (Uint8 *)screen->pixels + (y*2+1) * screen->pitch + (x*2+1) * bpp;
  532.  
  533. /* Ustawiamy wartość piksela, w zależności od formatu powierzchni*/
  534. switch(bpp)
  535. {
  536. case 1: //8-bit
  537. *p1 = pixel;
  538. *p2 = pixel;
  539. *p3 = pixel;
  540. *p4 = pixel;
  541. break;
  542.  
  543. case 2: //16-bit
  544. *(Uint16 *)p1 = pixel;
  545. *(Uint16 *)p2 = pixel;
  546. *(Uint16 *)p3 = pixel;
  547. *(Uint16 *)p4 = pixel;
  548. break;
  549.  
  550. case 3: //24-bit
  551. if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
  552. p1[0] = (pixel >> 16) & 0xff;
  553. p1[1] = (pixel >> 8) & 0xff;
  554. p1[2] = pixel & 0xff;
  555. p2[0] = (pixel >> 16) & 0xff;
  556. p2[1] = (pixel >> 8) & 0xff;
  557. p2[2] = pixel & 0xff;
  558. p3[0] = (pixel >> 16) & 0xff;
  559. p3[1] = (pixel >> 8) & 0xff;
  560. p3[2] = pixel & 0xff;
  561. p4[0] = (pixel >> 16) & 0xff;
  562. p4[1] = (pixel >> 8) & 0xff;
  563. p4[2] = pixel & 0xff;
  564. } else {
  565. p1[0] = pixel & 0xff;
  566. p1[1] = (pixel >> 8) & 0xff;
  567. p1[2] = (pixel >> 16) & 0xff;
  568. p2[0] = pixel & 0xff;
  569. p2[1] = (pixel >> 8) & 0xff;
  570. p2[2] = (pixel >> 16) & 0xff;
  571. p3[0] = pixel & 0xff;
  572. p3[1] = (pixel >> 8) & 0xff;
  573. p3[2] = (pixel >> 16) & 0xff;
  574. p4[0] = pixel & 0xff;
  575. p4[1] = (pixel >> 8) & 0xff;
  576. p4[2] = (pixel >> 16) & 0xff;
  577. }
  578. break;
  579.  
  580. case 4: //32-bit
  581. *(Uint32 *)p1 = pixel;
  582. *(Uint32 *)p2 = pixel;
  583. *(Uint32 *)p3 = pixel;
  584. *(Uint32 *)p4 = pixel;
  585. break;
  586.  
  587. }
  588. /* ewentualna aktualizacja obrazu (aka double buffering) */
  589. }
  590. }
  591.  
  592. SDL_Color getPixel(int x, int y) {
  593. SDL_Color color ;
  594. Uint32 col = 0 ;
  595. if ((x>=0) && (x<width) && (y>=0) && (y<height)) {
  596. //określamy pozycję
  597. char* pPosition=(char*)screen->pixels ;
  598. //przesunięcie względem y
  599. pPosition+=(screen->pitch*y*2) ;
  600. //przesunięcie względem x
  601. pPosition+=(screen->format->BytesPerPixel*x*2);
  602. //kopiujemy dane piksela
  603. memcpy(&col, pPosition, screen->format->BytesPerPixel);
  604. //konwertujemy kolor
  605. SDL_GetRGB(col, screen->format, &color.r, &color.g, &color.b);
  606. }
  607. return ( color ) ;
  608. }
  609.  
  610. SDL_Color getPixelSurface(int x, int y, SDL_Surface *surface) {
  611. SDL_Color color ;
  612. Uint32 col = 0 ;
  613. //określamy pozycję
  614. char* pPosition=(char*)surface->pixels ;
  615. //przesunięcie względem y
  616. pPosition+=(surface->pitch*y) ;
  617. //przesunięcie względem x
  618. pPosition+=(surface->format->BytesPerPixel*x);
  619. //kopiujemy dane piksela
  620. memcpy(&col, pPosition, surface->format->BytesPerPixel);
  621. //konwertujemy kolor
  622. SDL_GetRGB(col, surface->format, &color.r, &color.g, &color.b);
  623. return ( color ) ;
  624. }
  625.  
  626. void czyscEkran(Uint8 R, Uint8 G, Uint8 B)
  627. {
  628. SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, R, G, B));
  629. SDL_Flip(screen);
  630.  
  631. }
  632.  
  633. void ladujBMP(char const* nazwa, int x, int y)
  634. {
  635. SDL_Surface* bmp = SDL_LoadBMP(nazwa);
  636. if (!bmp)
  637. {
  638. printf("Unable to load bitmap: %s\n", SDL_GetError());
  639. }
  640. else
  641. {
  642. SDL_Color kolor;
  643. for (int yy=0; yy<bmp->h; yy++) {
  644. for (int xx=0; xx<bmp->w; xx++) {
  645. kolor = getPixelSurface(xx, yy, bmp);
  646. setPixel(xx, yy, kolor.r, kolor.g, kolor.b);
  647. }
  648. }
  649. SDL_FreeSurface(bmp);
  650. SDL_Flip(screen);
  651. }
  652.  
  653. }
  654.  
  655.  
  656. int main ( int argc, char** argv )
  657. {
  658. // console output
  659. freopen( "CON", "wt", stdout );
  660. freopen( "CON", "wt", stderr );
  661.  
  662. // initialize SDL video
  663. if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
  664. {
  665. printf( "Unable to init SDL: %s\n", SDL_GetError() );
  666. return 1;
  667. }
  668.  
  669. // make sure SDL cleans up before exit
  670. atexit(SDL_Quit);
  671.  
  672. // create a new window
  673. screen = SDL_SetVideoMode(width*2, height*2, 32,
  674. SDL_HWSURFACE|SDL_DOUBLEBUF);
  675. if ( !screen )
  676. {
  677. printf("Unable to set video: %s\n", SDL_GetError());
  678. return 1;
  679. }
  680.  
  681. SDL_WM_SetCaption( tytul , NULL );
  682. // program main loop
  683. bool done = false;
  684. while (!done)
  685. {
  686. // message processing loop
  687. SDL_Event event;
  688. while (SDL_PollEvent(&event))
  689. {
  690. // check for messages
  691. switch (event.type)
  692. {
  693. // exit if the window is closed
  694. case SDL_QUIT:
  695. done = true;
  696. break;
  697.  
  698. // check for keypresses
  699. case SDL_KEYDOWN:
  700. {
  701. // exit if ESCAPE is pressed
  702. if (event.key.keysym.sym == SDLK_ESCAPE)
  703. done = true;
  704. if (event.key.keysym.sym == SDLK_1)
  705. Funkcja1();
  706. if (event.key.keysym.sym == SDLK_2)
  707. Funkcja2();
  708. if (event.key.keysym.sym == SDLK_3)
  709. Funkcja3();
  710. if (event.key.keysym.sym == SDLK_4)
  711. Funkcja4();
  712. if (event.key.keysym.sym == SDLK_5)
  713. Funkcja5();
  714. if (event.key.keysym.sym == SDLK_6)
  715. Funkcja6();
  716. if (event.key.keysym.sym == SDLK_7)
  717. Funkcja7();
  718.  
  719. if (event.key.keysym.sym == SDLK_a)
  720. ladujBMP("obrazek1.bmp", 0, 0);
  721. if (event.key.keysym.sym == SDLK_s)
  722. ladujBMP("obrazek2.bmp", 0, 0);
  723. if (event.key.keysym.sym == SDLK_d)
  724. ladujBMP("obrazek3.bmp", 0, 0);
  725. if (event.key.keysym.sym == SDLK_z)
  726. ladujBMP("obrazek4.bmp", 0, 0);
  727. if (event.key.keysym.sym == SDLK_x)
  728. ladujBMP("obrazek5.bmp", 0, 0);
  729. if (event.key.keysym.sym == SDLK_c)
  730. ladujBMP("obrazek6.bmp", 0, 0);
  731.  
  732. if (event.key.keysym.sym == SDLK_l)
  733. Linia(rand()%width, rand()%height, rand()%width, rand()%height, 100+rand()%155, 100+rand()%155, 100+rand()%155);
  734. if (event.key.keysym.sym == SDLK_o)
  735. Okrag(rand()%width, rand()%height, rand()%200, 100+rand()%155, 100+rand()%155, 100+rand()%155);
  736. if (event.key.keysym.sym == SDLK_e)
  737. Elipsa(rand()%width, rand()%height, rand()%200, rand()%200, 100+rand()%155, 100+rand()%155, 100+rand()%155);
  738. if (event.key.keysym.sym == SDLK_b)
  739. czyscEkran(0, 0, 10); break;
  740. }
  741. } // end switch
  742. } // end of message processing
  743.  
  744. } // end main loop
  745.  
  746.  
  747. // all is well ;)
  748. printf("Exited cleanly\n");
  749. return 0;
  750. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement