mediaComp 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mediaComp/__init__.py ADDED
@@ -0,0 +1,23 @@
1
+ from .core import *
2
+ from mediaComp.models.Config import ConfigManager
3
+
4
+ __all__ = [
5
+ "setColorWrapAround", "getColorWrapAround", "pickAColor", "distance", "makeDarker", "makeLighter", "makeColor",
6
+ "setMediaFolder", "setTestMediaFolder", "getMediaFolder",
7
+ "showMediaFolder", "getShortPath", "setLibFolder", "pickAFile", "pickAFolder",
8
+ "randomPixels", "pictureTool", "pixelsToPicture", "makePicture", "makeEmptyPicture", "getPixels", "getWidth", "getHeight", "show",
9
+ "repaint", "addLine", "addText", "addRect", "addRectFilled", "addOval", "addOvalFilled", "addArc", "addArcFilled",
10
+ "getPixelAt", "setRed", "setGreen", "setBlue", "getRed", "getGreen", "getBlue", "getColor", "setColor", "getX", "getY",
11
+ "writePictureTo", "setAllPixelsToAColor", "copyInto", "duplicatePicture", "cropPicture", "calculateNeededFiller",
12
+ "requestInteger", "requestNumber", "requestIntegerInRange", "requestString", "showWarning", "showInformation", "showError",
13
+ "playMovie", "writeQuicktime", "writeAVI", "makeMovie", "makeMovieFromInitialFile", "addFrameToMovie", "writeFramesToDirectory",
14
+ "samplesToSound", "makeSound", "makeEmptySound", "makeEmptySoundBySeconds", "duplicateSound", "getSamples", "soundTool",
15
+ "play", "blockingPlay", "stopPlaying", "playAtRate", "playAtRateDur", "playInRange", "blockingPlayInRange", "playAtRateInRange",
16
+ "blockingPlayAtRateInRange", "getSamplingRate", "getSampleValueAt", "setSampleValueAt", "setSampleValue",
17
+ "getSampleValue", "getSound", "getNumSamples", "getDuration", "writeSoundTo", "randomSamples", "getIndex",
18
+ "playNote", "turn", "turnRight", "turnToFace", "turnLeft", "forward", "backward", "moveTo", "makeTurtle", "penUp",
19
+ "penDown", "drop", "getXPos", "getYPos", "getHeading", "makeWorld", "getTurtleList", "blue", "red",
20
+ "green", "gray", "darkGray", "lightGray", "yellow", "orange", "pink", "magenta", "cyan"
21
+ ]
22
+
23
+ config = ConfigManager
@@ -0,0 +1,7 @@
1
+ from .color import *
2
+ from .utils import *
3
+ from .image import *
4
+ from .movie import *
5
+ from .sound import *
6
+ from .turtle import *
7
+ from .world import *
@@ -0,0 +1,50 @@
1
+ from ..models.PixelColor import Pixel, Color
2
+
3
+ black = Color(0, 0, 0)
4
+ white = Color(255, 255, 255)
5
+ blue = Color(0, 0, 255)
6
+ red = Color(255, 0, 0)
7
+ green = Color(0, 255, 0)
8
+ gray = Color(128, 128, 128)
9
+ darkGray = Color(64, 64, 64)
10
+ lightGray = Color(192, 192, 192)
11
+ yellow = Color(255, 255, 0)
12
+ orange = Color(255, 200, 0)
13
+ pink = Color(255, 175, 175)
14
+ magenta = Color(255, 0, 255)
15
+ cyan = Color(0, 255, 255)
16
+
17
+ def setColorWrapAround(setting):
18
+ Pixel.setWrapLevels(bool(setting))
19
+
20
+ def getColorWrapAround():
21
+ return Pixel.getWrapLevels()
22
+
23
+ def pickAColor():
24
+ return Color.pickAColor()
25
+
26
+ def distance(c1, c2):
27
+ if not isinstance(c1, Color):
28
+ print("distance(c1,c2): First input is not a color")
29
+ raise ValueError
30
+ if not isinstance(c2, Color):
31
+ print("distance(c1,c2): Second input is not a color")
32
+ raise ValueError
33
+ return c1.distance(c2)
34
+
35
+ def makeDarker(color):
36
+ if not isinstance(color, Color):
37
+ print("makeDarker(color): Input is not a color")
38
+ raise ValueError
39
+ return Color(color.makeDarker())
40
+
41
+ def makeLighter(color):
42
+ if not isinstance(color, Color):
43
+ print("makeLighter(color): Input is not a color")
44
+ raise ValueError
45
+ return Color(color.makeLighter())
46
+
47
+
48
+ def makeColor(red, green=None, blue=None):
49
+ return Color(red, green, blue)
50
+
@@ -0,0 +1,310 @@
1
+ from ..models.Picture import Picture
2
+ from ..models.PixelColor import Pixel, Color
3
+ import os, random
4
+
5
+ black = Color(0, 0, 0)
6
+ white = Color(255, 255, 255)
7
+
8
+ def randomPixels(somePic, number):
9
+ pixelList = []
10
+ pixels = getPixels(somePic)
11
+ for count in range(number):
12
+ pixelList.append(random.choice(pixels))
13
+ if(isinstance(pixelsToPicture(pixelList), Picture)):
14
+ pictureTool(pixelsToPicture(pixelList))
15
+
16
+ def pictureTool(picture):
17
+ if isinstance(picture, Picture):
18
+ picture.pictureTool()
19
+ else:
20
+ print("openPicture(picture): Input is not a picture.")
21
+ raise ValueError
22
+
23
+ def pixelsToPicture(pixels, defaultColor=white, maxX=100, maxY=100):
24
+ maxX = max([getX(p) for p in pixels])
25
+ maxY = max([getY(p) for p in pixels])
26
+ newpic = makeEmptyPicture(maxX + 1, maxY + 1, defaultColor)
27
+ for pixel in pixels:
28
+ x = getX(pixel)
29
+ y = getY(pixel)
30
+ setColor(getPixelAt(newpic, x, y), getColor(pixel))
31
+ return newpic
32
+
33
+
34
+ def makePicture(filename, defaultColor=white):
35
+ global mediaFolder
36
+ if not isinstance(filename, str):
37
+ return pixelsToPicture(filename, defaultColor=defaultColor)
38
+ if not os.path.isabs(filename):
39
+ filename = mediaFolder + filename
40
+ if not os.path.isfile(filename):
41
+ print("makePicture(filename): There is no file at " + filename)
42
+ raise ValueError
43
+ picture = Picture()
44
+ picture.loadOrFail(filename)
45
+ return picture
46
+
47
+
48
+ def makeEmptyPicture(width, height, acolor=white):
49
+ if width > 10000 or height > 10000:
50
+ print("makeEmptyPicture(width, height[, acolor]): height and width must be less than 10000 each")
51
+ raise ValueError
52
+ if width <= 0 or height <= 0:
53
+ print("makeEmptyPicture(width, height[, acolor]): height and width must be greater than 0 each")
54
+ raise ValueError
55
+ picture = Picture(width, height, acolor)
56
+ return picture
57
+
58
+ def getPixels(picture):
59
+ if not isinstance(picture, Picture):
60
+ print("getPixels(picture): Input is not a picture")
61
+ raise ValueError
62
+ return picture.getPixels()
63
+
64
+
65
+ def getWidth(picture):
66
+ if not isinstance(picture, Picture):
67
+ print("getWidth(picture): Input is not a picture")
68
+ raise ValueError
69
+ return picture.getWidth()
70
+
71
+
72
+ def getHeight(picture):
73
+ if not isinstance(picture, Picture):
74
+ print("getHeight(picture): Input is not a picture")
75
+ raise ValueError
76
+ return picture.getHeight()
77
+
78
+ def show(picture, title=None):
79
+ if not isinstance(picture, Picture):
80
+ print("show(picture): Input is not a picture")
81
+ raise ValueError
82
+ picture.show()
83
+
84
+ def repaint(picture):
85
+ if not isinstance(picture, Picture):
86
+ print("repaint(picture): Input is not a picture")
87
+ raise ValueError
88
+ picture.repaint()
89
+
90
+ def addLine(picture, x1, y1, x2, y2, acolor=black):
91
+ if not isinstance(picture, Picture):
92
+ print("addLine(picture, x1, y1, x2, y2[, color]): First input is not a picture")
93
+ raise ValueError
94
+ if not isinstance(acolor, Color):
95
+ print("addLine(picture, x1, y1, x2, y2[, color]): Last input is not a color")
96
+ raise ValueError
97
+ picture.addLine(acolor, x1, y1, x2, y2)
98
+
99
+
100
+ def addText(picture, x, y, string, acolor=black):
101
+ if not isinstance(picture, Picture):
102
+ print("addText(picture, x, y, string[, color]): First input is not a picture")
103
+ raise ValueError
104
+ if not isinstance(acolor, Color):
105
+ print("addText(picture, x, y, string[, color]): Last input is not a color")
106
+ raise ValueError
107
+
108
+ picture.addText(acolor, x, y, string)
109
+
110
+
111
+ def addRect(picture, x, y, w, h, acolor=black):
112
+ if not isinstance(picture, Picture):
113
+ print("addRect(picture, x, y, w, h[, color]): First input is not a picture")
114
+ raise ValueError
115
+ if not isinstance(acolor, Color):
116
+ print("addRect(picture, x, y, w, h[, color]): Last input is not a color")
117
+ raise ValueError
118
+ picture.addRect(acolor, x, y, w, h)
119
+
120
+
121
+ def addRectFilled(picture, x, y, w, h, acolor=black):
122
+ if not isinstance(picture, Picture):
123
+ print("addRectFilled(picture, x, y, w, h[, color]): First input is not a picture")
124
+ raise ValueError
125
+ if not isinstance(acolor, Color):
126
+ print("addRectFilled(picture, x, y, w, h[, color]): Last input is not a color")
127
+ raise ValueError
128
+ picture.addRectFilled(acolor, x, y, w, h)
129
+
130
+
131
+ def addOval(picture, x, y, w, h, acolor=black):
132
+ if not isinstance(picture, Picture):
133
+ print("addOval(picture, x, y, w, h[, color]): First input is not a picture")
134
+ raise ValueError
135
+ if not isinstance(acolor, Color):
136
+ print("addOval(picture, x, y, w, h[, color]): Last input is not a color")
137
+ raise ValueError
138
+ picture.addOval(acolor, x, y, w, h)
139
+
140
+
141
+ def addOvalFilled(picture, x, y, w, h, acolor=black):
142
+ if not isinstance(picture, Picture):
143
+ print("addOvalFilled(picture, x, y, w, h[, color]): First input is not a picture")
144
+ raise ValueError
145
+ if not isinstance(acolor, Color):
146
+ print("addOvalFilled(picture, x, y, w, h[, color]): Last input is not a color")
147
+ raise ValueError
148
+ picture.addOvalFilled(acolor, x, y, w, h)
149
+
150
+
151
+ def addArc(picture, x, y, w, h, start, angle, acolor=black):
152
+ if not isinstance(picture, Picture):
153
+ print("addArc(picture, x, y, w, h, start, angle[, color]): First input is not a picture")
154
+ raise ValueError
155
+ if not isinstance(acolor, Color):
156
+ print("addArc(picture, x, y, w, h, start, angle[, color]): Last input is not a color")
157
+ raise ValueError
158
+ picture.addArc(acolor, x, y, w, h, start, angle)
159
+
160
+
161
+ def addArcFilled(picture, x, y, w, h, start, angle, acolor=black):
162
+ if not isinstance(picture, Picture):
163
+ print("addArcFilled(picture, x, y, w, h[, color]): First First input is not a picture")
164
+ raise ValueError
165
+ if not isinstance(acolor, Color):
166
+ print("addArcFilled(picture, x, y, w, h, start, angle[, color]): Last input is not a color")
167
+ raise ValueError
168
+ picture.addArcFilled(acolor, x, y, w, h, start, angle)
169
+
170
+ def getPixelAt(picture, x, y):
171
+ if not isinstance(picture, Picture):
172
+ print("getPixel(picture,x,y): First input is not a picture")
173
+ raise ValueError
174
+ if (x < Picture._PictureIndexOffset) or (x > getWidth(picture) - 1 + Picture._PictureIndexOffset):
175
+ print("getPixel(picture,x,y): x (= {}) is less than {} or bigger than the width (= {})".format(x, Picture._PictureIndexOffset, getWidth(picture) - 1 + Picture._PictureIndexOffset))
176
+ raise ValueError
177
+ if (y < Picture._PictureIndexOffset) or (y > getHeight(picture) - 1 + Picture._PictureIndexOffset):
178
+ print("getPixel(picture,x,y): y (= {}) is less than {} or bigger than the height (= {})".format(y, Picture._PictureIndexOffset, getHeight(picture) - 1 + Picture._PictureIndexOffset))
179
+ raise ValueError
180
+
181
+ return picture.getPixel(x - Picture._PictureIndexOffset, y - Picture._PictureIndexOffset)
182
+
183
+
184
+ def setRed(pixel, value):
185
+ value = Pixel.correctLevel(value)
186
+ if not isinstance(pixel, Pixel):
187
+ print("setRed(pixel,value): Input is not a pixel")
188
+ raise ValueError
189
+ pixel.setRed(value)
190
+
191
+
192
+ def getRed(pixel):
193
+ if not isinstance(pixel, Pixel):
194
+ print("getRed(pixel): Input is not a pixel")
195
+ raise ValueError
196
+ return pixel.getRed()
197
+
198
+
199
+ def setBlue(pixel, value):
200
+ value = Pixel.correctLevel(value)
201
+ if not isinstance(pixel, Pixel):
202
+ print("setBlue(pixel,value): Input is not a pixel")
203
+ raise ValueError
204
+ pixel.setBlue(value)
205
+
206
+
207
+ def getBlue(pixel):
208
+ if not isinstance(pixel, Pixel):
209
+ print("getBlue(pixel): Input is not a pixel")
210
+ raise ValueError
211
+ return pixel.getBlue()
212
+
213
+
214
+ def setGreen(pixel, value):
215
+ value = Pixel.correctLevel(value)
216
+ if not isinstance(pixel, Pixel):
217
+ print("setGreen(pixel,value): Input is not a pixel")
218
+ raise ValueError
219
+ pixel.setGreen(value)
220
+
221
+
222
+ def getGreen(pixel):
223
+ if not isinstance(pixel, Pixel):
224
+ print("getGreen(pixel): Input is not a pixel")
225
+ raise ValueError
226
+ return pixel.getGreen()
227
+
228
+
229
+ def getColor(pixel):
230
+ if not isinstance(pixel, Pixel):
231
+ print("getColor(pixel): Input is not a pixel")
232
+ raise ValueError
233
+ return Color(pixel.getColor())
234
+
235
+
236
+ def setColor(pixel, color):
237
+ if not isinstance(pixel, Pixel):
238
+ print("setColor(pixel,color): First input is not a pixel")
239
+ raise ValueError
240
+ if not isinstance(color, Color):
241
+ print("setColor(pixel,color): Second input is not a color")
242
+ raise ValueError
243
+ pixel.setColor(color)
244
+
245
+ def getX(pixel):
246
+ if not isinstance(pixel, Pixel):
247
+ print("getX(pixel): Input is not a pixel")
248
+ raise ValueError
249
+ return pixel.getX() + Picture._PictureIndexOffset
250
+
251
+
252
+ def getY(pixel):
253
+ if not isinstance(pixel, Pixel):
254
+ print("getY(pixel): Input is not a pixel")
255
+ raise ValueError
256
+ return pixel.getY() + Picture._PictureIndexOffset
257
+
258
+ def writePictureTo(picture, filename):
259
+ global mediaFolder
260
+ if not os.path.isabs(filename):
261
+ filename = mediaFolder + filename
262
+ if not isinstance(picture, Picture):
263
+ print("writePictureTo(picture,filename): First input is not a picture")
264
+ raise ValueError
265
+ picture.writeOrFail(filename)
266
+
267
+ def setAllPixelsToAColor(picture, color):
268
+ if not isinstance(picture, Picture):
269
+ print("setAllPixelsToAColor(picture,color): First input is not a picture")
270
+ raise ValueError
271
+ if not isinstance(color, Color):
272
+ print("setAllPixelsToAColor(picture,color): Second input is not a color")
273
+ raise ValueError
274
+ picture.setAllPixelsToAColor(color)
275
+
276
+ def copyInto(origPict, destPict, upperLeftX, upperLeftY):
277
+ if not isinstance(origPict, Picture):
278
+ print("copyInto(origPict, destPict, upperLeftX, upperLeftY): First parameter is not a picture")
279
+ raise ValueError
280
+ if not isinstance(destPict, Picture):
281
+ print("copyInto(origPict, destPict, upperLeftX, upperLeftY): Second parameter is not a picture")
282
+ raise ValueError
283
+ if upperLeftX < 0 or upperLeftX > getWidth(destPict):
284
+ print("copyInto(origPict, destPict, upperLeftX, upperLeftY): upperLeftX must be within the destPict")
285
+ raise ValueError
286
+ if upperLeftY < 0 or upperLeftY > getHeight(destPict):
287
+ print("copyInto(origPict, destPict, upperLeftX, upperLeftY): upperLeftY must be within the destPict")
288
+ raise ValueError
289
+ return origPict.copyInto(destPict, upperLeftX-1, upperLeftY-1)
290
+
291
+
292
+ def duplicatePicture(picture):
293
+ """returns a copy of the picture"""
294
+ if not isinstance(picture, Picture):
295
+ print("duplicatePicture(picture): Input is not a picture")
296
+ raise ValueError
297
+ return Picture(picture)
298
+
299
+ def cropPicture(picture, upperLeftX, upperLeftY, width, height):
300
+ if not isinstance(picture, Picture):
301
+ print("crop(picture, upperLeftX, upperLeftY, width, height): First parameter is not a picture")
302
+ raise ValueError
303
+ if upperLeftX < 1 or upperLeftX > getWidth(picture):
304
+ print("crop(picture, upperLeftX, upperLeftY, width, height): upperLeftX must be within the picture")
305
+ raise ValueError
306
+ if upperLeftY < 1 or upperLeftY > getHeight(picture):
307
+ print("crop(picture, upperLeftX, upperLeftY, width, height): upperLeftY must be within the picture")
308
+ raise ValueError
309
+ return picture.crop(upperLeftX-1, upperLeftY-1, width, height)
310
+
@@ -0,0 +1,83 @@
1
+ from ..models.Movie import Movie
2
+ import os
3
+
4
+
5
+ def playMovie(movie):
6
+ if isinstance(movie, Movie):
7
+ movie.play()
8
+ else:
9
+ print("playMovie( movie ): Input is not a Movie")
10
+ raise ValueError
11
+
12
+
13
+ def writeQuicktime(movie, destPath, framesPerSec=16):
14
+ if not (isinstance(movie, Movie)):
15
+ print("writeQuicktime(movie, path[, framesPerSec]): First input is not a Movie")
16
+ raise ValueError
17
+ if framesPerSec <= 0:
18
+ print("writeQuicktime(movie, path[, framesPerSec]): Frame rate must be a positive number")
19
+ raise ValueError
20
+ movie.writeQuicktime(destPath, framesPerSec)
21
+
22
+
23
+ def writeAVI(movie, destPath, framesPerSec=16):
24
+ if not (isinstance(movie, Movie)):
25
+ print("writeAVI(movie, path[, framesPerSec]): First input is not a Movie")
26
+ raise ValueError
27
+ if framesPerSec <= 0:
28
+ print("writeAVI(movie, path[, framesPerSec]): Frame rate must be a positive number")
29
+ raise ValueError
30
+ movie.writeAVI(destPath, framesPerSec)
31
+
32
+
33
+ def makeMovie():
34
+ return Movie()
35
+
36
+
37
+ def makeMovieFromInitialFile(filename):
38
+ import re
39
+ movie = Movie()
40
+ global mediaFolder
41
+ filename = filename.replace('/', os.sep)
42
+ sep_location = filename.rfind(os.sep)
43
+ if(-1 == sep_location):
44
+ filename = mediaFolder + filename
45
+
46
+ movie.directory = filename[:(filename.rfind(os.sep))]
47
+ movie.init_file = filename[(filename.rfind(os.sep)) + 1:]
48
+ regex = re.compile('[0-9]+')
49
+ file_regex = regex.sub('.*', movie.init_file)
50
+
51
+ for item in sorted(os.listdir(movie.directory)):
52
+ if re.match(file_regex, item):
53
+ movie.addFrame(movie.directory + os.sep + item)
54
+
55
+ return movie
56
+
57
+
58
+ def addFrameToMovie(a, b):
59
+ frame = None
60
+ movie = None
61
+ if a.__class__ == Movie:
62
+ movie = a
63
+ frame = b
64
+ else:
65
+ movie = b
66
+ frame = a
67
+
68
+ if not (isinstance(movie, Movie) and isinstance(frame, str)):
69
+ print("addFrameToMovie(frame, movie): frame is not a string or movie is not a Movie object")
70
+ raise ValueError
71
+
72
+ movie.addFrame(frame)
73
+
74
+
75
+ def writeFramesToDirectory(movie, directory=None):
76
+ if not isinstance(movie, Movie):
77
+ print("writeFramesToDirectory(movie[, directory]): movie is not a Movie object")
78
+ raise ValueError
79
+
80
+ if directory == None:
81
+ directory = user.home
82
+
83
+ movie.writeFramesToDirectory(directory)