Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. #include "testApp.h"
  2.  
  3. //--------------------------------------------------------------
  4. void testApp::setup(){
  5. file.open("hand_in_4.txt");
  6.  
  7. if(file.is_open){
  8. do{
  9. file >> g_type >> image_name >> x >> y >> w >> h;
  10. if(g_type == "image"){
  11. interview.loadImage(image_name);
  12. interview.resize(w, h);
  13. data = new unsigned char [w*h*3];
  14. image_texture.allocate(w, h, GL_RGB);
  15. data = interview.getPixels();
  16. image_texture.loadData(data, w, h, GL_RGB);
  17. }
  18.  
  19. if(g_type == "triangle"){
  20. ofTriangle(x1, y1, x2, y2, x3, y3);
  21. }
  22.  
  23. if(g_type == "rect"){
  24. ofSetColor(255, 0, 0);
  25. ofNoFill();
  26. ofSetLineWidth(5);
  27. ofRect(x1, y1, x2, y2);
  28. }
  29.  
  30. if(g_type == "circle"){
  31. ofSetColor(165, 189, 25);
  32. ofFill();
  33. ofSetCircleResolution(100);
  34. ofCircle(x1, y1, rad);
  35. }
  36.  
  37. if(g_type == "rainbow"){
  38. ofSetLineWidth(w);
  39. ofSetColor(255, 0, 0);
  40. ofLine(x1, y1, x2, y2);
  41. ofSetColor(0,255,0);
  42. ofLine(x1, y1+10, x2, y2+20);
  43. ofSetColor(165, 189, 25);
  44. ofLine(x1, y1+20, x2, y2+40);
  45. ofSetColor(255, 0, 0);
  46. ofLine(x1, y1+30, x2, y2+60);
  47. ofSetColor(255, 0, 0);
  48. ofLine(x1, y1+40, x2, y2+80);
  49. ofSetColor(255, 0, 0);
  50. ofLine(x1, y1+50, x2, y2+100);
  51. }
  52.  
  53. if(g_type == "box"){
  54. ofSetColor(255, 0, 0);
  55. ofNoFill();
  56. ofBox(x1, y1, z, size);
  57. }
  58.  
  59. if(g_type == "sphere"){
  60. ofNoFill();
  61. ofSetLineWidth(1);
  62. ofSphere(x1,y1,z,rad);
  63. }
  64.  
  65. }while(! file.eof());
  66.  
  67. file.close();
  68. }
  69.  
  70. }
  71.  
  72. //--------------------------------------------------------------
  73. void testApp::update(){
  74.  
  75. }
  76. /*
  77. //--------------------------------------------------------------
  78. void testApp::draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3){
  79.  
  80. ofSetLineWidth(3);
  81.  
  82. ifstream file("hand_in_4.txt");
  83. do{
  84. file >> g_type >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
  85. if(g_type == "triangle"){
  86. ofTriangle(x1, y1, x2, y2, x3, y3);
  87. }
  88. }while(! file.eof());
  89.  
  90. file.close();
  91.  
  92. }
  93.  
  94. //--------------------------------------------------------------
  95. void testApp::draw_rect(int x1, int y1, int x2, int y2){
  96.  
  97. ifstream file("hand_in_4.txt");
  98. do{
  99. file >> g_type >> x1 >> y1 >> x2 >> y2;
  100. if(g_type == "rect"){
  101. ofSetColor(255, 0, 0);
  102. ofNoFill();
  103. ofSetLineWidth(5);
  104. //ofRotateY(45);
  105. ofRect(x1, y1, x2, y2);
  106. }
  107. }while(! file.eof());
  108.  
  109. file.close();
  110.  
  111. }
  112.  
  113. //-------------------------------------------------------------
  114. void testApp::draw_circle(int x1, int y1, int rad){
  115.  
  116. ifstream file("hand_in_4.txt");
  117. do{
  118. file >> g_type >> x1 >> y1 >> rad;
  119. if(g_type == "circle"){
  120. ofSetColor(165, 189, 25);
  121. ofFill();
  122. ofSetCircleResolution(100);
  123. ofCircle(x1, y1, rad);
  124. }
  125. }while(! file.eof());
  126.  
  127. file.close();
  128.  
  129. }
  130.  
  131. //-------------------------------------------------------------
  132. void testApp::draw_rainbow(int x1, int y1, int x2, int y2, int w){
  133.  
  134. ifstream file("hand_in_4.txt");
  135. do{
  136. file >> g_type >> x1 >> y1 >> x2 >> y2;
  137. if(g_type == "rainbow"){
  138. ofSetLineWidth(w);
  139. ofSetColor(255, 0, 0);
  140. ofLine(x1, y1, x2, y2);
  141. ofSetColor(0,255,0);
  142. ofLine(x1, y1+10, x2, y2+20);
  143. ofSetColor(165, 189, 25);
  144. ofLine(x1, y1+20, x2, y2+40);
  145. ofSetColor(255, 0, 0);
  146. ofLine(x1, y1+30, x2, y2+60);
  147. ofSetColor(255, 0, 0);
  148. ofLine(x1, y1+40, x2, y2+80);
  149. ofSetColor(255, 0, 0);
  150. ofLine(x1, y1+50, x2, y2+100);
  151. }
  152. }while(! file.eof());
  153.  
  154. file.close();
  155.  
  156. }
  157.  
  158. //----------------------------------------------------
  159. void testApp::draw_box(int x1, int y1, int z, int size){
  160.  
  161. ifstream file("hand_in_4.txt");
  162. do{
  163. file >> g_type >> x1 >> y1 >> z >> size;
  164. if(g_type == "box"){
  165. ofSetColor(255, 0, 0);
  166. ofNoFill();
  167. ofBox(x1, y1, z, size);
  168. }
  169. }while(! file.eof());
  170.  
  171. file.close();
  172.  
  173. }
  174.  
  175. //----------------------------------------------------
  176. void testApp::draw_sphere(int x1, int y1, int z, int rad){
  177.  
  178. ifstream file("hand_in_4.txt");
  179. do{
  180. file >> g_type >> x1 >> y1 >> z >> rad;
  181. if(g_type == "sphere"){
  182. ofNoFill();
  183. ofSetLineWidth(1);
  184. ofSphere(x1,y1,z,rad);
  185. }
  186. }while(! file.eof());
  187.  
  188. file.close();
  189.  
  190. }
  191. */
  192. //--------------------------------------------------------------
  193. void testApp::draw(){
  194. ofBackground(0);
  195.  
  196. image_texture.draw(x, y, w, h);
  197.  
  198. ofTriangle(x1, y1, x2, y2, x3, y3);
  199.  
  200. ofRect(x1, y1, x2, y2);
  201.  
  202. ofCircle(x1, y1, rad);
  203.  
  204. ofLine(x1, y1, x2, y2, w);
  205.  
  206. ofBox(x1, y1, z, size);
  207.  
  208. ofSphere(x1, y1, z, rad);}
  209.  
  210. //--------------------------------------------------------------
  211. void testApp::keyPressed(int key){
  212.  
  213. }
  214.  
  215. //--------------------------------------------------------------
  216. void testApp::keyReleased(int key){
  217.  
  218. }
  219.  
  220. //--------------------------------------------------------------
  221. void testApp::mouseMoved(int x, int y){
  222.  
  223. }
  224.  
  225. //--------------------------------------------------------------
  226. void testApp::mouseDragged(int x, int y, int button){
  227.  
  228. }
  229.  
  230. //--------------------------------------------------------------
  231. void testApp::mousePressed(int x, int y, int button){
  232.  
  233. }
  234.  
  235. //--------------------------------------------------------------
  236. void testApp::mouseReleased(int x, int y, int button){
  237.  
  238. }
  239.  
  240. //--------------------------------------------------------------
  241. void testApp::windowResized(int w, int h){
  242.  
  243. }
  244.  
  245. //--------------------------------------------------------------
  246. void testApp::gotMessage(ofMessage msg){
  247.  
  248. }
  249.  
  250. //--------------------------------------------------------------
  251. void testApp::dragEvent(ofDragInfo dragInfo){
  252.  
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement