def main(): stddraw.setCanvasSize(1024, 256) stddraw.setXscale(0, _SAMPLES_PER_REDRAW) stddraw.setYscale(-.75, +.75) stddraw.show(0) # Create keyboardDict, a dictionary relating each keyboard key # to a guitar string. keyboardDict = {} i = 0 for key in _KEYBOARD: factor = 2 ** ((i-24) / 12.0) guitarString = guitarstring.GuitarString(_CONCERT_A * factor) keyboardDict[key] = guitarString i += 1 # pluckedGuitarStrings is the set of all guitar strings that have # been plucked. pluckedGuitarStrings = set() #stddraw.show(0) t = 0 # The main input loop. while True: if stddraw.hasNextKeyTyped(): # Fetch the key that the user just typed. key = stddraw.nextKeyTyped() # Figure out which guitar string to pluck, and pluck it. try: guitarString = keyboardDict[key] guitarString.pluck() pluckedGuitarStrings.add(guitarString) except KeyError: pass # Add up the samples from each plucked guitar string. Also # advance the simulation of each plucked guitar string by # one step. sample = 0.0 for guitarString in pluckedGuitarStrings: sample += guitarString.sample() guitarString.tic() # Play the total. stdaudio.playSample(sample) # Plot stddraw.point(t % _SAMPLES_PER_REDRAW, sample); if (t % _SAMPLES_PER_REDRAW) == (_SAMPLES_PER_REDRAW - 1): stddraw.show(0); stddraw.clear(); t += 1
def main(): stddraw.setCanvasSize(1024, 256) stddraw.setXscale(0, _SAMPLES_PER_REDRAW) stddraw.setYscale(-.75, +.75) stddraw.show(0) # Create keyboardDict, a dictionary relating each keyboard key # to a guitar string. keyboardDict = {} i = 0 for key in _KEYBOARD: factor = 2**((i - 24) / 12.0) guitarString = guitarstring.GuitarString(_CONCERT_A * factor) keyboardDict[key] = guitarString i += 1 # pluckedGuitarStrings is the set of all guitar strings that have # been plucked. pluckedGuitarStrings = set() #stddraw.show(0) t = 0 # The main input loop. while True: if stddraw.hasNextKeyTyped(): # Fetch the key that the user just typed. key = stddraw.nextKeyTyped() # Figure out which guitar string to pluck, and pluck it. try: guitarString = keyboardDict[key] guitarString.pluck() pluckedGuitarStrings.add(guitarString) except KeyError: pass # Add up the samples from each plucked guitar string. Also # advance the simulation of each plucked guitar string by # one step. sample = 0.0 for guitarString in pluckedGuitarStrings: sample += guitarString.sample() guitarString.tic() # Play the total. stdaudio.playSample(sample) # Plot stddraw.point(t % _SAMPLES_PER_REDRAW, sample) if (t % _SAMPLES_PER_REDRAW) == (_SAMPLES_PER_REDRAW - 1): stddraw.show(0) stddraw.clear() t += 1
def main(): # Create keyboardDict, a dictionary relating each keyboard key # to a guitar string. keyboardDict = {} i = 0 for key in _KEYBOARD: factor = 2 ** ((i-24) / 12.0) guitarString = guitarstring.GuitarString(_CONCERT_A * factor) keyboardDict[key] = guitarString i += 1 # pluckedGuitarStrings is the set of all guitar strings that have # been plucked. pluckedGuitarStrings = set() # loopCount is used to control the frequency of calls of # stddraw.show(). loopCount = 1023 # The main input loop. while True: # Call stddraw.show() occasionally to capture keyboard events. if loopCount == 1023: stddraw.show() loopCount = 0 loopCount += 1 if stddraw.hasNextKeyTyped(): # Fetch the key that the user just typed. key = stddraw.nextKeyTyped() # Figure out which guitar string to pluck, and pluck it. try: guitarString = keyboardDict[key] guitarString.pluck() pluckedGuitarStrings.add(guitarString) except KeyError: pass # Add up the samples from each plucked guitar string. Also # advance the simulation of each plucked guitar string by # one step. sample = 0.0 for guitarString in pluckedGuitarStrings: sample += guitarString.sample() guitarString.tic() # Play the total. stdaudio.playSample(sample)
def main(): # Create keyboardDict, a dictionary relating each keyboard key # to a guitar string. keyboardDict = {} i = 0 for key in _KEYBOARD: factor = 2**((i - 24) / 12.0) guitarString = guitarstring.GuitarString(_CONCERT_A * factor) keyboardDict[key] = guitarString i += 1 # pluckedGuitarStrings is the set of all guitar strings that have # been plucked. pluckedGuitarStrings = set() # loopCount is used to control the frequency of calls of # stddraw.show(). loopCount = 1023 # The main input loop. while True: # Call stddraw.show() occasionally to capture keyboard events. if loopCount == 1023: stddraw.show() loopCount = 0 loopCount += 1 if stddraw.hasNextKeyTyped(): # Fetch the key that the user just typed. key = stddraw.nextKeyTyped() # Figure out which guitar string to pluck, and pluck it. try: guitarString = keyboardDict[key] guitarString.pluck() pluckedGuitarStrings.add(guitarString) except KeyError: pass # Add up the samples from each plucked guitar string. Also # advance the simulation of each plucked guitar string by # one step. sample = 0.0 for guitarString in pluckedGuitarStrings: sample += guitarString.sample() guitarString.tic() # Play the total. stdaudio.playSample(sample)
def main(argv): t = int(argv[1]) dist = stdarray.readFloat1D() cx = stdarray.readFloat2D() cy = stdarray.readFloat2D() x = 0.0 y = 0.0 #stddraw.createWindow() for t1 in range(t): r = stdrandom.discrete(dist) x0 = cx[r][0] * x + cx[r][1] * y + cx[r][2] y0 = cy[r][0] * x + cy[r][1] * y + cy[r][2] x = x0 y = y0 stddraw.setPenRadius(0.001) stddraw.point(x, y) stddraw.show() stddraw.wait()
def main(argv): t = int(argv[1]) dist = stdarray.readFloat1D() cx = stdarray.readFloat2D() cy = stdarray.readFloat2D() x = 0.0 y = 0.0 #stddraw.createWindow() for t1 in range(t): r = stdrandom.discrete(dist) x0 = cx[r][0]*x + cx[r][1]*y + cx[r][2] y0 = cy[r][0]*x + cy[r][1]*y + cy[r][2] x = x0 y = y0 stddraw.setPenRadius(0.001) stddraw.point(x, y) stddraw.show() stddraw.wait()
vy = .023 radius = .05 dt = 20 start = time.time() t = 0 while t < 10000: # Update ball position and draw it there. if abs(rx + vx) + radius > 1.0: vx = -vx if abs(ry + vy) + radius > 1.0: vy = -vy rx = rx + vx ry = ry + vy #stddraw.clear() stddraw.setPenColor(stddraw.GRAY) stddraw.filledSquare(0, 0, 1.0) stddraw.setPenColor(stddraw.BLACK) stddraw.filledCircle(rx, ry, radius) #stddraw.sleep(dt) stddraw.show() t += 1 finish = time.time() print finish - start