New file |
| | |
| | | #! /usr/bin/env python |
| | | |
| | | from typing import Final |
| | | import numpy as np |
| | | from numpy import pi |
| | | import matplotlib.pyplot as plt |
| | | |
| | | |
| | | amplitude: tuple[float, float] = (1, 1) |
| | | # frequent |
| | | omega: tuple[float, float] = (-1, -2) |
| | | # phase |
| | | phi: tuple[float, float] = (pi/2, 3*pi/4) |
| | | |
| | | N: Final[int] = 100 |
| | | T = np.linspace(0, 2*pi, num=N) |
| | | x = amplitude[0] * np.cos(omega[0]*T + phi[0]) |
| | | y = amplitude[1] * np.cos(omega[1]*T + phi[1]) |
| | | |
| | | # plot |
| | | fig, ax = plt.subplots() |
| | | ax.plot(x, y, linewidth=2.0) |
| | | |
| | | plt.show() |
| | | |
New file |
| | |
| | | #! /usr/bin/env python |
| | | |
| | | from typing import Final |
| | | from math import pi, cos |
| | | import turtle |
| | | |
| | | amplitude: tuple[float, float] = (1, 1) |
| | | # frequent |
| | | omega: tuple[float, float] = (-1, -2) |
| | | # phase |
| | | phi: tuple[float, float] = (pi/2, 3*pi/4) |
| | | |
| | | # Diskretisieren |
| | | N: Final[int] = 360 |
| | | step = (2*pi) / N |
| | | T = [k * step for k in range(N)] |
| | | points = [( |
| | | amplitude[0] * cos(omega[0]*t + phi[0]), |
| | | amplitude[1] * cos(omega[1]*t + phi[1]) |
| | | ) for t in T |
| | | ] |
| | | |
| | | # Plot with turtle |
| | | (canvaswidth, canvasheight) = turtle.screensize() |
| | | point_size = 3 |
| | | # scale up |
| | | x_factor = (canvaswidth / 2) / amplitude[0] |
| | | y_factor = (canvasheight / 2) / amplitude[1] |
| | | print(x_factor, y_factor) |
| | | # as fast as possible |
| | | turtle.speed(0) |
| | | turtle.pendown() |
| | | for p in points: |
| | | x = x_factor * p[0] |
| | | y = y_factor * p[1] |
| | | turtle.teleport(x, y) |
| | | turtle.dot(point_size) |
| | | |
| | | turtle.done() |