Code Sketch


Tangram Shape
By: Harsh Karpe
Category: Art
clear()
showAxes()


def square = Picture{
    right(135)
    forward(70.71)
    right(90)
    forward(70.71)
    right(90)
    forward(70.71)
    right(90)
    forward(70.71)
    right(90)
}.thatsStrokeColored(black)

def triangle1 = Picture{
    right()
    forward(100)
    left(135)
    forward(70.71)
    left(90)
    forward(70.71)   
}.thatsStrokeColored(black)

def triangle2 = Picture{
    right(135)
    forward(141.42)
    left(135)
    forward(200)
    left(135)
    forward(141.42)
}.thatsStrokeColored(black)

def triangle3 = Picture{
    left(45)
    forward(70.71)
    left(135)
    forward(100)
    left(135)
    forward(70.71)
}.thatsStrokeColored(black)

def parallelogram = Picture{
    forward(100)
    right(135)
    forward(70.71)
    right(45)
    forward(100)
    right(135)
    forward(70.71)
}.thatsStrokeColored(black)

def triangle4 = Picture {
    left(45)
    forward(141.42)
    left(135)
    forward(100)
    left(90)
    forward(100)
}.thatsStrokeColored(black)


def shape= picStack(
    Picture{},
square.thatsFilledWith(red).thatsRotated(0).thatsTranslated(-50,0),
triangle2.thatsFilledWith(yellow).thatsRotated(-90).thatsTranslated(-100,-50),
triangle2.thatsFilledWith(blue).thatsRotated(-90).thatsTranslated(100,-50),
triangle3.thatsFilledWith(pink).thatsRotated(-90).thatsTranslated(0,-150),
parallelogram.thatsFilledWith(green).thatsRotated(-90).thatsTranslated(0,-50),
triangle4.thatsFilledWith(Color(255, 153, 0)).thatsRotated(0).thatsTranslated(100,-50),
triangle3.thatsFilledWith(Color(0, 255, 255)).thatsRotated(180).thatsTranslated(-50,0)
            )

shape.draw