<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def init(canvas_size=(512, 512), max_depth=12, face_color=None, background_color=None):
 """Initializes global state"""

    global _background_color
    _background_color = background_color
    global _ctx
    global cnt_elements
    global MAX_DEPTH
    global WIDTH
    global HEIGHT

    _init_state()
    sys.setrecursionlimit(20000)
    MAX_DEPTH = max_depth
    WIDTH, HEIGHT = canvas_size

    if face_color is not None:
        r, g, b = htmlcolor_to_rgb(face_color)
        _state["ctx"].set_source_rgb(r, g, b)
        hue, saturation, brightness = colorsys.rgb_to_hsv(r, g, b)
        _state["color"] = (hue, saturation, brightness, 1)
    logger.debug("Init done")