Last night Santa did a test run over Norway but dropped 3 presents. The number of trees each present is touching determines today's 3-digit answer:
red = 100's digit
blue = 10's digit
yellow = 1's digit
The code below generates the forest from the list of x, y, w & h values stored in the variable 'trees', via supplied functions draw_rect, draw_triangle and draw_tree.
Your job is to position the three presents at the given coordinates, then count how many trees each present is touching.
The presents should be drawn as coloured rectangles using draw_rect (numbers are x, y, width & height):
red present: -100, -100, 100, 80
blue present: -100, 100, 30, 20
yellow present: 60, 20, 60, 30
This problem is designed to be VERY easy, in case you have difficulty getting set up with the turtle library.
There are two versions of the code. The first works in 'standalone' Python, shell, vs code, Thonny, IDLE, Trinket etc.
The second works in Colab, Google's free, online Python environment. Click this link then 'Save a copy to Drive': https://colab.research.google.com/drive/1t-HxDCLfUZ97d3ZDSBdSKkqru-N1UEm8#scrollTo=_YAFw1AmO-Nb
import turtle
WIDTH, HEIGHT = 400, 300
scr = turtle.Screen()
scr.setup(WIDTH, HEIGHT)
t = turtle.Turtle()
turtle.tracer(0)
def draw_tree(x, y, w, h):
wth = w / 8
hth = h / 8
# t.fillcolor('white')
# draw_rect(x, y, w, h) # bounding box
t.fillcolor('brown')
draw_rect(x + wth * 3, y, wth * 2, hth * 2) # trunk
t.fillcolor('green')
draw_triangle(x + wth * 0, y + hth * 2, wth * 8, hth * 4) # base
draw_triangle(x + wth * 1, y + hth * 4, wth * 6, hth * 3) # middle
draw_triangle(x + wth * 2, y + hth * 6, wth * 4, hth * 2) # top
def draw_rect(x, y, w, h): # x,y is bottom left corner
t.penup()
t.goto(x, y)
t.pendown()
t.begin_fill()
t.goto(x + w, y)
t.goto(x + w, y + h)
t.goto(x, y + h)
t.goto(x, y)
t.end_fill()
def draw_triangle(x, y, w, h): # x,y is bottom left corner
t.penup()
t.goto(x, y)
t.pendown()
t.begin_fill()
t.goto(x + w, y)
t.goto(x + w/2, y+h)
t.goto(x, y)
t.end_fill()
# ADD CODE TO DRAW THE PRESENT RECTANGLES
# red present (100's digit)
# blue present (10's digit)
# yellow present (1's digit)
for i, tree in enumerate(trees):
x,y,w,h = tree
draw_tree(x, y, w, h)
t.hideturtle()
turtle.update()
trees = [[73, -143, 58.6, 58.6], [-53, -87, 47.4, 47.4], [-44, 92, 11.6, 11.6], [33, -63, 42.6, 42.6], [-186, 31, 23.8, 23.8], [-198, -95, 49.0, 49.0], [-7, -78, 45.6, 45.6], [-185, -110, 52.0, 52.0], [154, 113, 7.4, 7.4], [23, 84, 13.2, 13.2], [-148, -136, 57.2, 57.2], [93, 88, 12.4, 12.4], [14, -71, 44.2, 44.2], [-92, -46, 39.2, 39.2], [-142, 142, 1.6, 1.6], [-200, -52, 40.4, 40.4], [-16, -149, 59.8, 59.8], [93, 60, 18.0, 18.0], [-76, 73, 15.4, 15.4], [-148, -54, 40.8, 40.8], [67, 73, 15.4, 15.4], [50, -145, 59.0, 59.0], [88, -77, 45.4, 45.4], [-181, 39, 22.2, 22.2], [192, -7, 31.4, 31.4], [91, 7, 28.6, 28.6], [160, 78, 14.4, 14.4], [102, 58, 18.4, 18.4], [-6, 84, 13.2, 13.2], [92, -28, 35.6, 35.6], [-149, 0, 30.0, 30.0], [-127, 101, 9.8, 9.8], [48, 15, 27.0, 27.0], [-115, 87, 12.6, 12.6], [145, 118, 6.4, 6.4], [53, -107, 51.4, 51.4], [115, -3, 30.6, 30.6], [-127, -51, 40.2, 40.2], [-136, -21, 34.2, 34.2], [-129, 20, 26.0, 26.0], [-21, 109, 8.2, 8.2], [-191, 43, 21.4, 21.4], [194, -50, 40.0, 40.0], [-22, -33, 36.6, 36.6], [-74, 105, 9.0, 9.0], [-154, -47, 39.4, 39.4], [-174, 38, 22.4, 22.4], [-26, 19, 26.2, 26.2], [-104, -92, 48.4, 48.4], [-102, 111, 7.8, 7.8], [-192, -82, 46.4, 46.4], [65, 5, 29.0, 29.0], [179, -17, 33.4, 33.4], [-136, 31, 23.8, 23.8], [-92, -47, 39.4, 39.4], [-52, -41, 38.2, 38.2], [88, 29, 24.2, 24.2], [34, 97, 10.6, 10.6], [156, 76, 14.8, 14.8], [-170, 106, 8.8, 8.8], [125, 119, 6.2, 6.2], [-60, 20, 26.0, 26.0], [-126, 14, 27.2, 27.2], [-53, 21, 25.8, 25.8], [123, 130, 4.0, 4.0], [-150, -139, 57.8, 57.8], [-89, 106, 8.8, 8.8], [34, -133, 56.6, 56.6]]