Last active
October 10, 2015 15:15
-
-
Save rkhapov/096bd24ffb5a2deea8af to your computer and use it in GitHub Desktop.
graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import * | |
from tkinter import * | |
#Парочка математических функций | |
def sqr(a): | |
return a*a | |
def distance(x, y, x1, y1): | |
return sqrt(sqr(x1 - x) + sqr(y1 - y)) | |
try: | |
#Читаем данные из файла | |
f = open("input.txt") | |
prev_x, prev_y, prev_t = list(map(float, f.readline().split())) | |
first_t = prev_t | |
prev_speed = 0 | |
#Подготавливаем окно для рисования | |
window = Tk() | |
painter = Canvas(window, width = 800, height = 600, bg = "white") | |
#Рисуем координатные оси | |
painter.create_line(0, 600 - 2, 800, 600 - 2, width = 2, arrow = LAST) | |
painter.create_line(10, 800, 10, 0, width = 2, arrow = LAST) | |
painter.create_text(770, 590, text = "time") | |
painter.create_text(40, 10, text = "velocity") | |
for s in f.readlines(): | |
x, y, t = list(map(float, s.split())) | |
speed = distance(x, prev_x, y, prev_y) / (t - prev_t) | |
painter.create_line((prev_t - first_t) * 10, 600 - (prev_speed / 100), (t - first_t) * 10, 600 - (speed / 100), width = 1) | |
prev_x, prev_y, prev_t, prev_speed = x, y, t, speed | |
painter.pack() | |
window.mainloop() | |
#Единственная ошибка - ошибка открытия файла, поэтому можно считать, | |
#что если мы поймали исключение - то это 146% ошибка открытия | |
except OSError: | |
print("Cann't open file.data") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment