/
oscilloscope.py
executable file
·44 lines (35 loc) · 1.09 KB
/
oscilloscope.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#-----------------------------------------------------------------------
# oscilloscope.py
#-----------------------------------------------------------------------
# Simulate the output of an oscilloscope. Assume that the vertical and
# horizontal inputs are sinusoidal. Use these equations:
# x = A sin (wX + phiX)
# y = B sin (wY + phiY)
import stddraw
import sys
import math
stddraw.createWindow()
stddraw.setXscale(-1, +1)
stddraw.setYscale(-1, +1)
stddraw.setPenRadius(0)
A = float(sys.argv[1]) # amplitudes
B = float(sys.argv[2])
wX = float(sys.argv[3]) # angular frequencies
wY = float(sys.argv[4])
phiX = float(sys.argv[5]) # phase factors
phiY = float(sys.argv[6])
# Convert from degrees to radians.
phiY = math.radians(phiX)
phiY = math.radians(phiY)
t = 0.0
while True:
x = A * math.sin(wX * t + phiX)
y = B * math.sin(wY * t + phiY)
stddraw.point(x, y)
stddraw.sleep(10)
stddraw.show()
t += 0.01
#t += 0.0001
#-----------------------------------------------------------------------
# Example execution:
# python oscilloscope.py 1 1 2 3 20 45