Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. #Rakan Nassereddin, Quinn Chrzan, Ben Stewart
  2. #902593694, Insert ID's Here, " "
  3. #We worked on the homework assignment alone, using only this semester's course materials.
  4.  
  5.  
  6. from myro import *
  7. init()
  8.  
  9.  
  10. def record(time):
  11. pictures = []
  12. while timeRemaining(time):
  13. wait(.1)
  14. pictures.append(takePicture())
  15. pictures.append(takePicture())
  16. return pictures
  17.  
  18. def fadetoBlack():
  19. pictures = record(15)
  20. index = 10
  21.  
  22. for pic in pictures:
  23.  
  24. pix = getPixels(pic)
  25.  
  26. for x in pix:
  27. red = getRed(x)
  28. green = getGreen(x)
  29. blue = getBlue(x)
  30. if red <230:
  31. setRed(x, red + index)
  32. if blue < 230:
  33. setBlue(x, blue + index)
  34. if green <230:
  35. setGreen(x, green + index)
  36. index = index +10
  37.  
  38. savePicture(pictures, 'Fade to black.gif')
  39.  
  40.  
  41. def tempoChange(time):
  42. pictures = []
  43. while timeRemaining(time):
  44. wait(.1)
  45. for x in range(5):
  46. pictures.append(takePicture())
  47.  
  48. savePicture(pictures, 'tempo.gif')
  49.  
  50. return pictures
  51.  
  52.  
  53. def seeingRed(time):
  54. pictures = record(time)
  55.  
  56. for pic in pictures:
  57. pix = getPixels(pic)
  58.  
  59. for x in pix:
  60. setRed(x, 255)
  61. return pictures
  62.  
  63. def view360():
  64. pictures = []
  65.  
  66. for seconds in timer(11):
  67. turnLeft(.2,.1)
  68. pictures.append(takePicture())
  69. savePicture(pictures, '360-View.gif')
  70. return pictures
  71.  
  72. def robotZoom():
  73. pictures = []
  74.  
  75. for seconds in timer(10):
  76. forward(.4,.1)
  77. wait(.1)
  78. stop()
  79. pictures.append(takePicture())
  80. savePicture(pictures, 'Robot-Zoom')
  81. return pictures
  82.  
  83.  
  84. def gifitize():
  85. pictures = seeingRed(10)
  86. pics2 = robotZoom
  87. pics3 = view360
  88. savePicture(pictures, 'seeingRed.gif')
  89.  
  90. # EXAMPLE USAGE:
  91. # pics = recordGreenScreen(10,"/path/to/pic.jpg")
  92. # savePicture("/path/to/animated.gif")
  93.  
  94. def recordGreenScreen(time,pic):
  95. pictures = []
  96. pic = makePicture(pic)
  97. while timeRemaining(time):
  98. wait(.5)
  99. pictures.append(takePicture())
  100. processed = [greenScreen(rec,pic,makeColor(66,255,255)) for rec in pictures]
  101. return processed
  102.  
  103.  
  104. # pic1, pic2 are picture resources, colorFilter is the specified color we are filtering for
  105. def greenScreen(pic1,pic2,colorFilter):
  106. r,g,b = getRGB(colorFilter)
  107. for i in range(getWidth(pic1)):
  108. for j in range(getHeight(pic1)):
  109. pixel1 = getPixel(pic1,i,j)
  110. pixel2 = getPixel(pic2,i,j)
  111. diff = math.sqrt((getRed(pixel1)-r)**2 + (getGreen(pixel1)-g)**2 + (getBlue(pixel1)-b)**2)
  112. #print diff
  113. if diff <= 200:
  114. setGreen(pixel1, getGreen(pixel2))
  115. setRed(pixel1, getRed(pixel2))
  116. setBlue(pixel1, getBlue(pixel2))
  117. return pic1
  118.  
  119. #This is all part of one code: Split-Screen.
  120.  
  121. def takePic():
  122. t1 = takePicture()
  123. turnRight(.5, .5)
  124. t2 = takePicture()
  125.  
  126. def splitScreen(t1, t2):
  127. h = getHeight(t1)
  128. w = getWidth(t2)/2
  129. for i in range(w):
  130. for j in range(h):
  131. p = getPixel(t1,i,j)
  132. g = getGreen(p)
  133. r = getRed(p)
  134. b = getBlue(p)
  135. pixel2 = getPixel(t2,i,j)
  136. setGreen(pixel2,g)
  137. setRed(pixel2,r)
  138. setBlue(pixel2,b)
  139. return t2
  140.  
  141. def pictures():
  142. index = 0
  143. l = []
  144. while index <= 9:
  145. t = takePicture()
  146. turnRight(.5,.5)
  147. l.append(t)
  148. index = index + 1
  149. l2 = []
  150. for i in range(0,5):
  151. pic1 = l[i]
  152. pic2 = l[i+5]
  153. newPic = splitScreen(pic1, pic2)
  154. l2.append(newPic)
  155. return l2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement