-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtg.py
93 lines (81 loc) · 3.06 KB
/
tg.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# --- TeenyGraph (tg) --- By Vinícius Pavão - VP1147 --- #
# --- November 2019 --- #
import json
import graphics as gfx
from random import randint
# Setting colors
#Color1 = [255,255,255]
#Color2 = [40,40,40]
# Global variables
global Mkrs
Mkrs = 0
def theme(file):
global Color1 # Background Color
global Color2 # Axis Color
global Color3 # Grid Color
global Color4 # Plot Color
theme_file = json.load(open(file))
Color1 = theme_file.get("Color1")
Color2 = theme_file.get("Color2")
Color3 = theme_file.get("Color3")
Color4 = theme_file.get("Color4")
def plot(Fx):
r,g,b = Color4[0], Color4[1], Color4[2]
Count = ((Sx/2)*-1)*Factor; mc = 0
for i in range (1,Sx):
try:
if Sx*-1 < (Sx/2)-Fx(Count)/Factor < Sx:
Actual = Fx(Count)/Factor
Next = Fx(Count+(1*Factor))/Factor
ActualCord = gfx.Point(i, ((Sy/2)-Actual)) # Starting point
NextCord = gfx.Point((i+1), (((Sy+1)/2)-Next)) # Ending point
line = gfx.Line(ActualCord,NextCord);
line.setFill(gfx.color_rgb(r,g,b)); line.draw(Win)
if Mkrs != 0 and Count == Mkrs[mc]:
print(ActualCord, "x: "+str(Count)+" y: "+str(Fx(Count)))
label = gfx.Text(ActualCord, "x: "+str(Count)+" y: "+str(Fx(Count)))
label.setFill(gfx.color_rgb(r,g,b)); label.draw(Win)
mc+=1
else: pass
except ValueError: pass
except OverflowError: pass
except ZeroDivisionError: pass
except IndexError: pass
Count += Factor
def init(s,xs,g): # s - Window size # xs - x axis size
global Win; global Sx; global Sy; global Factor; # Def global variables
global x; global y; global G;
x, y = s, int(s*(3/4)) # XY max value ( x: 0,s ; y: 0,s*(3/4) )
Win = gfx.GraphWin("Teenygraph", x, y) # Show window
Sx, Sy = x,y #(x-200,y-200)
Factor = xs/x # Ratio between graphic and window size
G = g
Win.setBackground(gfx.color_rgb(Color1[0],Color1[1],Color1[2]))
grid(g*2) # Draw grid
axis(x,y) # Draw axis
def axis(x,y):
l1 = gfx.Line(gfx.Point(x/2,0),gfx.Point(x/2,x));
l1.setFill(gfx.color_rgb(Color2[0],Color2[1],Color2[2])); l1.draw(Win)
l2 = gfx.Line(gfx.Point(x,Sy/2),gfx.Point(1,y/2));
l2.setFill(gfx.color_rgb(Color2[0],Color2[1],Color2[2])); l2.draw(Win)
def grid(m): # m - Def the distance between 2 lines
e = 0
for i in range(0, int((Sx)/(m/Factor))+1):
l = gfx.Line(gfx.Point((e/Factor)+(Sx/2),0),gfx.Point((e/Factor)+(Sx/2),Sy))
l.setFill(gfx.color_rgb(Color3[0],Color3[1],Color3[2])); l.draw(Win)
l = gfx.Line(gfx.Point((Sx/2)-(e/Factor),0),gfx.Point(Sx/2-(e/Factor),Sy))
l.setFill(gfx.color_rgb(Color3[0],Color3[1],Color3[2])); l.draw(Win)
e+=m/2
e = 0
for i in range(0, int((Sy)/(m/Factor))+1):
l = gfx.Line(gfx.Point(0,(e/Factor)+(Sy/2)),gfx.Point(Sx,(e/Factor)+(Sy/2)))
l.setFill(gfx.color_rgb(Color3[0],Color3[1],Color3[2])); l.draw(Win)
l = gfx.Line(gfx.Point(0,(Sy/2)-(e/Factor)),gfx.Point(Sx,(Sy/2)-(e/Factor)))
l.setFill(gfx.color_rgb(Color3[0],Color3[1],Color3[2])); l.draw(Win)
e+=m/2
def clear():
for i in Win.items[:]:
i.undraw()
grid(G*2) # Draw grid
axis(x,y) # Draw axis
Win.update()