Se ofrecen a continuación unas posibles soluciones de los ejercicios SVG Ficheros (4).
import webbrowser
def main():
ruta = "svg-ficheros-4-1-1.html"
with open(ruta, mode="w", encoding="utf-8") as fichero:
print("<!DOCTYPE html>", file=fichero)
print('<html lang="es">', file=fichero)
print("<head>", file=fichero)
print(' <meta charset="utf-8">', file=fichero)
print(" <title>Ficheros (4) 1-1. SVG. Ejercicios. Python</title>", file=fichero)
print(' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
file=fichero)
print("</head>", file=fichero)
print("", file=fichero)
print("<body>", file=fichero)
print(' <svg version="1.1" xmlns="http://www.w3.org/2000/svg"', file=fichero)
print(' width="320" height="320" viewBox="-10 -10 320 320"', file=fichero)
print(' style="border: black 1px solid">', file=fichero)
for i in range(15):
print(f' <circle cx="150" cy="150" r="{-6*i + 150}" stroke="black" '
'stroke-width="1" fill="none" />', file=fichero)
print(' <polygon points="150,10 290,150 150,290 10,150" stroke="red" '
'stroke-width="2" fill="none" />', file=fichero)
print(" </svg>", file=fichero)
print("</body>", file=fichero)
print("</html>", file=fichero)
webbrowser.open(ruta)
if __name__ == "__main__":
main()
import webbrowser
def main():
ruta = "svg-ficheros-4-1-2.html"
with open(ruta, mode="w", encoding="utf-8") as fichero:
print("<!DOCTYPE html>", file=fichero)
print('<html lang="es">', file=fichero)
print("<head>", file=fichero)
print(' <meta charset="utf-8">', file=fichero)
print(" <title>Ficheros (4) 1-2. SVG. Ejercicios. Python</title>", file=fichero)
print(' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
file=fichero)
print("</head>", file=fichero)
print("", file=fichero)
print("<body>", file=fichero)
print(' <svg version="1.1" xmlns="http://www.w3.org/2000/svg"', file=fichero)
print(' width="320" height="320" viewBox="-10 -10 320 320"', file=fichero)
print(' style="border: black 1px solid">', file=fichero)
for i in range(20):
print(f' <line x1="0" y1="{-20*i + 150}" x2="300" y2="{20*i + 150}" '
'stroke="black" stroke-width="1" />', file=fichero)
print(f' <line x1="0" y1="{20*i + 150}" x2="300" y2="{-20*i + 150}" '
'stroke="black" stroke-width="1" />', file=fichero)
print(' <line x1="100" y1="-10" x2="100" y2="310" stroke="red" '
'stroke-width="2" />', file=fichero)
print(' <line x1="200" y1="-10" x2="200" y2="310" stroke="red" '
'stroke-width="2" />', file=fichero)
print(" </svg>", file=fichero)
print("</body>", file=fichero)
print("</html>", file=fichero)
webbrowser.open(ruta)
if __name__ == "__main__":
main()
import webbrowser
def main():
ruta = "svg-ficheros-4-1-3.html"
with open(ruta, mode="w", encoding="utf-8") as fichero:
print("<!DOCTYPE html>", file=fichero)
print('<html lang="es">', file=fichero)
print("<head>", file=fichero)
print(' <meta charset="utf-8">', file=fichero)
print(" <title>Ficheros (4) 1-3. SVG. Ejercicios. Python</title>", file=fichero)
print(' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
file=fichero)
print("</head>", file=fichero)
print("", file=fichero)
print("<body>", file=fichero)
print(' <svg version="1.1" xmlns="http://www.w3.org/2000/svg"', file=fichero)
print(' width="320" height="320" viewBox="-10 -10 320 320"', file=fichero)
print(' style="border: black 1px solid">', file=fichero)
for i in range(20):
print(f' <line x1="0" y1="150" x2="300" y2="{20*i + 150}" '
'stroke="black" stroke-width="1" />', file=fichero)
print(f' <line x1="0" y1="150" x2="300" y2="{-20*i + 150}" '
'stroke="black" stroke-width="1" />', file=fichero)
print(' <rect x="80" y="80" width="180" height="140" stroke="red" '
'stroke-width="2" fill="none" />', file=fichero)
print(" </svg>", file=fichero)
print("</body>", file=fichero)
print("</html>", file=fichero)
webbrowser.open(ruta)
if __name__ == "__main__":
main()
import webbrowser
def main():
ruta = "svg-ficheros-4-1-4.html"
with open(ruta, mode="w", encoding="utf-8") as fichero:
print("<!DOCTYPE html>", file=fichero)
print('<html lang="es">', file=fichero)
print("<head>", file=fichero)
print(' <meta charset="utf-8">', file=fichero)
print(" <title>Ficheros (4) 1-4. SVG. Ejercicios. Python</title>", file=fichero)
print(' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
file=fichero)
print("</head>", file=fichero)
print("", file=fichero)
print("<body>", file=fichero)
print(' <svg version="1.1" xmlns="http://www.w3.org/2000/svg"', file=fichero)
print(' width="320" height="320" viewBox="-10 -10 320 320"', file=fichero)
print(' style="border: black 1px solid">', file=fichero)
for i in range(11):
print(f' <line x1="0" y1="{30 * i}" x2="300" y2="{10*i + 100}" '
'stroke="black" stroke-width="1" />', file=fichero)
print(' <line x1="20" y1="110" x2="20" y2="190" '
'stroke="red" stroke-width="2" />', file=fichero)
print(' <line x1="280" y1="110" x2="280" y2="190" '
'stroke="red" stroke-width="2" />', file=fichero)
print(" </svg>", file=fichero)
print("</body>", file=fichero)
print("</html>", file=fichero)
webbrowser.open(ruta)
if __name__ == "__main__":
main()
import webbrowser
def main():
ruta = "svg-ficheros-4-1-5.html"
with open(ruta, mode="w", encoding="utf-8") as fichero:
print("<!DOCTYPE html>", file=fichero)
print('<html lang="es">', file=fichero)
print("<head>", file=fichero)
print(' <meta charset="utf-8">', file=fichero)
print(" <title>Ficheros (4) 1-5. SVG. Ejercicios. Python</title>", file=fichero)
print(' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
file=fichero)
print("</head>", file=fichero)
print("", file=fichero)
print("<body>", file=fichero)
print(' <svg version="1.1" xmlns="http://www.w3.org/2000/svg"', file=fichero)
print(' width="320" height="320" viewBox="-10 -10 320 320"', file=fichero)
print(' style="border: black 1px solid">', file=fichero)
for i in range(14):
print(f' <line x1="{10*i + 10}" y1="{15*i + 65}" x2="{10*i + 10}" '
f'y2="{15*i + 115}" stroke="black" stroke-width="1" />', file=fichero)
for i in range(19):
print(f' <line x1="{10*i + 10}" y1="{15*i + 15}" x2="{10*i + 60}" '
f'y2="{15*i + 15}" stroke="black" stroke-width="1" />', file=fichero)
print(f' <line x1="{10*i + 110}" y1="{15*i - 10}" x2="{10*i + 110}" '
f'y2="{15*i + 40}" stroke="black" stroke-width="1" />', file=fichero)
print(' <line x1="0" y1="75" x2="150" y2="300" '
'stroke="red" stroke-width="2" />', file=fichero)
print(' <line x1="25" y1="0" x2="225" y2="300" '
'stroke="red" stroke-width="2" />', file=fichero)
print(' <line x1="100" y1="0" x2="300" y2="300" '
'stroke="red" stroke-width="2" />', file=fichero)
print(" </svg>", file=fichero)
print("</body>", file=fichero)
print("</html>", file=fichero)
webbrowser.open(ruta)
if __name__ == "__main__":
main()
import webbrowser
def main():
ruta = "svg-ficheros-4-2-1.html"
with open(ruta, mode="w", encoding="utf-8") as fichero:
print("<!DOCTYPE html>", file=fichero)
print('<html lang="es">', file=fichero)
print("<head>", file=fichero)
print(' <meta charset="utf-8">', file=fichero)
print(" <title>Ficheros (4) 2-1. SVG. Ejercicios. Python</title>", file=fichero)
print(' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
file=fichero)
print("</head>", file=fichero)
print("", file=fichero)
print("<body>", file=fichero)
print(' <svg version="1.1" xmlns="http://www.w3.org/2000/svg"', file=fichero)
print(' width="620" height="320" viewBox="-10 -10 620 320"', file=fichero)
print(' style="border: black 1px solid">', file=fichero)
for i in range(4):
for j in range(12):
print(f' <rect x="{80*j + 20}" y="{80 * i}" width="40" '
'height="40" fill="black" />', file=fichero)
print(f' <line x1="0" y1="{80 * i}" x2="600" y2="{80 * i}" '
'stroke="red" stroke-width="1" />', file=fichero)
print(f' <rect x="{80*j}" y="{80*i + 40}" width="40" '
'height="40" fill="black" />', file=fichero)
print(f' <line x1="0" y1="{80*i + 40}" x2="600" y2="{80*i + 40}" '
'stroke="red" stroke-width="1" />', file=fichero)
print(" </svg>", file=fichero)
print("</body>", file=fichero)
print("</html>", file=fichero)
webbrowser.open(ruta)
if __name__ == "__main__":
main()
import webbrowser
def main():
ruta = "svg-ficheros-4-2-2.html"
with open(ruta, mode="w", encoding="utf-8") as fichero:
print("<!DOCTYPE html>", file=fichero)
print('<html lang="es">', file=fichero)
print("<head>", file=fichero)
print(' <meta charset="utf-8">', file=fichero)
print(" <title>Ficheros (4) 2-2. SVG. Ejercicios. Python</title>", file=fichero)
print(' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
file=fichero)
print("</head>", file=fichero)
print("", file=fichero)
print("<body>", file=fichero)
print(' <svg version="1.1" xmlns="http://www.w3.org/2000/svg"', file=fichero)
print(' width="620" height="320" viewBox="-10 -10 620 320"', file=fichero)
print(' style="border: black 1px solid">', file=fichero)
for i in range(5):
for j in range(10):
print(f' <rect x="{60 * j}" y="{60 * i}" width="25" height="25" '
'stroke="black" stroke-width="5" fill="none" />', file=fichero)
print(f' <rect x="{60*j + 30}" y="{60*i + 30}" width="25" height="25" '
'stroke="black" stroke-width="5" fill="none" />', file=fichero)
print(f' <rect x="{60*j + 32.5}" y="{60*i + 2.5}" width="20" '
'height="20" fill="black" />', file=fichero)
print(f' <rect x="{60*j + 2.5}" y="{60*i + 32.5}" width="20" '
'height="20" fill="black" />', file=fichero)
print(" </svg>", file=fichero)
print("</body>", file=fichero)
print("</html>", file=fichero)
webbrowser.open(ruta)
if __name__ == "__main__":
main()
import webbrowser
def main():
ruta = "svg-ficheros-4-2-3.html"
with open(ruta, mode="w", encoding="utf-8") as fichero:
print("<!DOCTYPE html>", file=fichero)
print('<html lang="es">', file=fichero)
print("<head>", file=fichero)
print(' <meta charset="utf-8">', file=fichero)
print(" <title>Ficheros (4) 2-3. SVG. Ejercicios. Python</title>", file=fichero)
print(' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
file=fichero)
print("</head>", file=fichero)
print("", file=fichero)
print("<body>", file=fichero)
print(' <svg version="1.1" xmlns="http://www.w3.org/2000/svg"', file=fichero)
print(' width="620" height="320" viewBox="-10 -10 620 320"', file=fichero)
print(' style="border: black 1px solid; background-color: lightgray">', file=fichero)
for i in range(7):
for j in range(15):
print(f' <rect x="{40 * j}" y="{40 * i}" width="36" height="36" '
'fill="black" />', file=fichero)
for i in range(6):
for j in range(14):
print(f' <circle cx="{40*j + 38}" cy="{40*i + 38}" r="6" '
'fill="white" />', file=fichero)
print(" </svg>", file=fichero)
print("</body>", file=fichero)
print("</html>", file=fichero)
webbrowser.open(ruta)
if __name__ == "__main__":
main()
import webbrowser
def main():
ruta = "svg-ficheros-4-2-4.html"
with open(ruta, mode="w", encoding="utf-8") as fichero:
print("<!DOCTYPE html>", file=fichero)
print('<html lang="es">', file=fichero)
print("<head>", file=fichero)
print(' <meta charset="utf-8">', file=fichero)
print(" <title>Ficheros (4) 2-4. SVG. Ejercicios. Python</title>", file=fichero)
print(' <meta name="viewport" content="width=device-width, initial-scale=1.0">',
file=fichero)
print(" </head>", file=fichero)
print("", file=fichero)
print("<body>", file=fichero)
print(' <svg version="1.1" xmlns="http://www.w3.org/2000/svg"', file=fichero)
print(' width="320" height="320" viewBox="-10 -10 320 320"', file=fichero)
print(' style="border: black 1px solid">', file=fichero)
print(" <defs>", file=fichero)
print(' <clipPath id="myClip">', file=fichero)
for i in range(20):
for j in range(5):
print(f' <rect x="{60*j + 30}" y="{15 * i}" width="30" height="7.5" '
'fill="black" />', file=fichero)
print(f' <rect x="{60*j}" y="{15*i + 7.5}" width="30" height="7.5" '
'fill="black" />', file=fichero)
print(" </clipPath>", file=fichero)
print(" </defs>", file=fichero)
for i in range(20):
for j in range(5):
print(f' <rect x="{60*j + 30}" y="{15 * i}" width="30" height="7.5" '
'fill="black" />', file=fichero)
print(f' <rect x="{60*j}" y="{15*i + 7.5}" width="30" height="7.5" '
'fill="black" />', file=fichero)
print(' <circle cx="150" cy="150" r="75" fill="white" />', file=fichero)
print(' <circle cx="150" cy="150" r="75" clip-path="url(#myClip)" transform="rotate(90 150 150)" />', file=fichero)
print(" </svg>", file=fichero)
print("</body>", file=fichero)
print("</html>", file=fichero)
webbrowser.open(ruta)
if __name__ == "__main__":
main()