McHefs 3D Logo

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian as well.
Chef has opened a new fast food chain  McHefs. He engaged the best logo designers of country to build a cool 3D logo for the new restaurants. Later he realised that he can't print 3D logo on menu, neon signboard, website etc. So he has asked you to make a 2D version of the 3D logo. You will be using a 320px × 240px (columns × lines) canvas to produce the 2D logo.
The logo is made using only triangles and quadrilaterals (convex and concave, but not selfintersecting). These polygons meet the following rules:
1) They may be tilted in any direction.
2) They have a solid colour. There are 9 colours numbered from 1 to 9.
3) They are allowed to intersect.
One logo which appeared during designing:
Notice the "jaggies"(jagged edges) in image; they are unavoidable hence acceptable in solution.
The XYZ axis are oriented as:
Note that +Z axis is coming out.
Important points:
1. If value of 2 polygons are exactly same, then the greater color value of two will be visible. Example at end (in Notes)
2. The edges of triangle or quadrilateral should be as accurate as if drawn by Bresenham's algorithm. Note that you don't have to implement Bresenham's algorithm, any approach which doesn't suffers from floating point error is acceptable. Also when rounding off X or Y whose decimal part is exactly 0.5, you have to round up. Like 21.5 becomes 22.
Input
First line contains N, the number of polygons (triangles and quadrilaterals). Then N lines follow, each consists of T the type of polygon, C the color of polygon and 3D coordinates of polygon <X, Y, Z>.
When T is 1, the polygon is Triangle and 3 coordinates are given for the triangle's vertices. When T is 2, the polygon is Quadrilateral and 4 coordinates are given for the quadrilateral's vertices.
Output
Output 240 lines, each containing 320 characters to describe the canvas. The background color of canvas is '0'. The i^{th}(i starts from 0) character on j^{th}(j starts from 0) line should have color value visible at <i, j>
Constraints
 1 ≤ N ≤ 1000
 1 ≤ T ≤ 2
 1 ≤ C ≤ 9
 0 ≤ X ≤ 319
 0 ≤ Y ≤ 239
 1000 ≤ Z ≤ 1000
Example
Input: 4 1 1 120 50 10 50 130 20 180 140 10 1 2 200 45 10 55 70 20 140 150 15 2 5 20 20 0 200 20 0 200 200 0 20 200 0 2 8 30 30 1 50 50 1 70 30 1 50 90 1 Output: Download the output
Notes
If <X, Y, Z> value of 2 polygons are exactly same, then the greater color value of two will be visible. Example, for the following input:
2 2 1 10 10 0 10 110 0 110 110 0 110 10 0 2 2 50 50 0 50 150 0 150 150 0 150 50 0
The (pictorial) output will be:
assuming color '0' is black, color '1' is red, color '2' is blue.
Author:  vinayak garg 
Tester:  gerald 
Editorial  http://discuss.codechef.com/problems/LOGO 
Tags  cook45, geometry, implementation, mediumhard, vinayak garg 
Date Added:  23022013 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 