diff --git a/a.html b/a.html new file mode 100644 index 0000000..0c8e408 --- /dev/null +++ b/a.html @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/documents/input specs/Discussion.txt b/documents/input specs/Discussion.txt new file mode 100644 index 0000000..3878d15 --- /dev/null +++ b/documents/input specs/Discussion.txt @@ -0,0 +1,238 @@ +NCERT Class 10th Chapter 6 Triangles + +Note:I think we should have an extend() function so that the user can extend a line without having to deal with the angle and making it look like a real extension +Note: We should not rotate the 'measurement' with the line, like they've write it straight (0°) in the math book even for bent lines + +Fig6.1 (ii) : +s1=square(side=100) +s2=square(side=60,center=s1.center) + +Fig 6.1 (iii): +t1=triangle(side=70) +Note: I think it would be quite efficient if the user writes just one side, we make an equilateral triangle, if two-isosceles and if all 3 we make skelene triangle +t2=triangle(side=50,center=t1.center) + +Fig 6.2: +l1=line(length=50,label="AD") +l2=line(angle=-90,length=50) +l3=line(angle=-10,y1=l2.y1,length=70,label="BC") +l4=line(x1=l3.x1,y1=l3.y1,x2=l1.x2,y2=l1.y2) + +Fig 6.5: +t=trapezium(side1=30,side2=40,distance=50,markAngles="all",label="ABCD") +Note: We can have specific parameters if we want only one angle to be marked + +Fig 6.6: +s=square(side=50,label="ABCD",shadeCorners="all") +Note: Similar to how we mark angles + +Fig 6.7: +s=square(side=50,label="ABCD") + +Fig 6.7 2nd part: +p=parallelogram(side1=40,side2=50,angle=50,label="PQRS) + +Fig 6.8: +p=parallelogram(side=40,side=40,angle=60,label="PQRS") + +Fig 6.9: +t=triangle(side=50,label="ABC") +e=extend(direction="forward",type="solid",t.side1,20) +e2=extend(direction="forward",type="solid",t.side3,20) +l=line(startpoint=midpoint(t.side1),endpoint=midpoint(t.side3)) + +Fig 6.11: +t=triangle(side=50,angle=-10,markAngles=t.v1,label="BCA") +e1=extend(direction="forward",t.side1,type="solid",cap="arrow",length=20) +e2=extend(direction="forward",t.side3,type="solid",cap="arrow",length=20,direction="forward") + +Fig 6.12: +t=triangle(type="right",side1=60,side2=80,angle=-30,label="BCA") +l1=line(startpoint=midpoint(t.side1),endpoint=midpoint(t.side2)) +e1=extend(l1,direction="both",cap="arrow",type="solid") +l2=line(startpoint=midpoint(t.side1),endpoint=midpoint(t.side2,ratio="1:3")) +e2=extend(l2,direction="both",cap="arrow") +Note: default for 'type' with extend is "dotted" + +Fig 6.13: +t=triangle(side=50,label="BCA") +l=line(startpoint=midpoint(t.side1),endpoint=midpoint(t.side3),type="dotted") +e=extend(l,cap="arrow",direction="both") + +Fig 6.14: +l1=line(length=50,label="AB") +l2=line(angle=-90,length=50) +l3=line(angle=-10,y1=l2.y1,length=70,label="DC") +l4=line(x1=l3.x1,y1=l3.y1,x2=l1.x2,y2=l1.y2) +l5=line(startpoint=midpoint(l2,ratio="2:5"),endpoint=midpoint(l4,ratio="2:5"),label="EF") + +Fig 6.14: +t=triangle(side=60,label="QRP",markAngles=t.v2) +l=line(startpoint=midpoint(t.side1),endpoint=midpoint(t.side3),label="ST") +a=angle(l,t.side1) +Note: by default the angle() function will mark the smaller angle + +Fig 6.15: +t=trapezium(side1=30,side2=50,distance=40,labels="DCBA",diagonal{v2,v4,"d1",dotted}) +l=line(startpoint=midpoint({v1,v4}),endpoint=midpoint({v2,v3})) +Note: Having diagonal inside the brackets will make it difficult to access each of its properties such as dotted line or solid line, cap style, labels, naming etc + +Fig 6.17: +t=triangle(side1=30,side2=40,label="BCA",markAngles=v2) +l=line(startpoint=midpoint(t.side2),label="DE",parallelTo=t.side1) +e=extend(l,direction="both",cap="arrow",length=30,type="solid") +a=angle(l,t.side3) + +Fig 6.17 (ii): +t=triangle(side=50,label="BCA") +l=line(startpoint=midpoint(t.side3),endpoint=midpoint(t.side2),label="DE") +e=extend(l,direction="both",type="solid",length=20) + +Fig 6.18: +k=kite(side1=30,side2=50,label="DCBA") +l1=line(startpoint=k.v2,endpoint=k.v4) +l2=line(startpoint=midpoint({k.v3,k.v4}),endpoint=midpoint({k.v2,k.v4}),label="ML") +l3=line(startpoint=midpoint({k.v2,k.v4}),endpoint=midpoint({k.v1,k.v4}),label=" N") +Note: I gave a space in label so that space is written instead of a label, or simply so that 'L' doesn't appear twice at the same point. We can also assign a special character that denotes "null" + +Fig 6.19: +t=triangle(side=60,label="BCA") +l1=line(startpoint=t.v3,endpoint=midpoint(t.side1),label=" E") +l2=line(startpoint=l1.endpoint,endpoint=midpoint(t.side3)) +l3=line(startpoint=l2.endpoint,endpoint=midpoint({t.v1,l1.endpoint}),label="DF") + +Note: I think we should have a "copy()" or "similar()" function to copy similar shapes which are slightly different. Eg. Two congruent triangles that have a common point, we can just do copy() like: +t2=copy(t1,v1=t1.v1) + +Trying to integrate medians/diagonals etc within the main functions: + +Fig 6.20: +t1=triangle(side=50,label="QRP",midpointLine(side2,side3,name="m",label="EF")) +t2=triangle(base=t1.side1,side2=20,label=" O") +t3=triangle(base=t1.m,side2=10,label=" D") +l=line(startpoint=t2.v3,endpoint=t1.v3) +Note: we'll have to use dynamic variable naming with this + +Fig 6.21: +t1=triangle(side=50,label="QRP") +t=trapezium(side1=t1.side1,side2=40,distance=10,label=" CB") +t2=triangle(base=t.base2,side=30,label=" O") +t3=triangle(base=t.side2,side=40,label=" A") +l=line(startpoint=t2.v3,endpoint=t1.t3) + +Fig 6.22: +t=triangle(side=50,label="BCA",markAngle=v1,markAngle=v2,markAngle=v3) +Note: opposed to angle() function, we can have this property that would allow the user to mark and differentiate between three angles by default + +Fig 6.23: +t=triangle(side=50,label="BCA",markAngle={v1,v2}) +e1=extend(t.side2,direction="forward",length=20,type="solid",cap="arrow") +e2=extend(t.side3,direction="backward",type="solid",cap="arrow",length=20) +Note: Using {} and writing two values separated by ',' will mark two or more angles as equal angles + +Fig 6.24 +t=triangle(side=40,label="BCA") + +Another alternate way for midpointLine(): + +Fig 6.24 (under the first one, not marked): +t=triangle(side=50,label="EFD",midpointLine=line(startpoint=midpoint(side2),endpoint=midpoint(side3),type="dotted",label="QP") + +Fig 6.25: +t=triangle(side1=30,side2=50,side3=20,label="BCA") + +Fig 6.26: +t1=triangle(side=30,label="BCA") +t2=triangle(v1=t1.x1+100,side=50,label="EFD",midpointline(side2,side3,type="dotted",label="PQ") +Note: I feel the idea you gave about having nested functions like above is easier to understand + +Fig 6.27 (lower one): +t=triangle(side1=40,side2=60,side3=30,label="EFD",markAngles=v3,side2.measurement="6cm",side3.measurement="3cm") + +Fig 6.28 (right one): +t=triangle(side=50,label="EFD",midpointLine(side2,side3,ratio="4:1",label="PQ",type="dotted")) + +Fig 6.29: +t1=triangle(side=30,label="PQO",angle=-90) +t2=copy(t1,v3=t1.v3,label="SR ") +Note: The labelling will happen before the figure is rotated by the given angle + +Fig 6.30: +t=triangle(side=50,label='BCA',markAngle={v1,v3}) + +=================================================================================================================t = triangle(length=('6','3\sqrt{3}','3.8'),angle=('60',-,'80'),label='BCA',baseAngle=0) +OR +l1 = line(label="AB",length='3.8',angle='0') +l2 = line(label="BC",length='6',svg={stroke-width=2}) +l3 = line(label="CA",length='3\sqrt{3}') +t = triangle(l1,l2,l3,angles=((l1,l3,60),(l2,l3,80))) + +--------------------------------------------------------------------------------------- +Manjot -- +1. lengthy code in second case +2. finding hard to associate +------------------------------------------------------------------------------------------------------ + +label = ' l' or (,'l') ' l' +label = 'BCA' or ('B','C','A') or 'B C A' + +style = dotted, dotted-aarowed, dotted-right-arrowed, dotted-left-arrowed +OR +style = dotted +arrow = forward, backward, both, none + +--------------------------------------------------------------------------------------------- +Manjot - Prefer second one -- seems simple +--------------------------------------------------------------------------------------------- + +Visual parameters +l2 = line(label="BC",length='6',svg={stroke-width=4,stroke=red}) +OR +thickness vs stroke-width +color vs stroke +as parameters of our object itself + +------------------------------------------------------------------------------------- +1. We didn't need to parse, as they have no semantic +2. learning curve, he/she needs to remember that which is core tool command and which is svg +3. misuse of svg functionality +4. We can focus more on semantic, whereas tool will also support visual effects from the first day + +Manjot -- preferred second one. Still we can implement svg +----------------------------------------------------------------------------------------------------- + +Point on Circle Periphery +point(location=perimeter, angle=-60, label='P') +OR +point(location=perimeter, ratio='5:7', label='P') + + + +triangle{ +label +length +angle +baseAngle +Style +showLengths = None (default), 'all', 'AB,BC', (l1,l2) +showAngles = None (default), 'all', 'all_', (v1_,v3_), 'A_,C_' -- _ is for values, all and all_ can be variables +} + +line( +label = 'A,B', 'l', ',l', 'l,' +length = 20 (default: cm), 20in, 20px, 20m, 20cm, 20km, 20mi, 20mm, +angle - 60 (default: degree), 60r, 60d +style = solid, dashed +arrows = None (default), (ratio='5:7',direction='forward', 'backward', v1, v2, 'A', 'B') -- for both sides ((direction='forward'),(direction='backward')) +showLength = False (default), True +points = (ratio = '5:7', label = 'P') -- for more multiple points, we can use list of arrays +extension = (direction = 'forward', 'backward', v1, v2, 'A', 'B', +line = {length = 4cm, style = dashed} +) +) + +Cicle{ +point = (ratio, label, location, angle) +} + +object property checks - angles doesn't follow line lengths \ No newline at end of file diff --git a/documents/input specs/InputNCERT106Traingles.txt b/documents/input specs/InputNCERT106Traingles.txt new file mode 100644 index 0000000..de20e50 --- /dev/null +++ b/documents/input specs/InputNCERT106Traingles.txt @@ -0,0 +1,162 @@ +NCERT Class 10th Chapter 6 Triangles + +Note:I think we should have an extend() function so that the user can extend a line without having to deal with the angle and making it look like a real extension +Note: We should not rotate the 'measurement' with the line, like they've write it straight (0°) in the math book even for bent lines + +Fig6.1 (ii) : +s1=square(side=100) +s2=square(side=60,center=s1.center) + +Fig 6.1 (iii): +t1=triangle(side=70) +Note: I think it would be quite efficient if the user writes just one side, we make an equilateral triangle, if two-isosceles and if all 3 we make skelene triangle +t2=triangle(side=50,center=t1.center) + +Fig 6.2: +l1=line(length=50,label="AD") +l2=line(angle=-90,length=50) +l3=line(angle=-10,y1=l2.y1,length=70,label="BC") +l4=line(x1=l3.x1,y1=l3.y1,x2=l1.x2,y2=l1.y2) + +Fig 6.5: +t=trapezium(side1=30,side2=40,distance=50,markAngles="all",label="ABCD") +Note: We can have specific parameters if we want only one angle to be marked + +Fig 6.6: +s=square(side=50,label="ABCD",shadeCorners="all") +Note: Similar to how we mark angles + +Fig 6.7: +s=square(side=50,label="ABCD") + +Fig 6.7 2nd part: +p=parallelogram(side1=40,side2=50,angle=50,label="PQRS) + +Fig 6.8: +p=parallelogram(side=40,side=40,angle=60,label="PQRS") + +Fig 6.9: +t=triangle(side=50,label="ABC") +e=extend(direction="forward",type="solid",t.side1,20) +e2=extend(direction="forward",type="solid",t.side3,20) +l=line(startpoint=midpoint(t.side1),endpoint=midpoint(t.side3)) + +Fig 6.11: +t=triangle(side=50,angle=-10,markAngles=t.v1,label="BCA") +e1=extend(direction="forward",t.side1,type="solid",cap="arrow",length=20) +e2=extend(direction="forward",t.side3,type="solid",cap="arrow",length=20,direction="forward") + +Fig 6.12: +t=triangle(type="right",side1=60,side2=80,angle=-30,label="BCA") +l1=line(startpoint=midpoint(t.side1),endpoint=midpoint(t.side2)) +e1=extend(l1,direction="both",cap="arrow",type="solid") +l2=line(startpoint=midpoint(t.side1),endpoint=midpoint(t.side2,ratio="1:3")) +e2=extend(l2,direction="both",cap="arrow") +Note: default for 'type' with extend is "dotted" + +Fig 6.13: +t=triangle(side=50,label="BCA") +l=line(startpoint=midpoint(t.side1),endpoint=midpoint(t.side3),type="dotted") +e=extend(l,cap="arrow",direction="both") + +Fig 6.14: +l1=line(length=50,label="AB") +l2=line(angle=-90,length=50) +l3=line(angle=-10,y1=l2.y1,length=70,label="DC") +l4=line(x1=l3.x1,y1=l3.y1,x2=l1.x2,y2=l1.y2) +l5=line(startpoint=midpoint(l2,ratio="2:5"),endpoint=midpoint(l4,ratio="2:5"),label="EF") + +Fig 6.14: +t=triangle(side=60,label="QRP",markAngles=t.v2) +l=line(startpoint=midpoint(t.side1),endpoint=midpoint(t.side3),label="ST") +a=angle(l,t.side1) +Note: by default the angle() function will mark the smaller angle + +Fig 6.15: +t=trapezium(side1=30,side2=50,distance=40,labels="DCBA",diagonal{v2,v4,"d1",dotted}) +l=line(startpoint=midpoint({v1,v4}),endpoint=midpoint({v2,v3})) +Note: Having diagonal inside the brackets will make it difficult to access each of its properties such as dotted line or solid line, cap style, labels, naming etc + +Fig 6.17: +t=triangle(side1=30,side2=40,label="BCA",markAngles=v2) +l=line(startpoint=midpoint(t.side2),label="DE",parallelTo=t.side1) +e=extend(l,direction="both",cap="arrow",length=30,type="solid") +a=angle(l,t.side3) + +Fig 6.17 (ii): +t=triangle(side=50,label="BCA") +l=line(startpoint=midpoint(t.side3),endpoint=midpoint(t.side2),label="DE") +e=extend(l,direction="both",type="solid",length=20) + +Fig 6.18: +k=kite(side1=30,side2=50,label="DCBA") +l1=line(startpoint=k.v2,endpoint=k.v4) +l2=line(startpoint=midpoint({k.v3,k.v4}),endpoint=midpoint({k.v2,k.v4}),label="ML") +l3=line(startpoint=midpoint({k.v2,k.v4}),endpoint=midpoint({k.v1,k.v4}),label=" N") +Note: I gave a space in label so that space is written instead of a label, or simply so that 'L' doesn't appear twice at the same point. We can also assign a special character that denotes "null" + +Fig 6.19: +t=triangle(side=60,label="BCA") +l1=line(startpoint=t.v3,endpoint=midpoint(t.side1),label=" E") +l2=line(startpoint=l1.endpoint,endpoint=midpoint(t.side3)) +l3=line(startpoint=l2.endpoint,endpoint=midpoint({t.v1,l1.endpoint}),label="DF") + +Note: I think we should have a "copy()" or "similar()" function to copy similar shapes which are slightly different. Eg. Two congruent triangles that have a common point, we can just do copy() like: +t2=copy(t1,v1=t1.v1) + +Trying to integrate medians/diagonals etc within the main functions: + +Fig 6.20: +t1=triangle(side=50,label="QRP",midpointLine(side2,side3,name="m",label="EF")) +t2=triangle(base=t1.side1,side2=20,label=" O") +t3=triangle(base=t1.m,side2=10,label=" D") +l=line(startpoint=t2.v3,endpoint=t1.v3) +Note: we'll have to use dynamic variable naming with this + +Fig 6.21: +t1=triangle(side=50,label="QRP") +t=trapezium(side1=t1.side1,side2=40,distance=10,label=" CB") +t2=triangle(base=t.base2,side=30,label=" O") +t3=triangle(base=t.side2,side=40,label=" A") +l=line(startpoint=t2.v3,endpoint=t1.t3) + +Fig 6.22: +t=triangle(side=50,label="BCA",markAngle=v1,markAngle=v2,markAngle=v3) +Note: opposed to angle() function, we can have this property that would allow the user to mark and differentiate between three angles by default + +Fig 6.23: +t=triangle(side=50,label="BCA",markAngle={v1,v2}) +e1=extend(t.side2,direction="forward",length=20,type="solid",cap="arrow") +e2=extend(t.side3,direction="backward",type="solid",cap="arrow",length=20) +Note: Using {} and writing two values separated by ',' will mark two or more angles as equal angles + +Fig 6.24 +t=triangle(side=40,label="BCA") + +Another alternate way for midpointLine(): + +Fig 6.24 (under the first one, not marked): +t=triangle(side=50,label="EFD",midpointLine=line(startpoint=midpoint(side2),endpoint=midpoint(side3),type="dotted",label="QP") + +Fig 6.25: +t=triangle(side1=30,side2=50,side3=20,label="BCA") + +Fig 6.26: +t1=triangle(side=30,label="BCA") +t2=triangle(v1=t1.x1+100,side=50,label="EFD",midpointline(side2,side3,type="dotted",label="PQ") +Note: I feel the idea you gave about having nested functions like above is easier to understand + +Fig 6.27 (lower one): +t=triangle(side1=40,side2=60,side3=30,label="EFD",markAngles=v3,side2.measurement="6cm",side3.measurement="3cm") + +Fig 6.28 (right one): +t=triangle(side=50,label="EFD",midpointLine(side2,side3,ratio="4:1",label="PQ",type="dotted")) + +Fig 6.29: +t1=triangle(side=30,label="PQO",angle=-90) +t2=copy(t1,v3=t1.v3,label="SR ") +Note: The labelling will happen before the figure is rotated by the given angle + +Fig 6.30: +t=triangle(side=50,label="BCA",markAngle={v1,v3}) + diff --git a/documents/input specs/NCERT106Traingles.pdf b/documents/input specs/NCERT106Traingles.pdf new file mode 100644 index 0000000..831c670 Binary files /dev/null and b/documents/input specs/NCERT106Traingles.pdf differ diff --git a/documents/input specs/spec.txt b/documents/input specs/spec.txt new file mode 100644 index 0000000..6ca9477 --- /dev/null +++ b/documents/input specs/spec.txt @@ -0,0 +1,12 @@ +line( +label = 'A,B', 'l', ',l', 'l,' +length = 20 (default: cm), 20in, 20px, 20m, 20cm, 20km, 20mi, 20mm, +angle - 60 (default: degree), 60r, 60d +style = solid, dashed +arrows = None (default), (ratio='5:7',direction='forward', 'backward', v1, v2, 'A', 'B') -- for both sides ((direction='forward'),(direction='backward')) +showLength = False (default), True +points = (ratio = '5:7', label = 'P') -- for more multiple points, we can use list of arrays +extension = (direction = 'forward', 'backward', v1, v2, 'A', 'B', +line = {length = 4cm, style = dashed} +) +) \ No newline at end of file diff --git a/src/__pycache__/sabertooth.cpython-36.pyc b/src/__pycache__/sabertooth.cpython-36.pyc new file mode 100644 index 0000000..14710dd Binary files /dev/null and b/src/__pycache__/sabertooth.cpython-36.pyc differ diff --git a/src/draw.html b/src/draw.html new file mode 100644 index 0000000..bbcfa5d --- /dev/null +++ b/src/draw.html @@ -0,0 +1,25 @@ + + + + + + + + +A +B + + +P + +Q + + +R + + + + + + +X diff --git a/src/draw.svg b/src/draw.svg new file mode 100644 index 0000000..348da8a --- /dev/null +++ b/src/draw.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/i.py b/src/i.py new file mode 100644 index 0000000..5e261d0 --- /dev/null +++ b/src/i.py @@ -0,0 +1,5 @@ +from sabertooth import instigate, line +instigate() +l1=line(length="5cm",label="A,B",color="red",points="P=1:1",showPoints=True) +l2=line(v1=l1.P,angle="90d") +l3=line(x1=10,y1=10,x2=210,y2=10) \ No newline at end of file diff --git a/src/sabertooth.py b/src/sabertooth.py new file mode 100644 index 0000000..454d125 --- /dev/null +++ b/src/sabertooth.py @@ -0,0 +1,346 @@ +import tkinter +import math +length,direction,style="length","direction","style" +root = tkinter.Tk() +root.withdraw() +screenWidth,screenHeight= root.winfo_screenwidth(), root.winfo_screenheight() +cm=screenWidth/40.64 +mm=cm/10 +inch=2.54*cm +path="draw.svg" +file=open(path,"w+") + +def instigate(width=screenWidth,height=screenHeight): + width=str(width) + height=str(height) + file.write('\n\n\n\n') + file.write('\n\n\n') + +class extension: + def __init__(self,length,direction,point="",style="dashed"): + self.length=length + self.point=point + self.direction=direction + self.style=style + +class line: + def __init__(self,length="10",color="black",x1=screenWidth/2,y1=screenHeight/2,angle="0",label=" , ",x2=None,y2=None,showLength=False,style="",thickness=None,v1=(screenWidth/2,screenHeight/2),v2=None,points="",forwardArrow=None,backwardArrow=None,showPoints=False,ext1=None,ext2=None,slope=0,showPointsLabels=False): + self.showPointsLabels=showPointsLabels + self.slope=slope + self.showPoints=showPoints + self.forwardArrow=forwardArrow + self.backwardArrow=backwardArrow + self.points=points + self.thickness=thickness + self.ext1=ext1 + self.ext2=ext2 + self.style=style + self.showLength=showLength + self.label=label + self.angle=angle #angle at x1y1 + self.length=length + self.color=color + self.x1=x1 + self.y1=y1 + self.x2=x2 + self.y2=y2 + self.v1=v1 + self.v2=v2 + if(self.v1!=(screenWidth/2,screenHeight/2)): + self.x1,self.y1=self.v1 + else: + self.v1=(self.x1,self.y1) + self.draw() #draws the line + + def handlePoints(self): + cosValue,sinValue,angle=self.handleAngle() + point=self.points.split(",") + for p in point: + s=p.split("=") + ratio=s[1].split(":") + ratio[0]=int(ratio[0]) + ratio[1]=int(ratio[1]) + x=self.x1+((self.x2-self.x1)*ratio[0]/(ratio[0]+ratio[1])) + y=self.y1+((self.y2-self.y1)*ratio[0]/(ratio[0]+ratio[1])) + setattr(self, s[0], (x,y)) + if(self.showPoints==True): + file.write(f'\n') + if(self.showPointsLabels==True): + textX=x-(10*cosValue) + textY=y+(10*sinValue) + file.write(f'{s[0]}\n') + + def returnStyleInfo(self): + if((self.style).lower()=="dashed"): + styleInfo='stroke-dasharray="5 2" ' + else: + styleInfo="" + return styleInfo + + def handleAngle(self): + if(self.slope!=0): + self.angle=str(math.degrees(math.atan(self.slope))) + angleMeasure="" + angleUnits="" + for character in self.angle: + if(character.isalpha()==0): + angleMeasure=angleMeasure+character + else: + angleUnits=angleUnits+character + angleUnits.lower() + angleMeasure = 0-float(angleMeasure) + if(angleUnits=="d" or angleUnits==""): + sinValue=math.sin(math.radians(angleMeasure)) + cosValue=math.cos(math.radians(angleMeasure)) + else: + sinValue=math.sin(angleMeasure) + cosValue=math.cos(angleMeasure) + angleMeasure = math.degrees(angleMeasure) + return cosValue,sinValue,angleMeasure + + def handleLine(self): + cosValue,sinValue,angleMeasure=self.handleAngle() + measure="" + units="" + for character in self.length: + if(character.isalpha()==0): + measure=measure+character + else: + units=units+character + units.lower() + if(units=="cm"): + measure=int(float(measure)*cm) + elif(units=="inch"): + measure=int(float(measure)*inch) + elif(units=="mm"): + measure=int(float(measure)*mm) + else: + measure=int(float(measure)*cm) + return measure + + def handleLabel(self): + cosValue,sinValue,angleMeasure=self.handleAngle() + individualLabels=self.label.split(',') + labelBeginX=int(self.x1-cosValue*8) #x coordinate of the label for beginning of the line + labelBeginY=int(self.y1+sinValue*8) + labelEndX=int(self.x2+cosValue*8) #x coordinate of the label for the endpoint of the line + labelEndY=int(self.y2-sinValue*8) + labelExpression=f'{individualLabels[0]}\n{individualLabels[1]}\n' + file.write(labelExpression) + setattr(self,individualLabels[0],(self.x1,self.y2)) + setattr(self,individualLabels[1],(self.x2,self.y2)) + + def handleLength(self): + cosValue,sinValue,angleMeasure=self.handleAngle() + lengthOfLength=len(self.length)*8 + textX=(self.x1+self.x2-lengthOfLength)/2 #x coordinate for text tag + textY=(self.y1+self.y2+8)/2 #y coordinate for text tag + if(self.showLength==True): + file.write(f'{self.length}\n') + + def handleExtension(self): + if(not self.ext1==None): + if(self.ext1.direction.lower()=="backward"): + e1=line(color=self.color,x1=self.x1,y1=self.y1,length=self.ext1.length,style=self.ext1.style,angle='-'+self.angle,label=','+self.ext1.point,thickness=self.thickness) + else: + e1=line(color=self.color,x1=self.x2,y1=self.y2,style=self.ext1.style,length=self.ext1.length,angle='-'+self.angle,label=','+self.ext1.point,thickness=self.thickness) + if(not self.ext2==None): + if(self.ext2.direction.lower()=="backward"): + e2=line(color=self.color,x1=self.x1,y1=self.y1,length=self.ext2.length,style=self.ext2.style,angle='-'+self.angle,label=','+self.ext2.point,thickness=self.thickness) + else: + e2=line(color=self.color,x1=self.x2,y1=self.y2,length=self.ext2.length,style=self.ext2.style,angle='-'+self.angle,label=','+self.ext2.point,thickness=self.thickness) + + def handleWidth(self): + if(self.thickness==None): + widthExpression="" + else: + widthExpression=f'stroke-width="{self.thickness}" ' + return widthExpression + + def handleArrows(self): + cosValue,sinValue,angle=self.handleAngle() + if(self.forwardArrow!=None): + arrows=self.forwardArrow.split(",") + for a in arrows: + ar=a.split("=") + arr=ar[0] + ar=ar[1].split(":") + ar[0]=int(ar[0]) + ar[1]=int(ar[1]) + x=self.x1+((self.x2-self.x1)*ar[0]/(ar[0]+ar[1])) + y=self.y1+((self.y2-self.y1)*ar[0]/(ar[0]+ar[1])) + if(x==self.x1): + otherX=int(self.x1-(cosValue*5)) + else: + otherX=self.x1 + if(y==self.y1): + otherY=int(self.y1-(sinValue*5)) + else: + otherY=self.y1 + w=self.width + if(w==None): + w="" + file.write(f'\n') + setattr(self,arr,(x,y)) + if(self.backwardArrow!=None): + arrows=self.backwardArrow.split(",") + for a in arrows: + ar=a.split("=") + arr=ar[0] + ar=ar[1].split(":") + ar[0]=int(ar[0]) + ar[1]=int(ar[1]) + x=self.x1+((self.x2-self.x1)*ar[0]/(ar[0]+ar[1])) + y=self.y1+((self.y2-self.y1)*ar[0]/(ar[0]+ar[1])) + if(x==self.x1): + otherX=int(self.x1+(cosValue*5)) + else: + otherX=self.x1 + if(y==self.y1): + otherY=int(self.y1+(sinValue*5)) + else: + otherY=self.y1 + w=self.width + if(w==None): + w="" + file.write(f'\n') + setattr(self,arr,(x,y)) + + def draw(self): + styleInfo,measure,widthExpression=self.returnStyleInfo(),self.handleLine(),self.handleWidth() + cosValue,sinValue,angleMeasure=self.handleAngle() + if(self.v2!=None): + self.x2,self.y2=self.v2 + else: + if(self.y2==None): + self.y2=int(self.y1+(sinValue*measure)) #because it may get into non-terminating, non-reckering decimal values + if(self.x2==None): + self.x2=int(self.x1+(cosValue*measure)) + self.v2=(self.x2,self.y2) + if(self.x2==self.x1): + if(self.y2\n') + self.handleLabel() + self.handleLength() + self.handleExtension() + self.handleArrows() + if(self.points!=""): + self.handlePoints() + +#circle code +class circle: + def __init__(self,x1=screenWidth/2,y1=screenHeight/2,center=(screenWidth/2,screenHeight/2),radius="2.5cm",color="black",thickness=None,fill=None,drawRadii=None,label=None,chords=None,points=None,showPoints=False,showPointsLabels=False,tangents=None,sectors=None): + self.points=points + self.showPoints=showPoints + self.showPointsLabels=showPointsLabels + self.tangents=tangents + self.sectors=sectors + self.x1=x1 + self.y1=y1 + self.color=color + self.fill=fill + self.thickness=thickness + if(self.x1!=screenWidth/2 and self.y1!=screenHeight/2): + self.center=(self.x1,self.y1) + elif(self.x1!=screenWidth/2): + self.center=(self.x1,screenHeight/2) + elif(self.y1!=screenHeight/2): + self.center(screenWidth/2,self.y2) + else: + self.center=center + self.radius=radius + self.drawRadii=drawRadii + self.chords=chords + self.draw() + + def handleRadius(self): + measure="" + units="" + for character in self.radius: + if(character.isalpha()==0): + measure=measure+character + else: + units=units+character + units.lower() + if(units=="cm"): + measure=int(float(measure)*cm) + elif(units=="inch"): + measure=int(float(measure)*inch) + elif(units=="mm"): + measure=int(float(measure)*mm) + else: + measure=int(float(measure)*cm) + return measure + + def handleDrawRadii(self): + if(self.drawRadii==None): + return + individuals=self.drawRadii.split(",") + for x in individuals: + l=line(v1=self.center,color=self.color,thickness=self.thickness,angle="-"+x,length=self.radius) + + def handlePoints(self,radiusLength): + if(self.points==None): + return + individuals=self.points.split(",") + for x in individuals: + measure="" + unit="" + z=x.split("=") + for y in z[1]:#processing angles + if(y.isalpha()==0): + unit=unit+y + else: + measure=measure+y + if(unit!='r' or unit!='R'): + measure=math.radians(float(measure)) + x=self.x1+math.cos(measure)*radiusLength + y=self.y1-math.sin(measure)*radiusLength + setattr(self,z[0],(x,y)) + if(self.showPoints==True): + file.write(f'\n') + if(self.showPointsLabels==True): + file.write(f'{z[0]}\n') + + def handleTangents(self,radiusLength): + if(self.tangents==None): + return + individuals=self.tangents.split(",") + for z in individuals: + x=math.cos(math.radians(float(z)))*radiusLength+self.x1 + y=math.sin(math.radians(float(z)))*radiusLength+self.y1 + l=line(v1=(x,y),angle=z+90,length=self.radius,color=self.color,thickness=self.thickness) + + def handleChords(self,radiusLength): + if(self.chords==None): + return + for individual in self.chords: + x1=radiusLength*math.cos(math.radians(individual[0]))+self.x1 + x2=radiusLength*math.cos(math.radians(individual[1]))+self.x1 + y1=self.y1-radiusLength*math.sin(math.radians(individual[0])) + y2=self.y1-radiusLength*math.sin(math.radians(individual[1])) + l=line(v1=(x1,y1),v2=(x2,y2),color=self.color,thickness=self.thickness) + + def handleSectors(self): + if(self.sectors==None): + return + for individual in self.sectors: + l1=line(v1=self.center,length=self.radius,angle=str(individual[0]),color=self.color,thickness=self.thickness) + l2=line(v1=self.center,angle=str(individual[1]),length=self.radius,color=self.color,thickness=self.thickness) + + def draw(self): + radiusLength=self.handleRadius() + file.write(f'') + self.handleDrawRadii() + self.handlePoints(radiusLength) + self.handleTangents(radiusLength) + self.handleChords(radiusLength) + self.handleSectors() \ No newline at end of file diff --git a/src/t.py b/src/t.py new file mode 100644 index 0000000..0f62f4a --- /dev/null +++ b/src/t.py @@ -0,0 +1,3 @@ +from sabertooth import instigate, line, circle +instigate() +c=circle(sectors=[(30,60),(60,90)]) diff --git a/src/test.py b/src/test.py new file mode 100644 index 0000000..7d83568 --- /dev/null +++ b/src/test.py @@ -0,0 +1,4 @@ +from sabertooth import instigate, line, extension +instigate() +l1=line(label="A,Alakazam") +l2=line(v1=l1.A,v2=l1.Alakazam) \ No newline at end of file