代写一个绘图程序,根据文本文件中的内容,根据算法生成对应的图形。
General presentation
You will design and implement a program that will
- extract and analyse the various characteristics of (simple) polygons, their contours being coded and stored in a file, and
- either display those characteristics: perimeter, area, convexity, number of rotations that keep the polygon invariant, and depth (the length of the longest chain of enclosing polygons)
- or output some Latex code, to be stored in a file, from which a pictorial representation of the polygons can be produced, coloured in a way which is proportional to their area.
Call encoding any 2-dimensional grid of size between between 2 2 and 50 50 (both dimensions can be dierent) all of whose elements are either 0 or 1.
Call neighbour of a member m of an encoding any of the at most eight members of the grid whose value is 1 and each of both indexes diers from ms corresponding index by at most 1. Given a particular encoding, we inductively define for all natural numbers d the set of polygons of depth d (for this encoding) as follows. Let a natural number d be given, and suppose that for all d0 < d
, the set of polygons of depth d0 has been defined. Change in the encoding all 1s that determine those polygons to 0. Then the set of polygons of depth d is defined as the set of polygons which can be obtained from that encoding by connecting 1s with some of their neighbours in such a way that we obtain a maximal polygon (that is, a polygon which is not included in any other polygon obtained from that encoding by connecting 1s with some of their neighbours).
Submission
Your programs will be stored in a file named polygons.py. After you have developed and tested your program, upload your files using Ed. Assignments can be submitted more than once: the last version is marked.
Assessment
The assignment is worth 10 marks. the automarking script will allocate 30 seconds to each run of your program.
Late assignments will be penalised: the mark for a late submission will be the minimum of the awarded mark and 10 minus the number of full and partial days that have elapsed from the due date.
The outputs of your programs should be exactly as indicated.
Examples
First example
Given a file named polys_1.txt whose contents is
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
your program when run as python3 polygons.py file polys_1.txt should output
Polygon 1:Perimeter: 78.4Area: 384.16Convex: yesNb of invariant rotations: 4Depth: 0Polygon 2:Perimeter: 75.2Area: 353.44Convex: yesNb of invariant rotations: 4Depth: 1Polygon 3:Perimeter: 72.0Area: 324.00Convex: yesNb of invariant rotations: 4Depth: 2Polygon 4:Perimeter: 68.8Area: 295.84Convex: yesNb of invariant rotations: 4Depth: 3Polygon 5:Perimeter: 65.6Area: 268.96Convex: yesNb of invariant rotations: 4Depth: 4Polygon 6:Perimeter: 62.4Area: 243.36Convex: yesNb of invariant rotations: 4Depth: 5Polygon 7:Perimeter: 59.2Area: 219.04Convex: yesNb of invariant rotations: 4Depth: 6Polygon 8:Perimeter: 56.0Area: 196.00Convex: yesNb of invariant rotations: 4Depth: 7Polygon 9:Perimeter: 52.8Area: 174.24Convex: yesNb of invariant rotations: 4Depth: 8Polygon 10:Perimeter: 49.6Area: 153.76Convex: yesNb of invariant rotations: 4Depth: 9Polygon 11:Perimeter: 46.4Area: 134.56Convex: yesNb of invariant rotations: 4Depth: 10Polygon 12:Perimeter: 43.2Area: 116.64Convex: yesNb of invariant rotations: 4Depth: 11Polygon 13:Perimeter: 40.0Area: 100.00Convex: yesNb of invariant rotations: 4Depth: 12Polygon 14:Perimeter: 36.8Area: 84.64Convex: yesNb of invariant rotations: 4Depth: 13Polygon 15:Perimeter: 33.6Area: 70.56Convex: yesNb of invariant rotations: 4Depth: 14Polygon 16:Perimeter: 30.4Area: 57.76Convex: yesNb of invariant rotations: 4Depth: 15Polygon 17:Perimeter: 27.2Area: 46.24Convex: yesNb of invariant rotations: 4Depth: 16Polygon 18:Perimeter: 24.0Area: 36.00Convex: yesNb of invariant rotations: 4Depth: 17Polygon 19:Perimeter: 20.8Area: 27.04Convex: yesNb of invariant rotations: 4Depth: 18Polygon 20:Perimeter: 17.6Area: 19.36Convex: yesNb of invariant rotations: 4Depth: 19Polygon 21:Perimeter: 14.4Area: 12.96Convex: yesNb of invariant rotations: 4Depth: 20Polygon 22:Perimeter: 11.2Area: 7.84Convex: yesNb of invariant rotations: 4Depth: 21Polygon 23:Perimeter: 8.0Area: 4.00Convex: yesNb of invariant rotations: 4Depth: 22Polygon 24:Perimeter: 4.8Area: 1.44Convex: yesNb of invariant rotations: 4Depth: 23Polygon 25:Perimeter: 1.6Area: 0.16Convex: yesNb of invariant rotations: 4Depth: 24
and when run as python3 polygons.py -print file polys_1.txt should produce some output saved in a file named polys_1.tex, which can be given as argument to pdflatex to produce a file named polys_1.pdf that views as follows.
Second example
Given a file named polys_2.txt whose contents is
00000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111100011111111111111111111111111111111111111111111110000011111111111111111111111111111111111111111111000010011111111111111111111111111111111111111111100100110011111111111111111111111111111111111111110011001110011111111111111111111111111111111111111001110011110011111111111111111111111111111111111100111100111110011111111111111111111111111111111110011111001111110011111111111111111111111111111111001111110011111110011111111111111111111111111111100111111100111111110011111111111111111111111111110011111111001111111110011111111111111111111111111001111111110011111111110011111111111111111111111100111111111100111111111110011111111111111111111110011111111111001111111111110011111111111111111111001111111111110011111111111110011111111111111111100111111111111100111111111111110011111111111111110011111111111111001111111111111110011111111111111001111111111111110011111111111111110011111111111100111111111111111100111111111111111110011111111110011111111111111111001111111111111111110011111111001111111111111111110011111111111111111110011111100111111111111111111100111111111111111111110011110011111111111111111111001111111111011111111110011001111111111011111111110011111111111111111111001111001111111111111111111100111111111111111111100111111001111111111111111111001111111111111111110011111111001111111111111111110011111111111111111001111111111001111111111111111100111111111111111100111111111111001111111111111111001111111111111110011111111111111001111111111111110011111111111111001111111111111111001111111111111100111111111111100111111111111111111001111111111111001111111111110011111111111111111111001111111111110011111111111001111111111111111111111001111111111100111111111100111111111111111111111111001111111111001111111110011111111111111111111111111001111111110011111111001111111111111111111111111111001111111100111111100111111111111111111111111111111001111111001111110011111111111111111111111111111111001111110011111001111111111111111111111111111111111001111100111100111111111111111111111111111111111111001111001110011111111111111111111111111111111111111001110011001111111111111111111111111111111111111111001100100111111111111111111111111111111111111111111001000011111111111111111111111111111111111111111111000001111111111111111111111111111111111111111111111000111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000
your program when run as python3 polygons.py file polys_2.txt should output
Polygon 1:Perimeter: 37.6 + 92*sqrt(.32)Area: 176.64Convex: noNb of invariant rotations: 2Depth: 0Polygon 2:Perimeter: 17.6 + 42*sqrt(.32)Area: 73.92Convex: yesNb of invariant rotations: 1Depth: 1Polygon 3:Perimeter: 16.0 + 38*sqrt(.32)Area: 60.80Convex: yesNb of invariant rotations: 1Depth: 2Polygon 4:Perimeter: 16.0 + 40*sqrt(.32)Area: 64.00Convex: yesNb of invariant rotations: 1Depth: 0Polygon 5:Perimeter: 14.4 + 34*sqrt(.32)Area: 48.96Convex: yesNb of invariant rotations: 1Depth: 3Polygon 6:Perimeter: 16.0 + 40*sqrt(.32)Area: 64.00Convex: yesNb of invariant rotations: 1Depth: 0Polygon 7:Perimeter: 12.8 + 30*sqrt(.32)Area: 38.40Convex: yesNb of invariant rotations: 1Depth: 4Polygon 8:Perimeter: 14.4 + 36*sqrt(.32)Area: 51.84Convex: yesNb of invariant rotations: 1Depth: 1Polygon 9:Perimeter: 11.2 + 26*sqrt(.32)Area: 29.12Convex: yesNb of invariant rotations: 1Depth: 5Polygon 10:Perimeter: 14.4 + 36*sqrt(.32)Area: 51.84Convex: yesNb of invariant rotations: 1Depth: 1Polygon 11:Perimeter: 9.6 + 22*sqrt(.32)Area: 21.12Convex: yesNb of invariant rotations: 1Depth: 6Polygon 12:Perimeter: 12.8 + 32*sqrt(.32)Area: 40.96Convex: yesNb of invariant rotations: 1Depth: 2Polygon 13:Perimeter: 8.0 + 18*sqrt(.32)Area: 14.40Convex: yesNb of invariant rotations: 1Depth: 7Polygon 14:Perimeter: 12.8 + 32*sqrt(.32)Area: 40.96Convex: yesNb of invariant rotations: 1Depth: 2Polygon 15:Perimeter: 6.4 + 14*sqrt(.32)Area: 8.96Convex: yesNb of invariant rotations: 1Depth: 8Polygon 16:Perimeter: 11.2 + 28*sqrt(.32)Area: 31.36Convex: yesNb of invariant rotations: 1Depth: 3Polygon 17:Perimeter: 4.8 + 10*sqrt(.32)Area: 4.80Convex: yesNb of invariant rotations: 1Depth: 9Polygon 18:Perimeter: 11.2 + 28*sqrt(.32)Area: 31.36Convex: yesNb of invariant rotations: 1Depth: 3Polygon 19:Perimeter: 3.2 + 6*sqrt(.32)Area: 1.92Convex: yesNb of invariant rotations: 1Depth: 10Polygon 20:Perimeter: 9.6 + 24*sqrt(.32)Area: 23.04Convex: yesNb of invariant rotations: 1Depth: 4Polygon 21:Perimeter: 1.6 + 2*sqrt(.32)Area: 0.32Convex: yesNb of invariant rotations: 1Depth: 11Polygon 22:Perimeter: 9.6 + 24*sqrt(.32)Area: 23.04Convex: yesNb of invariant rotations: 1Depth: 4Polygon 23:Perimeter: 8.0 + 20*sqrt(.32)Area: 16.00Convex: yesNb of invariant rotations: 1Depth: 5Polygon 24:Perimeter: 8.0 + 20*sqrt(.32)Area: 16.00Convex: yesNb of invariant rotations: 1Depth: 5Polygon 25:Perimeter: 6.4 + 16*sqrt(.32)Area: 10.24Convex: yesNb of invariant rotations: 1Depth: 6Polygon 26:Perimeter: 6.4 + 16*sqrt(.32)Area: 10.24Convex: yesNb of invariant rotations: 1Depth: 6Polygon 27:Perimeter: 4.8 + 12*sqrt(.32)Area: 5.76Convex: yesNb of invariant rotations: 1Depth: 7Polygon 28:Perimeter: 4.8 + 12*sqrt(.32)Area: 5.76Convex: yesNb of invariant rotations: 1Depth: 7Polygon 29:Perimeter: 3.2 + 8*sqrt(.32)Area: 2.56Convex: yesNb of invariant rotations: 1Depth: 8Polygon 30:Perimeter: 3.2 + 8*sqrt(.32)Area: 2.56Convex: yesNb of invariant rotations: 1Depth: 8Polygon 31:Perimeter: 1.6 + 4*sqrt(.32)Area: 0.64Convex: yesNb of invariant rotations: 1Depth: 9Polygon 32:Perimeter: 1.6 + 4*sqrt(.32)Area: 0.64Convex: yesNb of invariant rotations: 1Depth: 9Polygon 33:Perimeter: 17.6 + 42*sqrt(.32)Area: 73.92Convex: yesNb of invariant rotations: 1Depth: 1Polygon 34:Perimeter: 16.0 + 38*sqrt(.32)Area: 60.80Convex: yesNb of invariant rotations: 1Depth: 2Polygon 35:Perimeter: 14.4 + 34*sqrt(.32)Area: 48.96Convex: yesNb of invariant rotations: 1Depth: 3Polygon 36:Perimeter: 12.8 + 30*sqrt(.32)Area: 38.40Convex: yesNb of invariant rotations: 1Depth: 4Polygon 37:Perimeter: 11.2 + 26*sqrt(.32)Area: 29.12Convex: yesNb of invariant rotations: 1Depth: 5Polygon 38:Perimeter: 9.6 + 22*sqrt(.32)Area: 21.12Convex: yesNb of invariant rotations: 1Depth: 6Polygon 39:Perimeter: 8.0 + 18*sqrt(.32)Area: 14.40Convex: yesNb of invariant rotations: 1Depth: 7Polygon 40:Perimeter: 6.4 + 14*sqrt(.32)Area: 8.96Convex: yesNb of invariant rotations: 1Depth: 8Polygon 41:Perimeter: 4.8 + 10*sqrt(.32)Area: 4.80Convex: yesNb of invariant rotations: 1Depth: 9Polygon 42:Perimeter: 3.2 + 6*sqrt(.32)Area: 1.92Convex: yesNb of invariant rotations: 1Depth: 10Polygon 43:Perimeter: 1.6 + 2*sqrt(.32)Area: 0.32Convex: yesNb of invariant rotations: 1Depth: 11
and when run as python3 polygons.py -print file polys_2.txt should produce some output saved in a file named polys_2.tex, which can be given as argument to pdflatex to produce a file named polys_2.pdf that views as follows.
Third example
Given a file named polys_3.txt whose contents is
0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 01 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 10 1 0 0 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 0 1 0 0 1 00 1 0 0 0 1 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 0 0 0 1 00 0 1 0 0 1 0 0 0 0 1 0 0 1 1 0 1 0 0 0 0 0 0 1 0 1 1 0 0 1 0 0 0 0 1 0 0 1 0 00 0 1 0 0 1 0 0 0 0 1 0 0 1 0 1 0 0 1 1 1 1 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 1 0 00 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 00 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 00 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 1 0 0 0 0 1 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 01 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 11 1 0 1 0 1 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 0 1 0 1 1 0 0 0 1 0 0 1 0 1 0 1 0 1 11 1 1 0 1 0 1 0 1 0 1 0 0 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 0 1 0 1 1 11 1 0 0 1 1 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 0 1 1 0 0 0 1 0 1 0 1 1 1 0 0 1 11 1 0 0 1 0 1 0 1 0 1 0 0 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 0 1 0 0 1 11 1 0 0 1 0 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 0 1 1 0 0 0 1 0 1 0 1 0 1 0 0 1 11 1 0 0 1 0 1 0 1 0 1 0 0 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 0 1 0 0 1 11 1 1 0 1 1 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 0 1 1 0 0 0 1 0 1 0 1 1 1 0 1 1 11 1 0 1 0 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 0 1 0 0 1 0 1 0 1 0 1 11 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 0 1 0 0 0 0 1 0 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 10 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 00 0 0 1 0 0 0 0 0 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0 0 00 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 1 1 1 1 1 1 1 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 00 0 1 0 0 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 1 0 00 0 1 0 0 1 0 0 0 0 1 0 0 1 1 0 1 0 0 0 0 0 0 1 0 1 1 0 0 1 0 0 0 0 1 0 0 1 0 00 1 0 0 0 1 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 0 0 0 1 00 1 0 0 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 0 1 0 0 1 01 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 10 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 0
your program when run as python3 polygons.py file polys_3.txt should output
Polygon 1:Perimeter: 2.4 + 9*sqrt(.32)Area: 2.80Convex: noNb of invariant rotations: 1Depth: 0Polygon 2:Perimeter: 51.2 + 4*sqrt(.32)Area: 117.28Convex: noNb of invariant rotations: 2Depth: 0Polygon 3:Perimeter: 2.4 + 9*sqrt(.32)Area: 2.80Convex: noNb of invariant rotations: 1Depth: 0Polygon 4:Perimeter: 17.6 + 40*sqrt(.32)Area: 59.04Convex: noNb of invariant rotations: 2Depth: 1Polygon 5:Perimeter: 3.2 + 28*sqrt(.32)Area: 9.76Convex: noNb of invariant rotations: 1Depth: 2Polygon 6:Perimeter: 27.2 + 6*sqrt(.32)Area: 5.76Convex: noNb of invariant rotations: 1Depth: 2Polygon 7:Perimeter: 4.8 + 14*sqrt(.32)Area: 6.72Convex: noNb of invariant rotations: 1Depth: 1Polygon 8:Perimeter: 4.8 + 14*sqrt(.32)Area: 6.72Convex: noNb of invariant rotations: 1Depth: 1Polygon 9:Perimeter: 3.2 + 2*sqrt(.32)Area: 1.12Convex: yesNb of invariant rotations: 1Depth: 2Polygon 10:Perimeter: 3.2 + 2*sqrt(.32)Area: 1.12Convex: yesNb of invariant rotations: 1Depth: 2Polygon 11:Perimeter: 2.4 + 9*sqrt(.32)Area: 2.80Convex: noNb of invariant rotations: 1Depth: 0Polygon 12:Perimeter: 2.4 + 9*sqrt(.32)Area: 2.80Convex: noNb of invariant rotations: 1Depth: 0
and when run as python3 polygons.py -print file polys_3.txt should produce some output saved in a file named polys_3.tex, which can be given as argument to pdflatex to produce a file named polys_3.pdf that views as follows.
Detailed description
Input
The input is expected to consist of ydim lines of xdim 0s and 1s, where xdim and ydim are at least equal to 2 and at most equal to 50, with possibly lines consisting of spaces only that will be ignored and with possibly spaces anywhere on the lines with digits. If n is the xth digit of the yth line with digits, with 0 < x < xdim
and 0 < y < ydim
, then n is to be associated with a point situated x * 0.4 cm to the right and y * 0.4 cm below an origin.
Output
The program should be run as either
python3 polygons.py --file filename.txt
or as
python3 polygons.py -print --file filename.txt
(where filename.txt is the name of a file that stores the input). You can study the program ascii_art.py from Lecture 7 to find out how this can be done.
If the input is incorrect, that is, does not satisfy the conditions spelled out in the previous section, then the program should print out a single line that reads
Incorrect input.
and immediately exit.
When the program is run without -print as command-line argument
If the input is correct, then the program should output a first line that reads one of
Cannot get polygons as expected.
in case it is not possible to use all 1s in the input and make them the contours of polygons of depth d, for any natural number d, as defined in the general presentation.
Otherwise, the program should output a first line that reads
Polygon N:
with N an appropriate integer at least equal to 1 to refer to the Nth polygon listed in the order of polygons with highest point from smallest value of y to largest value of y, and for a given value of y, from smallest value of x to largest value of x, a second line that reads one of
Perimeter: a + b*sqrt(.32)Perimeter: aPerimeter: b*sqrt(.32)
with a an appropriate strictly positive floating point number with 1 digit after the decimal point and b an appropriate strictly positive integer, a third line that reads
Area: a
with a an appropriate floating point number with 2 digits after the decimal point, a fourth line that reads one of
Convex: yesConvex: no
a fifth line that reads
Nb of invariant rotations: N
with N an appropriate integer at least equal to 1, and a sixth line that reads
Depth: N
with N an appropriate positive integer (possibly 0).
Pay attention to the expected format, including spaces. Note that your program should output no blank line. For a given test, the output of your program will be compared with the expected output; your program will pass the test if and only if both outputs are absolutely identical, character for character, including spaces. For the provided examples, the expected outputs are available in files that end in _output.txt. To check that the output of your program on those examples is correct, you can redirect it to a file and compare the contents of that file with the contents of the appropriate _output.txt file using the diff command. If diff silently exits then your program passes the test; otherwise it fails it. For instance, run
python3 polygons.py --file polys_1.txt > polys_1_my_output.txt
and then
diff polys_1_my_output.txt polys_1_output.txt
to check whether your program succeeds on the first provided example.
When the program is run with -print as command-line argument
If the input is correct, then the program should output some lines saved in a file named filename.tex, that can be given as an argument to pdflatex to produce a file named filename.pdf that depicts the maze. The provided examples will show you what filename.tex should contain.
- Polygons are drawn from lowest to highest depth, and for a given depth, the same ordering as previously described is used.
- The point that determines the polygon index is used as a starting point in drawing the line segments that make up the polygon, in a clockwise manner.
- A polygonss colour is determined by its area. The largest polygons are yellow. The smallest polygons are orange. Polygons in-between mix orange and yellow in proportion of their area. For instance, a polygon whose size is 25% the dierence of the size between the largest and the smallest polygon will receive 25% of orange (and 75% of yellow). That proportion is computed as an integer. When the value is not an integer, it is rounded to the closest integer, with values of the form z.5 rounded up to z + 1.
Pay attention to the expected format, including spaces and blank lines. Lines that start with % are comments. The contents of the file output by your program will be compared with the expected output (saved in a file of a dierent name of course) using the diff command. For your program to pass the associated test, diff should silently exit, which requires that the contents of both files be absolutely identical, character for character, including spaces and blank lines. Check your program on the provided examples using the associated .tex files. For instance, rename the provided file polys_1.tex to polys_1_expected.tex, and then run
python3 polygons.py -print --file polys_1.txt
and then
diff polys_1.tex polys_1_expected.tex
to check whether your program succeeds on the first provided example.