from pathlib import Path
from zipfile import ZipFile, ZIP_DEFLATED, ZIP_STORED
from xml.sax.saxutils import escape
import os, math
home=Path.home(); desktop=next((p for p in (home/'Рабочий стол',home/'Desktop') if p.is_dir()),home/'Desktop');desktop.mkdir(exist_ok=True)
out=desktop/'Практическая_работа_35_готовая.odt'
s=[]
def add(x):s.append(x)
def line(x1,y1,x2,y2,w=2,color='#333',dash=''):
add(f'<line x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}" stroke="{color}" stroke-width="{w}" {"stroke-dasharray="+chr(34)+dash+chr(34) if dash else ""}/>')
def poly(points,fill='#ddd',stroke='#333',w=2):
add(f'<polygon points="{points}" fill="{fill}" stroke="{stroke}" stroke-width="{w}"/>')
def rect(x,y,w,h,fill='#ddd',stroke='#333',r=0):add(f'<rect x="{x}" y="{y}" width="{w}" height="{h}" rx="{r}" fill="{fill}" stroke="{stroke}" stroke-width="2"/>')
def circ(x,y,r,fill='#ddd',stroke='#333',w=2):add(f'<circle cx="{x}" cy="{y}" r="{r}" fill="{fill}" stroke="{stroke}" stroke-width="{w}"/>')
def txt(x,y,t,size=20):add(f'<text x="{x}" y="{y}" font-family="Liberation Serif" font-size="{size}" fill="#222">{escape(t)}</text>')
def arrow(x1,y1,x2,y2,color='#344c61',w=6):
line(x1,y1,x2,y2,w,color)
a=math.atan2(y2-y1,x2-x1);z=17
poly(f'{x2},{y2} {x2-z*math.cos(a-.44)},{y2-z*math.sin(a-.44)} {x2-z*math.cos(a+.44)},{y2-z*math.sin(a+.44)}',color,color,1)
def svg(w,h):return f'<svg xmlns="http://www.w3.org/2000/svg" width="{w}" height="{h}" viewBox="0 0 {w} {h}">'+''.join(s)+'</svg>'
# Задание 1: векторы на плоскости
poly('240,200 315,85 515,85 440,200','#e3e7e9','#919a9d',1)
arrow(240,200,145,75,'#899ba4',6);txt(135,72,'C',22)
arrow(240,200,285,20,'#899ba4',6);txt(280,15,'P',22)
arrow(240,200,390,200,'#283e56',7);txt(234,231,'O',24)
arrow(240,200,355,125,'#a0abb0',5);txt(315,156,'b',22)
arrow(285,20,390,130,'#283e56',6);txt(397,133,'P',22)
arrow(345,200,390,130,'#283e56',6);txt(345,228,'P',22)
arrow(345,200,455,200,'#283e56',6);txt(455,228,'A',22)
line(395,141,505,272,6,'#283e56','25,13');txt(390,233,'a',22);txt(174,146,'c',22);txt(258,112,'p',22)
svg1=svg(610,290);s.clear()
# Задание 2: рисунки из фигур: кораблик, ёлка, клоун, поезд.
# Кораблик
poly('25,250 265,250 218,315 75,315','#798d9a');poly('135,245 135,110 258,245','#f1f4f5');poly('135,245 135,115 30,245','#e9eff2')
line(135,245,135,108,3);add('<path d="M137 113 Q157 103 180 109 L180 158 Q158 145 137 158 Z" fill="#73889b" stroke="#333" stroke-width="2"/>');circ(215,281,18,'#f3f4f2')
# Елка
poly('465,105 417,180 442,180 392,245 432,245 376,325 575,325 519,245 559,245 513,180 538,180','#bdcbd0')
poly('477,60 486,85 512,85 492,99 500,124 477,110 454,124 462,99 442,85 468,85','#889dac')
rect(465,325,26,38,'#a0a6a7')
for x,y in [(435,172),(515,172),(411,294),(542,293)]:circ(x,y,16,'#8c9eaa')
for x,y in [(477,162),(477,267)]:poly(f'{x},{y-25} {x+16},{y} {x},{y+25} {x-16},{y}','#eef1f1')
for x,y in [(477,221)]:add(f'<path d="M{x+9} {y-25} A27 27 0 1 0 {x+9} {y+25} A19 19 0 1 1 {x+9} {y-25}" fill="#e9eef0" stroke="#333"/>')
for x,y in [(403,225),(550,225),(477,294)]:poly(f'{x-25},{y-15} {x},{y} {x-25},{y+15} {x-25},{y-15} {x+25},{y-15} {x},{y} {x+25},{y+15} {x+25},{y-15}','#8799a1')
# Клоун
circ(740,155,52,'#f3f5f5');poly('685,119 795,119 740,90','#97a4aa');circ(740,85,6,'#a3adb2')
for x in (720,760):circ(x,149,7,'#55626b')
add('<path d="M728 174 Q740 187 752 174" fill="none" stroke="#343434" stroke-width="2"/>')
poly('740,184 670,325 812,325','#b1bfc6')
for y in range(211,318,23):
for x in range(705+(y//23%2)*10,781,21):circ(x,y,4,'#f5f7f7','#555',1)
for x,d in [(670,-1),(809,1)]:
poly(f'{x},{200} {x+35*d},{247} {x+20*d},{260} {x-12*d},{220}','#b9c4c9')
circ(x+27*d,266,12,'#e9eeef')
for x in (730,760):poly(f'{x-9},325 {x+9},325 {x+4},407','#a0b3ba')
for x in (730,760):poly(f'{x-13},404 {x+17},404 {x+6},417','#8499a4')
# Поезд снизу
for x1,y1,x2,y2 in [(170,575,856,575),(170,586,856,586)]:line(x1,y1,x2,y2,5,'#354b61')
# локомотив
rect(198,480,180,77,'#b0bec5');poly('198,482 175,520 198,554','#a8b8bd')
rect(284,435,68,47,'#a4b6bd');rect(294,443,41,31,'#eff2f1',r=5)
poly('231,480 246,411 261,411 269,480','#aebbc0');rect(225,404,52,10,'#bac9d0')
for x in [228,320]:circ(x,562,20,'#526877')
for x in [228,320]:circ(x,562,6,'#d4dde0')
# Вагоны
for shift in [0,245]:
x=392+shift
poly(f'{x},442 {x+230},442 {x+211},555 {x+16},555','#b3c1c6')
poly(f'{x-7},442 {x+18},428 {x+205},428 {x+237},442','#d2dadd')
for xx in [x+25,x+140]:rect(xx,462,64,49,'#eef1f1',r=7)
for xx in [x+56,x+178]:circ(xx,562,19,'#546a79')
circ(x+118,535,17,'#a3b0b6')
for a in range(12):
xx=x+118+13*math.cos(a*math.pi/6);yy=535+13*math.sin(a*math.pi/6);circ(round(xx,2),round(yy,2),2,'#e5edef','#555',1)
for x in [385,630]:poly(f'{x},529 {x-10},541 {x},553 {x+10},541','#5b7081')
svg2=svg(890,610)
content='''<?xml version="1.0" encoding="UTF-8"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" office:version="1.2"><office:automatic-styles>
<style:style style:name="P" style:family="paragraph"><style:paragraph-properties fo:margin-bottom="0.13cm"/><style:text-properties fo:font-family="Liberation Serif" fo:font-size="12pt"/></style:style>
<style:style style:name="C" style:family="paragraph" style:parent-style-name="P"><style:paragraph-properties fo:text-align="center" fo:margin-bottom="0.22cm"/><style:text-properties fo:font-size="14pt" fo:font-weight="bold"/></style:style>
<style:style style:name="H" style:family="paragraph" style:parent-style-name="P"><style:text-properties fo:font-weight="bold"/></style:style>
<style:style style:name="I" style:family="paragraph" style:parent-style-name="P"><style:paragraph-properties fo:text-align="center" fo:margin-top="0.1cm" fo:margin-bottom="0.12cm"/></style:style>
<style:style style:name="T" style:family="text"><style:text-properties fo:font-weight="bold"/></style:style>
</office:automatic-styles><office:body><office:text>
<text:p text:style-name="C">Практическая работа № 35</text:p>
<text:p text:style-name="P"><text:span text:style-name="T">Тема:</text:span> «Рисование в MS Word 2010»</text:p>
<text:p text:style-name="P"><text:span text:style-name="T">Цель:</text:span> научиться работать в текстовом процессоре MS Word, создавать рисунки, используя вкладку Вставка, работать с готовыми шаблонами фигур, менять формат рисунка.</text:p>
<text:p text:style-name="C">Порядок выполнения работы:</text:p>
<text:p text:style-name="H">Задание 1: Постройте чертеж согласно образцу</text:p>
<text:p text:style-name="P">1. Запустите текстовый процессор MS Word.</text:p>
<text:p text:style-name="P">2. С помощью вкладки Вставка → Фигуры постройте чертеж.</text:p>
<text:p text:style-name="P">3. Сохраните работу в папке на Рабочем столе под своей фамилией.</text:p>
<text:p text:style-name="I"><draw:frame draw:name="Чертеж векторов" text:anchor-type="as-char" svg:width="12.2cm" svg:height="5.8cm"><draw:image xlink:href="Pictures/vector.svg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/></draw:frame></text:p>
<text:p text:style-name="H">Задание №2: Нарисуйте по образцу</text:p>
<text:p text:style-name="I"><draw:frame draw:name="Фигуры из автофигур" text:anchor-type="as-char" svg:width="17.2cm" svg:height="11.8cm"><draw:image xlink:href="Pictures/shapes.svg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/></draw:frame></text:p>
</office:text></office:body></office:document-content>'''
styles='''<?xml version="1.0" encoding="UTF-8"?><office:document-styles xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" office:version="1.2"><office:styles><style:default-style style:family="paragraph"><style:paragraph-properties fo:margin-bottom="0.12cm"/><style:text-properties fo:font-family="Liberation Serif" fo:font-size="12pt"/></style:default-style></office:styles><office:automatic-styles><style:page-layout style:name="pm"><style:page-layout-properties fo:page-width="21cm" fo:page-height="29.7cm" fo:margin-top="1.6cm" fo:margin-bottom="1.5cm" fo:margin-left="1.7cm" fo:margin-right="1.7cm"/></style:page-layout></office:automatic-styles><office:master-styles><style:master-page style:name="Standard" style:page-layout-name="pm"/></office:master-styles></office:document-styles>'''
manifest='''<?xml version="1.0" encoding="UTF-8"?><manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2"><manifest:file-entry manifest:full-path="/" manifest:media-type="application/vnd.oasis.opendocument.text"/><manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/><manifest:file-entry manifest:full-path="styles.xml" manifest:media-type="text/xml"/><manifest:file-entry manifest:full-path="Pictures/vector.svg" manifest:media-type="image/svg+xml"/><manifest:file-entry manifest:full-path="Pictures/shapes.svg" manifest:media-type="image/svg+xml"/></manifest:manifest>'''
with ZipFile(out,'w') as z:
z.writestr('mimetype','application/vnd.oasis.opendocument.text',compress_type=ZIP_STORED)
for name,body in [('content.xml',content),('styles.xml',styles),('META-INF/manifest.xml',manifest),('Pictures/vector.svg',svg1),('Pictures/shapes.svg',svg2)]:z.writestr(name,body,compress_type=ZIP_DEFLATED)
print('Готово:',out)