コード例 #1
0
def test_class_rect():
    r1 = Rect(10, 10, 50, 50)
    r2 = eval(repr(r1))
    print(r1, str(r1.area()), sep=':')
    print(r2, str(r2.area()), sep=':')
    r1.draw()
    r2.draw()
コード例 #2
0
ファイル: reconstructPickle.py プロジェクト: tgrossb/Tingley
def main():
    # First thing is to read the source image and grayscale it
    pickleFile = sys.argv[1]

    with open(pickleFile, 'rb') as file:
        rawImg, scaleFactor, rangedNotes = pickle.load(file)

    if scaleFactor < 1.0:
        img = cv2.resize(rawImg,
                         None,
                         fx=scaleFactor,
                         fy=scaleFactor,
                         interpolation=cv2.INTER_CUBIC)
    else:
        img = rawImg

    lniName = "Labeled notes"
    noteImg = img.copy()
    drawParams = DrawParams()
    for note in rangedNotes:
        rect = Rect(note.rect.x, note.rect.y, note.rect.w, note.rect.h,
                    str(note.noteLine) + " " + str(note.duration))
        rect.draw(noteImg, drawParams, lniName, allInfo=False)
    cv2.namedWindow(lniName)
    cv2.setMouseCallback(lniName, Rect.onClick, lniName)
    cv2.imshow(lniName, noteImg)

    print("\t\tPress space to continue...")
    while True:
        if cv2.waitKey(30) == 32:
            break

    cv2.destroyAllWindows()
コード例 #3
0
ファイル: paint.py プロジェクト: ydhwa/python_lectures
def test_class_rect():
    r1 = Rect(10, 10, 50, 50)
    r2 = eval(repr(r1))

    print(r1, str(r1.area()), sep=':')
    print(r2, str(r2.area()), sep=':')

    r1.draw()
    r2.draw()

    # 비교 연산자 오버로딩
    print(Rect(10, 20) == Rect(20, 10))
    print(Rect(10, 10) > Rect(10, 5))
    print(Rect(10, 20) < Rect(20, 10))
コード例 #4
0
ファイル: playPiece.py プロジェクト: tgrossb/Tingley
def main():
	# First thing is to read the source image and grayscale it
	pickleFile = sys.argv[1]

	with open(pickleFile, 'rb') as file:
		rawImg, scaleFactor, rangedNotes = pickle.load(file)

	if scaleFactor < 1.0:
		img = cv2.resize(rawImg, None, fx = scaleFactor, fy = scaleFactor, interpolation = cv2.INTER_CUBIC)
	else:
		img = rawImg

	lniName = "Labeled notes"
	noteImg = img.copy()
	drawParams = DrawParams()
	for note in rangedNotes:
		rect = Rect(note.rect.x, note.rect.y, note.rect.w, note.rect.h, str(note.noteLine) + " " + str(note.duration))
		rect.draw(noteImg, drawParams, lniName, allInfo = False)
	cv2.namedWindow(lniName)
	cv2.setMouseCallback(lniName, Rect.onClick, lniName)
	cv2.imshow(lniName, noteImg)

	print("\t\tPress space to continue...")
	while True:
		if cv2.waitKey(30) == 32:
			break
	cv2.destroyAllWindows()

	bpm = None
	while bpm is None:
		bpm = input("How many beats per minute should this be played at (ex. 90)?  ")
		try:
			bpm = int(bpm)
			if bpm <= 0:
				bpm = None
		except ValueError:
			print("Error: '" + str(bpm) + " is not a valid integer greater than 0")
			bpm = None

	print("Building full waveform")
	msPerBar = 60000.0 / bpm * 4.0
	waveform = None
	for note in rangedNotes:
		# Open the appropriate waveform
		song = AudioSegment.from_wav("sounds/" + str(note.midi) + ".wav")
		msDuration = int(msPerBar / note.duration)
		if msDuration >= len(song):
			print("Error: BPM too low, the samples aren't long enough")
			sys.exit(0)
		sub = song[:msDuration]
		if waveform is None:
			waveform = sub
		else:
			waveform = waveform.append(sub)
	wavFileName = pickleFile[:pickleFile.rindex(".")] + ".wav"
	waveform.export(wavFileName, format = "wav")
	print("Exported concatenative waveform to '" + wavFileName + "'")

	print("Running WaveNet with the generated waveform as a seed")
	dir = pickleFile[:pickleFile.rindex("/")]
	os.system('nsynth_generate --checkpoint_path=checkpoint/model.ckpt-200000 --source_path=' + wavFileName  + ' --save_path=' + dir + ' --batch_size=4')
コード例 #5
0
ファイル: simulation.py プロジェクト: eporat/Project-BBRA
class Simulation:
    def __init__(self, width, height, camera, draw=True):
        self.width = width
        self.height = height
        self.draw = draw
        self.camera = camera

        if self.draw:
            pygame.init()
            self.screen = pygame.display.set_mode((width, height))
            pygame.display.set_caption("Simulation")
        self.reset()

    def reset(self):
        self.animating = False
        if self.draw:
            self.clock = pygame.time.Clock()

        self.table  = Rect(50, 50, self.width-50, self.height-50)
        self.center_y = (self.table.y1 + self.table.y2) / 2
        self.puck = Puck(self.width/2, 0.75 * self.height, 20, pygame.Color('red'))
        self.striker = Striker(self.width/2, 0.25 * self.height, 40, pygame.Color('blue'))
        self.collide_rect = self.table.collide_rect(self.puck)

    def handle_events(self):
        if self.draw:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.done = True
                # if event.type == pygame.KEYDOWN:
                #     if event.key == 32:
                #         self.animating = True

    def run(self, iterations=1):
        self.done = False

        for _ in range(iterations):
            if self.done:
                break

            self.handle_events()
            if self.draw:
                self.screen.fill(pygame.Color('white'))
                self.table.draw(self.screen)

            self.puck.vel = self.camera.puck['pos'] - self.puck.pos
            self.puck.pos = self.camera.puck['pos']
            print(self.puck.vel)
            self.striker.pos = self.camera.striker['pos']
            self.table = Rect(self.camera.table['min_x'], self.camera.table['min_y'],
                                self.camera.table['max_x'], self.camera.table['max_y'])
            self.puck.update(self)
            #self.striker.update(self)

            if self.draw:
                pygame.display.flip()

        return self.striker.vel

    def quit(self):
        if self.draw:
            pygame.quit()