Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.23 KB | None | 0 0
  1. #include<gl/glut.h>
  2. #include <cmath>
  3. float d = 0, e = 0, f = 0, b = 0;
  4. float kol = -1.99; float dol = -1.99; float lol = -1.99;
  5. void fish3()
  6. {
  7. glColor3f(0.0, 1.0, 0.0);//green fish
  8. glBegin(GL_POLYGON);
  9. glVertex2f(0.8+d, 0.15);
  10. glVertex2f(0.85+d, 0.2);
  11. glVertex2f(0.95+d, 0.15);
  12. glVertex2f(0.85+d, 0.10);
  13. glEnd();
  14.  
  15. glBegin(GL_TRIANGLES);
  16. glVertex2f(0.93+d, 0.15);
  17. glVertex2f(0.98+d, 0.19);
  18. glVertex2f(0.98+d, 0.11);
  19. glEnd();
  20.  
  21.  
  22. glBegin(GL_TRIANGLES);
  23. glVertex2f(0.855+d, 0.2);
  24. glVertex2f(0.925+d, 0.25);
  25. glVertex2f(0.87+d, 0.15);
  26. glEnd();
  27.  
  28. glBegin(GL_TRIANGLES);
  29. glVertex2f(0.857+d, 0.1);
  30. glVertex2f(0.925+d, 0.05);
  31. glVertex2f(0.87+d, 0.15);
  32. glEnd();
  33.  
  34. glColor3f(0.0, 0.0, 0.0);
  35. glPointSize(4.0);
  36. glBegin(GL_POINTS);
  37. glVertex2f(0.83+d, 0.165);
  38. glEnd();
  39.  
  40. }
  41. void fish3back()
  42. {
  43. glColor3f(0.0, 1.0, 0.0);//green fish
  44. glBegin(GL_POLYGON);
  45. glVertex2f(-0.8 + d, 0.15);
  46. glVertex2f(-0.85 + d, 0.2);
  47. glVertex2f(-0.95 + d, 0.15);
  48. glVertex2f(-0.85 + d, 0.10);
  49. glEnd();
  50.  
  51. glBegin(GL_TRIANGLES);
  52. glVertex2f(-0.93 + d, 0.15);
  53. glVertex2f(-0.98 + d, 0.19);
  54. glVertex2f(-0.98 + d, 0.11);
  55. glEnd();
  56.  
  57.  
  58. glBegin(GL_TRIANGLES);
  59. glVertex2f(-0.855 + d, 0.2);
  60. glVertex2f(-0.925 + d, 0.25);
  61. glVertex2f(-0.87 + d, 0.15);
  62. glEnd();
  63.  
  64. glBegin(GL_TRIANGLES);
  65. glVertex2f(-0.857 + d, 0.1);
  66. glVertex2f(-0.925 + d, 0.05);
  67. glVertex2f(-0.87 + d, 0.15);
  68. glEnd();
  69.  
  70. glColor3f(0.0, 0.0, 0.0);
  71. glPointSize(4.0);
  72. glBegin(GL_POINTS);
  73. glVertex2f(-0.83 + d, 0.165);
  74. glEnd();
  75.  
  76. }
  77.  
  78. void fish4()
  79. {
  80. glColor3f(0.5, 0.6, 0.0);// green1 fish
  81. glBegin(GL_POLYGON);
  82. glVertex2f(-0.7 - d, -0.15);
  83. glVertex2f(-0.75 - d, -0.2);
  84. glVertex2f(-0.85 - d, -0.15);
  85. glVertex2f(-0.75 - d, -0.1);
  86. glEnd();
  87.  
  88. glBegin(GL_TRIANGLES);
  89. glVertex2f(-0.83 - d, -0.15);
  90. glVertex2f(-0.9 - d, -0.19);
  91. glVertex2f(-0.9 - d, -0.11);
  92. glEnd();
  93.  
  94.  
  95. glBegin(GL_TRIANGLES);
  96. glVertex2f(-0.755 - d, -0.2);
  97. glVertex2f(-0.795 - d, -0.25);
  98. glVertex2f(-0.775 - d, -0.15);
  99. glEnd();
  100.  
  101. glBegin(GL_TRIANGLES);
  102. glVertex2f(-0.755 - d, -0.1);
  103. glVertex2f(-0.795 - d, -0.05);
  104. glVertex2f(-0.775 - d, -0.15);
  105. glEnd();
  106.  
  107. glColor3f(0.0, 0.0, 0.0);
  108. glPointSize(4.0);
  109. glBegin(GL_POINTS);
  110. glVertex2f(-0.73 -d, -0.135);
  111. glEnd();
  112. }
  113. void fish4back()
  114. {
  115. glColor3f(0.5, 0.6, 0.0);// green1 fish
  116. glBegin(GL_POLYGON);
  117. glVertex2f(+0.7 - d, -0.15);
  118. glVertex2f(+0.75 - d, -0.2);
  119. glVertex2f(+0.85 - d, -0.15);
  120. glVertex2f(+0.75 - d, -0.1);
  121. glEnd();
  122.  
  123. glBegin(GL_TRIANGLES);
  124. glVertex2f(+0.83 - d, -0.15);
  125. glVertex2f(+0.9 - d, -0.19);
  126. glVertex2f(+0.9 - d, -0.11);
  127. glEnd();
  128.  
  129.  
  130. glBegin(GL_TRIANGLES);
  131. glVertex2f(+0.755 - d, -0.2);
  132. glVertex2f(+0.795 - d, -0.25);
  133. glVertex2f(+0.775 - d, -0.15);
  134. glEnd();
  135.  
  136. glBegin(GL_TRIANGLES);
  137. glVertex2f(+0.755 - d, -0.1);
  138. glVertex2f(+0.795 - d, -0.05);
  139. glVertex2f(+0.775 - d, -0.15);
  140. glEnd();
  141.  
  142. glColor3f(0.0, 0.0, 0.0);
  143. glPointSize(4.0);
  144. glBegin(GL_POINTS);
  145. glVertex2f(+0.73 - d, -0.135);
  146. glEnd();
  147. }
  148.  
  149. void fish5()
  150. {
  151. glColor3f(0.0, 0.0, 1.0);//blue fish
  152. glBegin(GL_POLYGON);
  153. glVertex2f(-0.7 - e, -0.25);
  154. glVertex2f(-0.75 - e, -0.3);
  155. glVertex2f(-0.775 - e, -0.3);
  156. glVertex2f(-0.85 - e, -0.25);
  157. glVertex2f(-0.775 - e, -0.2);
  158. glVertex2f(-0.75 - e, -0.2);
  159. glEnd();
  160.  
  161. glBegin(GL_TRIANGLES);
  162. glVertex2f(-0.83 - e, -0.25);
  163. glVertex2f(-0.9 - e, -0.29);
  164. glVertex2f(-0.9 - e, -0.21);
  165. glEnd();
  166.  
  167. glBegin(GL_TRIANGLES);
  168. glVertex2f(-0.775 - e, -0.2);
  169. glVertex2f(-0.79 - e, -0.125);
  170. glVertex2f(-0.75 - e, -0.2);
  171. glEnd();
  172.  
  173. glBegin(GL_TRIANGLES);
  174. glVertex2f(-0.75 - e, -0.3);
  175. glVertex2f(-0.795 - e, -0.35);
  176. glVertex2f(-0.775 - e, -0.3);
  177. glEnd();
  178.  
  179. glColor3f(0.0, 0.0, 0.0);
  180. glPointSize(4.0);
  181. glBegin(GL_POINTS);
  182. glVertex2f(-0.73 - e, -0.235);
  183. glEnd();
  184. }
  185. void fish5back()
  186. {
  187. glColor3f(0.0, 0.0, 1.0);//blue fish
  188. glBegin(GL_POLYGON);
  189. glVertex2f(+0.7 - e, -0.25);
  190. glVertex2f(+0.75 - e, -0.3);
  191. glVertex2f(+0.775 - e, -0.3);
  192. glVertex2f(+0.85- e, -0.25);
  193. glVertex2f(+0.775 - e, -0.2);
  194. glVertex2f(+0.75 - e, -0.2);
  195. glEnd();
  196.  
  197. glBegin(GL_TRIANGLES);
  198. glVertex2f(+0.83 - e, -0.25);
  199. glVertex2f(+0.9 - e, -0.29);
  200. glVertex2f(+0.9 - e, -0.21);
  201. glEnd();
  202.  
  203. glBegin(GL_TRIANGLES);
  204. glVertex2f(+0.775 - e, -0.2);
  205. glVertex2f(+0.79- e, -0.125);
  206. glVertex2f(+0.75 - e, -0.2);
  207. glEnd();
  208.  
  209. glBegin(GL_TRIANGLES);
  210. glVertex2f(+0.75 - e, -0.3);
  211. glVertex2f(+0.795 - e, -0.35);
  212. glVertex2f(+0.775 - e, -0.3);
  213. glEnd();
  214.  
  215. glColor3f(0.0, 0.0, 0.0);
  216. glPointSize(4.0);
  217. glBegin(GL_POINTS);
  218. glVertex2f(+0.73 - e, -0.235);
  219. glEnd();
  220. }
  221.  
  222.  
  223. void fish6()
  224. {
  225. glColor3f(1.0, 0.0, 0.0);//red1 fish
  226. glBegin(GL_POLYGON);
  227. glVertex2f(0.7 + f, 0.25);
  228. glVertex2f(0.75 + f, 0.3);
  229. glVertex2f(0.775 + f, 0.3);
  230. glVertex2f(0.85 + f, 0.25);
  231. glVertex2f(0.775 + f, 0.2);
  232. glVertex2f(0.75 + f, 0.2);
  233. glEnd();
  234.  
  235. glBegin(GL_TRIANGLES);
  236. glVertex2f(0.83 + f, 0.25);
  237. glVertex2f(0.9 + f, 0.29);
  238. glVertex2f(0.9 + f, 0.21);
  239. glEnd();
  240.  
  241. glBegin(GL_TRIANGLES);
  242. glVertex2f(0.775 + f, 0.3);
  243. glVertex2f(0.79 + f, 0.4);
  244. glVertex2f(0.75 + f, 0.3);
  245. glEnd();
  246.  
  247. glBegin(GL_TRIANGLES);
  248. glVertex2f(0.775 + f, 0.2);
  249. glVertex2f(0.79 + f, 0.1);
  250. glVertex2f(0.75 + f, 0.2);
  251. glEnd();
  252.  
  253. glColor3f(0.0, 0.0, 0.0);
  254. glPointSize(4.0);
  255. glBegin(GL_POINTS);
  256. glVertex2f(0.73 + f, 0.265);
  257. glEnd();
  258.  
  259. }
  260. void fish6back()
  261. {
  262. glColor3f(1.0, 0.0, 0.0);//red1 fish
  263. glBegin(GL_POLYGON);
  264. glVertex2f(-0.7 + f, 0.25);
  265. glVertex2f(-0.75 + f, 0.3);
  266. glVertex2f(-0.775 + f, 0.3);
  267. glVertex2f(-0.85 + f, 0.25);
  268. glVertex2f(-0.775 + f, 0.2);
  269. glVertex2f(-0.75 + f, 0.2);
  270. glEnd();
  271.  
  272. glBegin(GL_TRIANGLES);
  273. glVertex2f(-0.83 + f, 0.25);
  274. glVertex2f(-0.9 + f, 0.29);
  275. glVertex2f(-0.9 + f, 0.21);
  276. glEnd();
  277.  
  278. glBegin(GL_TRIANGLES);
  279. glVertex2f(-0.775 + f, 0.3);
  280. glVertex2f(-0.79 + f, 0.4);
  281. glVertex2f(-0.75 + f, 0.3);
  282. glEnd();
  283.  
  284. glBegin(GL_TRIANGLES);
  285. glVertex2f(-0.775 + f, 0.2);
  286. glVertex2f(-0.79 + f, 0.1);
  287. glVertex2f(-0.75 + f, 0.2);
  288. glEnd();
  289.  
  290. glColor3f(0.0, 0.0, 0.0);
  291. glPointSize(4.0);
  292. glBegin(GL_POINTS);
  293. glVertex2f(-0.73 + f, 0.265);
  294. glEnd();
  295.  
  296. }
  297.  
  298.  
  299. void plant()
  300. {
  301. glColor3f(0.0, 1.0, 0.0);
  302. glLineWidth(4.0);
  303. glBegin(GL_LINES);
  304. glVertex2f(0.9, -0.8);
  305. glVertex2f(0.8, -0.9);
  306. glVertex2f(0.8, -0.8);
  307. glVertex2f(0.8, -0.9);
  308. glVertex2f(0.7, -0.8);
  309. glVertex2f(0.8, -0.9);
  310. glVertex2f(0.75, -0.8);
  311. glVertex2f(0.8, -0.9);
  312. glVertex2f(0.85, -0.8);
  313. glVertex2f(0.8, -0.9);
  314. glVertex2f(0.725, -0.8);
  315. glVertex2f(0.8, -0.9);
  316. glVertex2f(0.775, -0.8);
  317. glVertex2f(0.8, -0.9);
  318. glVertex2f(0.825, -0.8);
  319. glVertex2f(0.8, -0.9);
  320. glVertex2f(0.875, -0.8);
  321. glVertex2f(0.8, -0.9);
  322.  
  323.  
  324.  
  325. glLineWidth(4.0);
  326. glBegin(GL_LINES);
  327. glVertex2f(0.5, -0.95);
  328. glVertex2f(0.6, -0.85);
  329. glVertex2f(0.5, -0.85);
  330. glVertex2f(0.5, -0.95);
  331. glVertex2f(0.4, -0.85);
  332. glVertex2f(0.5, -0.95);
  333. glVertex2f(0.45, -0.85);
  334. glVertex2f(0.5, -0.95);
  335. glVertex2f(0.55, -0.85);
  336. glVertex2f(0.5, -0.95);
  337. glVertex2f(0.425, -0.85);
  338. glVertex2f(0.5, -0.95);
  339. glVertex2f(0.475, -0.85);
  340. glVertex2f(0.5, -0.95);
  341. glVertex2f(0.525, -0.85);
  342. glVertex2f(0.5, -0.95);
  343. glVertex2f(0.575, -0.85);
  344. glVertex2f(0.5, -0.95);
  345. glEnd();
  346.  
  347.  
  348.  
  349. glLineWidth(4.0);
  350. glBegin(GL_LINES);
  351. glVertex2f(0.175, -0.9);
  352. glVertex2f(0.275, -0.8);
  353. glVertex2f(0.175, -0.8);
  354. glVertex2f(0.175, -0.9);
  355. glVertex2f(0.075, -0.8);
  356. glVertex2f(0.175, -0.9);
  357. glVertex2f(0.125, -0.8);
  358. glVertex2f(0.175, -0.9);
  359. glVertex2f(0.225, -0.8);
  360. glVertex2f(0.175, -0.9);
  361. glVertex2f(0.1, -0.8);
  362. glVertex2f(0.175, -0.9);
  363. glVertex2f(0.15, -0.8);
  364. glVertex2f(0.175, -0.9);
  365. glVertex2f(0.2, -0.8);
  366. glVertex2f(0.175, -0.9);
  367. glVertex2f(0.25, -0.8);
  368. glVertex2f(0.175, -0.9);
  369. glEnd();
  370.  
  371.  
  372.  
  373. glLineWidth(4.0);
  374. glBegin(GL_LINES);
  375. glVertex2f(-0.175, -0.95);
  376. glVertex2f(-0.275, -0.85);
  377. glVertex2f(-0.175, -0.85);
  378. glVertex2f(-0.175, -0.95);
  379. glVertex2f(-0.075, -0.85);
  380. glVertex2f(-0.175, -0.95);
  381. glVertex2f(-0.125, -0.85);
  382. glVertex2f(-0.175, -0.95);
  383. glVertex2f(-0.225, -0.85);
  384. glVertex2f(-0.175, -0.95);
  385. glVertex2f(-0.1, -0.85);
  386. glVertex2f(-0.175, -0.95);
  387. glVertex2f(-0.15, -0.85);
  388. glVertex2f(-0.175, -0.95);
  389. glVertex2f(-0.2, -0.85);
  390. glVertex2f(-0.175, -0.95);
  391. glVertex2f(-0.25, -0.85);
  392. glVertex2f(-0.175, -0.95);
  393. glEnd();
  394.  
  395. glLineWidth(4.0);
  396. glBegin(GL_LINES);
  397. glVertex2f(-0.475, -0.9);
  398. glVertex2f(-0.575, -0.8);
  399. glVertex2f(-0.475, -0.9);
  400. glVertex2f(-0.475, -0.8);
  401. glVertex2f(-0.375, -0.8);
  402. glVertex2f(-0.475, -0.9);
  403. glVertex2f(-0.425, -0.8);
  404. glVertex2f(-0.475, -0.9);
  405. glVertex2f(-0.525, -0.8);
  406. glVertex2f(-0.475, -0.9);
  407. glVertex2f(-0.4, -0.8);
  408. glVertex2f(-0.475, -0.9);
  409. glVertex2f(-0.45, -0.8);
  410. glVertex2f(-0.475, -0.9);
  411. glVertex2f(-0.5, -0.8);
  412. glVertex2f(-0.475, -0.9);
  413. glVertex2f(-0.55, -0.8);
  414. glVertex2f(-0.475, -0.9);
  415. glEnd();
  416.  
  417.  
  418.  
  419. glLineWidth(4.0);
  420. glBegin(GL_LINES);
  421. glVertex2f(-0.9, -0.85);
  422. glVertex2f(-0.8, -0.95);
  423. glVertex2f(-0.8, -0.85);
  424. glVertex2f(-0.8, -0.95);
  425. glVertex2f(-0.7, -0.85);
  426. glVertex2f(-0.8, -0.95);
  427. glVertex2f(-0.75, -0.85);
  428. glVertex2f(-0.8, -0.95);
  429. glVertex2f(-0.85, -0.85);
  430. glVertex2f(-0.8, -0.95);
  431. glVertex2f(-0.725, -0.85);
  432. glVertex2f(-0.8, -0.95);
  433. glVertex2f(-0.775, -0.85);
  434. glVertex2f(-0.8, -0.95);
  435. glVertex2f(-0.825, -0.85);
  436. glVertex2f(-0.8, -0.95);
  437. glVertex2f(-0.875, -0.85);
  438. glVertex2f(-0.8, -0.95);
  439. glEnd();
  440.  
  441. }
  442.  
  443.  
  444. void sand()
  445. {
  446. glColor3f(1.0,1.0,0.7);
  447. glBegin(GL_POLYGON);
  448. glVertex2f(-1.0,-1.0);
  449. glVertex2f(-1.0,-0.849);
  450. glVertex2f(1.0,-0.849);
  451. glVertex2f(1.0,-1.0);
  452. glEnd();
  453. }
  454. void bubble()
  455. {
  456. glPushMatrix();
  457. glTranslatef(0.8, -0.8-b,0);//1
  458. glColor3f(0.0, 0.8, 1.0);
  459. glutSolidSphere(0.05, 45, 15);
  460. glPopMatrix();
  461. glPushMatrix();
  462. glTranslatef(0.5, -0.8 - b, 0);//2
  463. glColor3f(0.0, 0.8, 1.0);
  464. glutSolidSphere(0.05, 45, 15);
  465. glPopMatrix();
  466. glPushMatrix();
  467. glTranslatef(0.2, -0.8 - b, 0); //3
  468. glColor3f(0.0, 0.8, 1.0);
  469. glutSolidSphere(0.05, 45, 15);
  470. glPopMatrix();
  471. glPushMatrix();
  472. glTranslatef(-0.2, -0.8 - b, 0); //4
  473. glColor3f(0.0, 0.8, 1.0);
  474. glutSolidSphere(0.05, 45, 15);
  475. glPopMatrix();
  476. glPushMatrix();
  477. glTranslatef(-0.5, -0.8 - b, 0); //5
  478. glColor3f(0.0, 0.8, 1.0);
  479. glutSolidSphere(0.05, 45, 15);
  480. glPopMatrix();
  481. glPushMatrix();
  482. glTranslatef(-0.8, -0.8 - b, 0); //6
  483. glColor3f(0.0, 0.8, 1.0);
  484. glutSolidSphere(0.05, 45, 15);
  485. glPopMatrix();
  486. glClearColor(0.0, 1.0, 1.0, 1.0);
  487. }
  488.  
  489. void display(void)
  490. {
  491. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  492. sand();
  493. plant();
  494. if (d >= dol)
  495. {
  496. dol = -1.99;
  497. d = d - 0.0007;
  498. fish3();
  499. fish4();
  500. }
  501. if (d < dol)
  502. {
  503. d = d + 0.0007;
  504. fish3back();
  505. dol = 1.99;
  506. fish4back();
  507. }
  508.  
  509. if (e >= kol )//-1.99
  510. {
  511. kol = -1.99;
  512. e = e - 0.0005;
  513. fish5();
  514. }
  515. if (e < kol)
  516. {
  517. e = e + 0.0005;
  518. fish5back();
  519. kol = 1.99;
  520. }
  521.  
  522. if (f >= lol)
  523. {
  524. lol = -1.99;
  525. f = f - 0.0002;
  526. fish6();
  527. }
  528. if (f < lol)
  529. {
  530. f = f + 0.0002;
  531. fish6back();
  532. lol = 1.99;
  533. }
  534. if (b >= -1.99)
  535. {
  536. b = b - 0.001;
  537. }
  538. else
  539. b = 0;
  540. bubble();
  541. glutPostRedisplay();
  542. glFlush();
  543. glutSwapBuffers();
  544.  
  545. }
  546.  
  547.  
  548. int main(int argc, char** argv)
  549. {
  550. glutInit(&argc, argv);
  551. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  552. glutInitWindowPosition(0, 0);
  553. glutInitWindowSize(500, 500);
  554. glutCreateWindow("fish");
  555. glutDisplayFunc(display);
  556. glutMainLoop();
  557. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement