Skip to content

Instantly share code, notes, and snippets.

@wmalarski
Created March 21, 2017 20:37
Show Gist options
  • Save wmalarski/a09d3794c68b9bf79de635519d64906e to your computer and use it in GitHub Desktop.
Save wmalarski/a09d3794c68b9bf79de635519d64906e to your computer and use it in GitHub Desktop.
VPython Lab3 Exercise3
from __future__ import division
import math
def func(x):
return 50 * math.sin(x)
x_args = [(2 * x * math.pi)/50 for x in range(51)]
y_args = [func(x) for x in x_args]
y_min, y_max = min(y_args), max(y_args)
y_lines = [y for y in range(25, -25, -1)]
scale = 50/(y_max - y_min)
def symbol(y, y_line):
ys = y * scale
if ys < y_line < 0:
return "-"
elif ys > y_line > 0:
return "+"
elif int(ys) == 0 and y_line == 0:
return "0"
else:
return " "
with open("file2.txt", "w") as file_data:
points = [[symbol(y, y_line) for y in y_args] for y_line in y_lines]
lines = ["".join(l) for l in points]
file_data.write("\n".join(lines))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment