;; A program to draw different classic tetris blocks in mock-3D
;; by Eli Bocek-Rivele
;;draw-cube draws one mock-3D cube and takes 2 parameters
;; topleft is the topleft corner of the cube (of type position), and color is its line color
;; example usage is (draw-cube (make-posn 100 100) 'red)
(define (draw-cube topleft color)
(and
(draw-solid-line topleft (make-posn (+ (posn-x topleft) 50)
(posn-y topleft)) color)
(draw-solid-line topleft (make-posn (posn-x topleft)
(+ (posn-y topleft) 50)) color)
(draw-solid-line topleft (make-posn (+ (posn-x topleft) 35)
(+ (posn-y topleft) 35)) color)
(draw-solid-line (make-posn (+ 50 (posn-x topleft)) (posn-y topleft))
(make-posn (+ (posn-x topleft) 85) (+ (posn-y topleft) 35)) color)
(draw-solid-line (make-posn (posn-x topleft) (+ 50 (posn-y topleft)))
(make-posn (+ 35 (posn-x topleft)) (+ (posn-y topleft) 85)) color)
(draw-solid-line (make-posn (+ 50 (posn-x topleft)) (+ 50 (posn-y topleft)))
(make-posn (+ 85 (posn-x topleft)) (+ (posn-y topleft) 85)) color)
(draw-solid-line (make-posn (posn-x topleft) (+ 50 (posn-y topleft)))
(make-posn (+ 50 (posn-x topleft)) (+ 50 (posn-y topleft))) color)
(draw-solid-line (make-posn (+ 50 (posn-x topleft)) (posn-y topleft))
(make-posn (+ 50 (posn-x topleft)) (+ 50 (posn-y topleft))) color)
(draw-solid-line (make-posn (+ 35 (posn-x topleft)) (+ 35 (posn-y topleft)))
(make-posn (+ 35 (posn-x topleft)) (+ 85 (posn-y topleft))) color)
(draw-solid-line (make-posn (+ 35 (posn-x topleft)) (+ 35 (posn-y topleft)))
(make-posn (+ 85 (posn-x topleft)) (+ 35 (posn-y topleft))) color)
(draw-solid-line (make-posn (+ 35 (posn-x topleft)) (+ 85 (posn-y topleft)))
(make-posn (+ 85 (posn-x topleft)) (+ 85 (posn-y topleft))) color)
(draw-solid-line (make-posn (+ 85 (posn-x topleft)) (+ 35 (posn-y topleft)))
(make-posn (+ 85 (posn-x topleft)) (+ 85 (posn-y topleft))) color)
) )
;;draw-tetris-shape calls draw-cube multiple times to create the tetris shapes
;;it takes 3 parameters, shape is which tetris shape you want
;;t-posn is the position around which the shape will be created, of type position
;;color is the color of the whole shape
;;example usage: (draw-tetris-shape 1 (make-posn 200 100) 'red)
;;here are the different shapes and how they match up to their number
;; 1 is the upside-down T shape
;; 2 is the L shape
;; 3 is the backwards-L shape
;; 4 is the block
;; 5 is the straight line
(define (draw-tetris-shape shape t-posn color)
(cond
[(= shape 1) (and
(draw-cube (make-posn (posn-x t-posn) (+ (posn-y t-posn) 50)) color)
(draw-cube (make-posn (+ (posn-x t-posn) 50) (+ (posn-y t-posn) 50)) color)
(draw-cube (make-posn (+ (posn-x t-posn) 100) (+ (posn-y t-posn) 50)) color)
(draw-cube (make-posn (+ (posn-x t-posn) 50) (posn-y t-posn)) color) )]
[(= shape 2) (and
(draw-cube t-posn color)
(draw-cube (make-posn (posn-x t-posn) (+ (posn-y t-posn) 50)) color)
(draw-cube (make-posn (posn-x t-posn) (+ (posn-y t-posn) 100)) color)
(draw-cube (make-posn (+ (posn-x t-posn) 50) (+ (posn-y t-posn) 100)) color) )]
[(= shape 3) (and
(draw-cube (make-posn (+ (posn-x t-posn) 50) (posn-y t-posn)) color)
(draw-cube (make-posn (+ (posn-x t-posn) 50) (+ (posn-y t-posn) 50)) color)
(draw-cube (make-posn (+ (posn-x t-posn) 50) (+ (posn-y t-posn) 100)) color)
(draw-cube (make-posn (posn-x t-posn) (+ (posn-y t-posn) 100)) color) )]
[(= shape 4) (and
(draw-cube t-posn color)
(draw-cube (make-posn (posn-x t-posn) (+ (posn-y t-posn) 50)) color)
(draw-cube (make-posn (+ (posn-x t-posn) 50) (posn-y t-posn)) color)
(draw-cube (make-posn (+ (posn-x t-posn) 50) (+ (posn-y t-posn) 50)) color) )]
[else (and
(draw-cube t-posn color)
(draw-cube (make-posn (+ (posn-x t-posn) 50) (posn-y t-posn)) color)
(draw-cube (make-posn (+ (posn-x t-posn) 100) (posn-y t-posn)) color)
(draw-cube (make-posn (+ (posn-x t-posn) 150) (posn-y t-posn)) color) )] ))
;;here i'm starting a canvas for my sample cases
;; (start 700 400)
;;draw all of the shapes in different colors and places, an example
;;(draw-tetris-shape 1 (make-posn 200 100) 'red)
;;(draw-tetris-shape 2 (make-posn 400 100) 'blue)
;;(draw-tetris-shape 3 (make-posn 550 100) 'green)
;;(draw-tetris-shape 4 (make-posn 200 250) 'black)
;;(draw-tetris-shape 5 (make-posn 350 300) 'yellow)