Guest User

Untitled

a guest
Mar 19th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. public void flipVerticalRectangle(int x, int y, int width, int height)
  2. {
  3. for (int sourceY = y, i = 1; sourceY >= (y - (height-1)/2); sourceY--, i+=2)
  4. {
  5. if (y > 0 && y <= this.getHeight() + height)
  6. {
  7. for (int sourceX = x; sourceX <= (x + (width-1)); sourceX++)
  8. {
  9. if (x + width > 0 && x <= this.getWidth())
  10. {
  11. Pixel sourcePix = this.getPixel(sourceX, sourceY);
  12. Pixel targetPix = this.getPixel(sourceX, sourceY - (height-i));
  13. Color tempcolor = targetPix.getColor();
  14. targetPix.setColor(sourcePix.getColor());
  15. sourcePix.setColor(tempcolor);
  16. }
  17. }
  18. }
  19. }
  20. }
  21.  
  22. /**
  23. * TODO: Add header comment and complete the method
  24. **/
  25. public void flipHorizontalRectangle(int x, int y, int width, int height)
  26. {
  27. // No change if square is completely outside picture
  28. if (!(x + width < 0 || y < 0 || x >= this.getWidth() || y >= this.getHeight() + height))
  29. {
  30. for (int sourceY = y; sourceY >= (y - (height-1)); sourceY--)
  31. {
  32. for (int sourceX = x, i = 1; sourceX <= (x + (width-1)/2); sourceX++, i+=2)
  33. {
  34. Pixel sourcePix = this.getPixel(sourceX, sourceY);
  35. Pixel targetPix = this.getPixel(width + (sourceX-i), sourceY);
  36. Color tempcolor = targetPix.getColor();
  37. targetPix.setColor(sourcePix.getColor());
  38. sourcePix.setColor(tempcolor);
  39. }
  40. }
  41. }
  42. }
  43.  
  44. public void concatenateSound(Sound firstSound, Sound secondSound)
  45. {
  46. int endOfOriginal = this.getLength();
  47. int endOfFirstSound = firstSound.getLength();
  48. int endOfSecondSound = secondSound.getLength();
  49.  
  50. for (int firstSoundi = 0; firstSoundi < endOfFirstSound; firstSoundi++)
  51. {
  52. this.setSampleValueAt(firstSoundi, firstSound.getSampleValueAt(firstSoundi));
  53. }
  54. for (int secondSoundi = endOfFirstSound, secondSoundj = 0; secondSoundj < endOfSecondSound; secondSoundi++, secondSoundj++)
  55. {
  56. this.setSampleValueAt(secondSoundi, secondSound.getSampleValueAt(secondSoundj));
  57. }
  58. for (int endSound = endOfSecondSound; endSound < endOfOriginal; endSound++)
  59. {
  60. this.setSampleValueAt(endSound, 0);
  61. }
  62. }
  63.  
  64.  
  65. public void concatenateSound(Sound firstSound, Sound secondSound, int switchPoint)
  66. {
  67. int endOfOriginal = this.getLength();
  68. int endOfFirstSound = firstSound.getLength();
  69. int endOfSecondSound = secondSound.getLength();
  70.  
  71. for (int index = 0; index < endOfOriginal; index++)
  72. {
  73. if (endOfFirstSound < switchPoint) {
  74. for (int shortFirstSound = 0; shortFirstSound < endOfFirstSound; shortFirstSound++)
  75. {
  76. this.setSampleValueAt(shortFirstSound, firstSound.getSampleValueAt(shortFirstSound));
  77. }
  78. for (int secondSoundA = endOfFirstSound, secondSoundLength = 0; secondSoundA < endOfOriginal && secondSoundLength < endOfSecondSound; secondSoundA++, secondSoundLength++)
  79. {
  80. this.setSampleValueAt(secondSoundA, secondSound.getSampleValueAt(secondSoundLength));
  81. }
  82. }
  83. else if (switchPoint < endOfFirstSound) {
  84. for (int longFirstSound = 0; longFirstSound < switchPoint; longFirstSound++)
  85. {
  86. this.setSampleValueAt(longFirstSound, firstSound.getSampleValueAt(longFirstSound));
  87. }
  88. for (int secondSoundB = switchPoint, secondSoundLength = 0; secondSoundB < (endOfOriginal - 1) && secondSoundLength < endOfSecondSound; secondSoundB++, secondSoundLength++)
  89. {
  90. this.setSampleValueAt(secondSoundB, secondSound.getSampleValueAt(secondSoundLength));
  91. }
  92. }
  93. }
  94. }
Add Comment
Please, Sign In to add comment