Projektordner für das Team Deutsches Museum (FORUM).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

drawableImage.cpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #include "drawableImage.h"
  2. #include "images.h"
  3. //--------------------------------------------------------------
  4. DrawableImage::DrawableImage(string imageName, float sceneSizeX, float sceneSizeY) {
  5. //Color for symbol
  6. redImageColor = 121;
  7. greenImageColor = 205;
  8. blueImageColor = 205;
  9. pastMiddle = true;
  10. fileImageHex.loadImage("Hexagon.png");
  11. imageToDraw.loadImage(imageName);
  12. fileImageHex = changeImageColor(fileImageHex, redImageColor, greenImageColor, blueImageColor);
  13. imageToDraw = changeImageColor(imageToDraw, redImageColor, greenImageColor, blueImageColor);
  14. xToMoveInCloud = ofRandom(1, 4);
  15. yToMoveIntoCloud = 0;
  16. ticksToMovePictureToRight = 150;
  17. counterToMovePictureToRight = 0;
  18. newMaxHeight = sceneSizeY - imageToDraw.getHeight() - 3;
  19. imageHeight = imageToDraw.getHeight();
  20. maxYpositionForPicture = setMaxHeightPosition(sceneSizeY);
  21. }
  22. //--------------------------------------------------------------
  23. DrawableImage::~DrawableImage() {
  24. }
  25. //--------------------------------------------------------------
  26. void DrawableImage::updateImage(float sceneSizeX, float sceneSizeY) {
  27. if (cloudAttractorIsSet) {
  28. doMovementOfImageAtCloud(maxYpositionForPicture, sceneSizeX, sceneSizeY);
  29. }
  30. else if (symbolAttractorIsSet) {
  31. drawImage(sceneSizeX, sceneSizeY);
  32. }
  33. }
  34. //--------------------------------------------------------------
  35. void DrawableImage::drawImage(float sceneSizeX, float sceneSizeY)
  36. {
  37. yToMoveIntoCloud = 0;
  38. xToMoveInCloud = 0;
  39. counterToMovePictureToRight = 0;
  40. imageToDraw.draw((sceneSizeX / 2 - imageToDraw.getWidth() / 2), (sceneSizeY - imageToDraw.getHeight() - 5)); //Symbol at bottom
  41. fileImageHex.draw((sceneSizeX / 2 - imageToDraw.getWidth() / 2), (sceneSizeY - imageToDraw.getHeight() - 5)); //Hexagon at bottom
  42. }
  43. //--------------------------------------------------------------
  44. void DrawableImage::doMovementOfImageAtCloud(int maxYpositionForPicture, float sceneSizeX, float sceneSizeY)
  45. {
  46. if (yToMoveIntoCloud <= maxYpositionForPicture) { //y-Movement into cloud
  47. yToMoveIntoCloud += 3;
  48. }
  49. else if (counterToMovePictureToRight < ticksToMovePictureToRight) {
  50. counterToMovePictureToRight++;
  51. }
  52. else { //x-Movement in cloud
  53. if (pastMiddle) { //from the middle to right: midpoint + x and x gets increased til its Scenesize
  54. xToMoveInCloud += 3;
  55. }
  56. else { //From left to the middle: midpoint - x decreased til x is 0 again
  57. xToMoveInCloud -= 3;
  58. }
  59. }
  60. if (pastMiddle && xToMoveInCloud >= sceneSizeX / 2 + imageToDraw.getWidth()) { //Left from middle
  61. pastMiddle = false;
  62. }
  63. if (!pastMiddle && xToMoveInCloud <= 0) { //Rigth from middle
  64. pastMiddle = true;
  65. }
  66. imageToDraw.draw(getImagePosX(sceneSizeX), getImagePosY(sceneSizeY));
  67. fileImageHex.draw(getImagePosX(sceneSizeX), getImagePosY(sceneSizeY));
  68. }
  69. int DrawableImage::setMaxHeightPosition(float sceneSizeY) // Array for max y-values (so that height of the hexagons fits together and can hook into one another in honeycomb structure)
  70. {
  71. for (float i = 0; i <= 4; i++) { //alculate the max y-values
  72. newMaxHeight -= imageHeight / 2;
  73. maxHeightPositions.push_back(newMaxHeight);
  74. }
  75. int rgen = ofRandom(0, 4);
  76. return (int)maxHeightPositions.at(rgen); //random array position to choose random y-position
  77. }
  78. //--------------------------------------------------------------
  79. bool DrawableImage::imageIsOnTop(float sceneSizeY) { //see if symbol and particles reached cloud
  80. return yToMoveIntoCloud >= maxYpositionForPicture;
  81. }
  82. //--------------------------------------------------------------
  83. ofImage DrawableImage::changeImageColor(ofImage imageToDraw, int r, int g, int b) { //Processing the color information of the individual image pixels
  84. int threshold = 1;
  85. int picWidth = imageToDraw.getWidth();
  86. int picHeight = imageToDraw.getHeight();
  87. for (int x = 0; x < picWidth; x++) { //go through all pixel and set new rgb-values
  88. for (int y = 0; y < picHeight; y++)
  89. {
  90. int index = (x + y * picWidth) * 4;
  91. if (imageToDraw.getPixelsRef()[index + 3] >= threshold) {
  92. imageToDraw.getPixelsRef()[index] = r;
  93. imageToDraw.getPixelsRef()[index + 1] = g;
  94. imageToDraw.getPixelsRef()[index + 2] = b;
  95. }
  96. }
  97. }
  98. ofSetColor(255, 255, 255); //set color to white again so the colors don't distort themself
  99. imageToDraw.update();
  100. return imageToDraw;
  101. }
  102. //--------------------------------------------------------------
  103. int DrawableImage::getHeight() {
  104. return imageToDraw.getHeight();
  105. }
  106. //--------------------------------------------------------------
  107. int DrawableImage::getWidth() {
  108. return imageToDraw.getWidth();
  109. }
  110. //--------------------------------------------------------------
  111. int DrawableImage::getMaxHeight() {
  112. return maxYpositionForPicture;
  113. }
  114. //--------------------------------------------------------------
  115. float DrawableImage::getImagePosX(float sceneSizeX) {
  116. if (pastMiddle)
  117. return (sceneSizeX / 2 - imageToDraw.getWidth() / 2) + xToMoveInCloud;
  118. else
  119. return (sceneSizeX / 2 - imageToDraw.getWidth() / 2) - xToMoveInCloud;
  120. }
  121. //--------------------------------------------------------------
  122. float DrawableImage::getImagePosY(float sceneSizeY) {
  123. return (sceneSizeY - imageToDraw.getHeight() - 5) - yToMoveIntoCloud;
  124. }