repl.it
@ArjunSS1/

Graph Program - points

Python

No description

fork
loading
Files
  • main.py
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.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
import math, os
from colorama import Fore, Back, Style 

#The entire graph



class points:
  def __init__(self,x,y):
    self.x = x
    self.y = y
  def graph_(self):
    x = y = 0 
    while y < len(graph): #Grows larger for larger graphs
      for x in range(0,len(graph[y])):
      #  print(x,y,end=" ")
        output = graph[y][x]
        if output == '+':
          print(Fore.WHITE + output,end=" ",flush=True)
        elif output == '0':
          if x == 10:
            output += ' '
          print(Fore.GREEN + output,end=" ",flush=True)
        else:
          print(Fore.RED + output,end=" ",flush=True)
      print("")
      y += 1 #Line complete x^ is for the individual characters
  
  def reset(self):
    global graph #Resets the graph with the global variable
    graph = [['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ["-","-","-","-","-","-","-","-","-","-","[]","-","-","-","-","-","-","-","-","-","-"],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+'],
        ['+','+','+','+','+','+','+','+','+','+',"| ",'+','+','+','+','+','+','+','+','+','+']]

      
class graph_class(points):
  def __init__(self,x,y):
    super().__init__(x,y)

  def __str__(self):
    return f"({self.x},{self.y})"

  def configure(self): #Reconfigure the graph

    graph[10-self.y][self.x+10] = '0'



def run(name):
  global x,y
  os.system('clear')
  print(f"    {name:^10}") #Writes the name at the top
  coords = graph_class(0,0)
  coords.reset() #Resets the graph to zero
  raw_amount = input("Enter the coordinates:\n>>> ").replace('(','').replace(')','')
  if(raw_amount.strip().lower() == 'exit'):
    exit()
  try:
    str_x,str_y = raw_amount.split(',')
    x,y = int(str_x),int(str_y)
    if (((x >= -10) and (x <= 10)) and ((y >= -10) and (y <= 10))) is False:
      run(name,current_x,current_y)        
  except: #If we get an error
    run(name) #STarts the code again
  coords = graph_class(x,y) #Start the graphing process
  coords.configure() #We reconfigure the graph to have the existing coords
  os.system("clear") #Clears the screen for the big wall of text
  coords.graph_() #We show the graph
  inputval = input("") 
  run(name) 

run('Grapher') #Start the program
?