Explore
Courses
Batches
Sketches
Statistics
Code a Pookkalam
Jobs
Devsprint
People
Course Creation
Create a Course
Guidelines
Resources
Support
Blogs
My Profile
About Us
Login
Sketches
0
Tetris
By
Anand Chitipothu
Run
cw = 30 colors = [ ["#ddd", "#bbb"], ["#aaa", "#888"], ["#777", "#555"] ] cells = """ ------------ ------------ ------------ -----11----- -----1----- --------1--- ---0-1--10-- 110011210011 210112122001 ------------ ------------ """ cells = cells.strip().splitlines() n = len(cells[0]) cw = 300/n def cell(row, col, color): x = col*cw+cw/2 y = row*cw+cw/2 c1, c2 = colors[color] r1 = rectangle(x=x, y=y, w=cw, h=cw, fill=c1, stroke="none") r2 = rectangle(x=x, y=y, w=cw/2, h=cw/2, fill=c2, stroke="none") return r1+r2 bg = rectangle(w=300, h=300, fill="white", stroke="none") show(bg) empty = rectangle(w=0, h=0, fill="none", stroke="none") def make_shape(ri, ci, value): if value == "-": return empty else: return cell(ri, ci, int(value)) shapes = [make_shape(ri, ci, v) for ri, row in enumerate(cells) for ci, v in enumerate(row)] shape = combine(shapes) | translate(x=-150, y=-150) | scale(y=-1) show(shape)
Comments
Want to discuss?
Post it here, our mentors will help you out.
Login