Draw on matrix

1

I would like to know how to fill a matrix in such a way that it would appear that I "draw" a figure, it is supposed that I should create the figure and then "paint" it (that would be done for example by adding another number to the "drawing"), I know to paint I should use (or so they told me) backctraking and I have been reading that I could use Bresenham to "draw" in the matrix but I do not understand much how to use both methods, if they could guide me I would appreciate it very much.

Update: The figures that can be requested would be "square", "triangle", "circle" and "rectangle", you must draw its outline and then show that figure filled with the "color" "who chose, the user should only choose if he wants a large or small figure What I've been doing recently is this:

# -*- coding: utf-8 -*-
def Rombo(n):

    l = [[' ' for x in range(n)] for z in range(n/2+1)]
    for e in range(n):
        for i in range(e,n-e):
            l[e][i] = '*'
    l = l[:0:-1]+l
    for i in l:
        print ' '.join(i)


def Cuadrado(largo,ancho):

   for i in range(largo):
       if i in[0]:
         print("* "*(ancho))
       elif i in[(largo-1)]:
         print("* "*(ancho))
       else:
         print("*"+"  "*(ancho)+" *")

def Opciones():
   op=0
   while op!=1 and op!=2 and op!=9:
     print
     print " Menu de opciones"
     print"-----------------------"
     print "[1] Rombo"
     print "[2] Cuadrado"
     print "[9] terminar la ejecucion"
     op = int(raw_input("ingrese opcion: "))
   return op  

#programa
opcion=Opciones()
while opcion!=9:
   if opcion==1:
       Rombo(21)
   elif opcion==2:
      Cuadrado(6,6) 
   else:
      print"Debe ingresar una opcion valida"
print 'Adios, nos vemos :3' 

Note: Something like that would be the menu, I managed to implement the square and diamond but I do not know how to stop the infinite loop so they do not print anymore, I also do not know how to fill the square with the color that want the user and in the case of the diamond I did not think of how to do it that only shows the edges, but I get everything full.

    
asked by Wolf 23.12.2018 в 18:24
source

1 answer

0

I made an outline on the subject of the filling, I hope it serves you:

opciones = {1:"Rombo", 2:"Cuadrado", 9:"Rellenar/Vaciar",99:"Terminar la ejecución"}
rellenar = False
relleno = " "

def rombo(n):
  l = [[" " for x in range(n)] for z in range(int(n/2+1))]
  for e in range(n):
    for i in range(e, n-e):
      l[e][i] = "*"
  l = l[:0:-1] + l
  for i in l:
    print(" ".join(i))


def cuadrado(lado):
  for i in range(lado):
    if i is 0:
      print("* "*(lado))
    elif i in[(lado-1)]:
      print("* "*(lado))
    else:
      print(("*"+relleno) + (relleno*2)*(lado-2) + "*")

def obtenerAncho():
  while True:
    op2 = input("Ingrese el ancho: ")
    if op2.isdigit() is True:
      return int(op2)
    return 0


while True:
  print("")
  print("Menú de opciones".center(30))
  print("-"*30)
  for opcion in list(opciones.keys()):
    print("[%d] %s" % (opcion, opciones[opcion]))

  op1 = input("\nIngrese una opción: ")
  if op1.isdigit() is True and int(op1) in list(opciones.keys()):
    if op1 == "1":
      rombo(obtenerAncho())
    elif op1 == "2":
      cuadrado(obtenerAncho())
    elif op1 == "9":
      rellenar = not rellenar
      print(" RELLENO ACTIVADO ".center(30,"=") if rellenar is True else " RELLENO DESACTIVADO ".center(30,"="))
      relleno = "#" if rellenar is True else " "
    elif op1 == "99":
      print("Hasta la vista baby")
      break
    
answered by 26.12.2018 в 17:00