Advertisement
Guest User

main

a guest
Jul 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.93 KB | None | 0 0
  1. float redValue = 0f;
  2. float greenValue = 0f;
  3. float blueValue = 0f;
  4.  
  5. float redValueTemp = 0f;
  6. float greenValueTemp = 0f;
  7. float blueValueTemp = 0f;
  8.  
  9. float[] color_1 = {1.0f, 0.0f, 0.0f};
  10. float[] color_2 = {0.0f, 1.0f, 0.0f};
  11. float[] color_3 = {0.0f, 0.0f, 1.0f};
  12. float[] color_4 = {1.0f, 1.0f, 1.0f};
  13.  
  14. float y = 0;
  15. float x = 0;
  16.  
  17. float x_spacing = 0;
  18. float y_spacing = 0;
  19.  
  20. float spacing_speed = 0.01f;
  21. float spacing_speed_speed = 0.001f;
  22.  
  23. boolean q_down = false;
  24. boolean a_down = false;
  25. boolean w_down = false;
  26. boolean s_down = false;
  27. boolean e_down = false;
  28. boolean d_down = false;
  29.  
  30. boolean showQuad = false;
  31.  
  32. float[] stillImage = {};
  33.  
  34. glClear(GL_COLOR_BUFFER_BIT);
  35. glMatrixMode( GL_PROJECTION );
  36. glLoadIdentity();
  37.  
  38. while(!glfwWindowShouldClose(window)) {
  39. /* Keyboard keys */
  40.  
  41. //Key Q
  42. if(glfwGetKey(window, GLFW_KEY_Q) == GL_TRUE) {
  43. x_spacing += spacing_speed;
  44. q_down = true;
  45. } else if(glfwGetKey(window, GLFW_KEY_Q) == GL_FALSE && q_down) {
  46. q_down = false;
  47. }
  48.  
  49. //Key A
  50. if(glfwGetKey(window, GLFW_KEY_A) == GL_TRUE && x_spacing - spacing_speed > 0) {
  51. x_spacing-= spacing_speed;
  52. a_down = true;
  53. } else if(glfwGetKey(window, GLFW_KEY_A) == GL_FALSE && a_down) {
  54. a_down = false;
  55. }
  56.  
  57. //Key W
  58. if(glfwGetKey(window, GLFW_KEY_W) == GL_TRUE) {
  59. y_spacing+= spacing_speed;
  60. w_down = true;
  61. } else if(glfwGetKey(window, GLFW_KEY_W) == GL_FALSE && w_down) {
  62. w_down = false;
  63. }
  64.  
  65. //Key S
  66. if(glfwGetKey(window, GLFW_KEY_S) == GL_TRUE && y_spacing - spacing_speed > 0) {
  67. y_spacing-= spacing_speed;
  68. s_down = true;
  69. } else if(glfwGetKey(window, GLFW_KEY_S) == GL_FALSE && s_down) {
  70. s_down = false;
  71. }
  72.  
  73. //Key E
  74. if(glfwGetKey(window, GLFW_KEY_E) == GL_TRUE && !e_down) {
  75. spacing_speed += spacing_speed_speed;
  76. e_down = true;
  77. } else if(glfwGetKey(window, GLFW_KEY_E) == GL_FALSE && e_down) {
  78. e_down = false;
  79. }
  80.  
  81. //Key D
  82. if(glfwGetKey(window, GLFW_KEY_D) == GL_TRUE && spacing_speed - spacing_speed_speed > 0 && !d_down) {
  83. spacing_speed -= spacing_speed_speed;
  84. d_down = true;
  85. } else if(glfwGetKey(window, GLFW_KEY_D) == GL_FALSE && d_down) {
  86. d_down = false;
  87. }
  88.  
  89. //Key Enter
  90. if(glfwGetKey(window, GLFW_KEY_ENTER) == GL_TRUE && !showQuad) {
  91. showQuad = true;
  92. } else if(glfwGetKey(window, GLFW_KEY_ENTER) == GL_FALSE && showQuad) {
  93. showQuad = false;
  94. }
  95.  
  96.  
  97. glfwPollEvents();
  98. glClear(GL_COLOR_BUFFER_BIT);
  99.  
  100. if(true) {
  101. for (int i = 0; i < (windowWidth / (x_spacing + 1)) * (windowHeight / (y_spacing + 1)); i++) {
  102.  
  103. /* First to second color */
  104.  
  105. //Red
  106. if (x > 0) {
  107. redValue = (color_1[0]) - ((1.0f - color_2[0]) / (windowWidth / x));
  108. } else {
  109. redValue = color_1[0];
  110. }
  111.  
  112. //Green
  113. if (x > 0) {
  114. greenValue = (color_1[1]) - ((1.0f - color_2[1]) / (windowWidth / x));
  115. } else {
  116. greenValue = color_1[1];
  117. }
  118.  
  119. //Blue
  120. if (x > 0) {
  121. blueValue = (color_1[2]) - ((1.0f - color_2[2]) / (windowWidth / x));
  122. } else {
  123. blueValue = color_1[2];
  124. }
  125.  
  126.  
  127. /* Third to forth color */
  128.  
  129. //Red
  130. if (x > 0) {
  131. redValueTemp = (color_3[0]) - ((1.0f - color_4[0]) / (windowWidth / x));
  132. } else {
  133. redValueTemp = color_3[0];
  134. }
  135.  
  136. //Green
  137. if (x > 0) {
  138. greenValueTemp = (color_3[1]) - ((1.0f - color_4[1]) / (windowWidth / x));
  139. } else {
  140. greenValueTemp = color_3[1];
  141. }
  142.  
  143. //Blue
  144. if (x > 0) {
  145. blueValueTemp = (color_3[2]) - ((1.0f - color_4[2]) / (windowWidth / x));
  146. } else {
  147. blueValueTemp = color_3[2];
  148. }
  149.  
  150.  
  151. /* Combining first and second with third and forth */
  152.  
  153. //Red
  154. if (y > 0) {
  155. redValue = (redValue) - ((1.0f - redValueTemp) / (windowHeight / y));
  156. }
  157.  
  158. //Green
  159. if (y > 0) {
  160. greenValue = (greenValue) - ((1.0f - greenValueTemp) / (windowHeight / y));
  161. }
  162.  
  163. //Blue
  164. if (y > 0) {
  165. blueValue = (blueValue) - ((1.0f - blueValueTemp) / (windowHeight / y));
  166. }
  167.  
  168.  
  169. /* Correction when starting value is less than finishing */
  170.  
  171. if (redValue < 0) {
  172. redValue *= -1.0f;
  173. }
  174.  
  175. if (greenValue < 0) {
  176. greenValue *= -1.0f;
  177. }
  178.  
  179. if (blueValue < 0) {
  180. blueValue *= -1.0f;
  181. }
  182.  
  183. //Apply color to pixel
  184. glColor3f(redValue, greenValue, blueValue);
  185.  
  186. //Draw point
  187. drawPoint(x, y);
  188.  
  189. //next x-pixel
  190. x += (x_spacing + 1);
  191.  
  192. //When to reset x-pixel to 0 and next y-pixel
  193. if (i % (int) ((windowWidth) / (x_spacing + 1)) == 0) {
  194. y += (y_spacing + 1);
  195. x = 0;
  196. }
  197. }
  198. }
  199.  
  200. //Reset x and y after entire array is done
  201. y = 0;
  202. x = 0;
  203.  
  204. //Draw a Quad with colors when Enter is pressed
  205. if(showQuad) {
  206. drawQuad(color_1, color_3, color_4, color_2);
  207. System.out.println("Quad showing");
  208. }
  209.  
  210. glFlush();
  211. glfwSwapBuffers(window);
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement