Small projectElementary20 XPExercise 1/8

A tuft of grass

Task

Make a program with a 700 × 500 canvas. A left mouse click draws a tuft of grass where you click: at least 5 green lines (blades) that start at the click and end at most 30 points to the left or right and at most 50 points above it. The right button erases the whole picture.

The blades may have a random direction and length.

The program runs in a tkinter simulation right in your browser - after Run you see the window and can click it. The tests click and check what was drawn on the canvas.

Examples

  • Call

    from tkinter import _mente as okno
    
    
    def v_poriadku(ciara, x, y):
        zaciatok = (round(ciara.coords[0]), round(ciara.coords[1]))
        koniec = (round(ciara.coords[-2]), round(ciara.coords[-1]))
        if koniec == (x, y):
            zaciatok, koniec = koniec, zaciatok
        return zaciatok == (x, y) and abs(koniec[0] - x) <= 30 and 0 <= y - koniec[1] <= 50
    
    
    okno.check("platno 700x500", okno.size() == (700, 500), f"rozmer je {okno.size()}")
    okno.click(350, 250)
    steble = okno.items("line")
    okno.check("klik nakreslil trs", len(steble) >= 5, f"pocet ciar: {len(steble)}")
    okno.check("steble su v povolenom rozsahu", steble and all(v_poriadku(c, 350, 250) for c in steble))
    okno.check("trava je zelena", steble and all(okno.greenish(c.fill) for c in steble))

    Expected output

    platno 700x500: OK
    klik nakreslil trs: OK
    steble su v povolenom rozsahu: OK
    trava je zelena: OK
  • Call

    from tkinter import _mente as okno
    
    okno.click(100, 400)
    okno.click(600, 100)
    okno.check("dva trsy", len(okno.items("line")) >= 10)
    okno.click(300, 300, button=3)
    okno.check("prave tlacidlo zmaze obrazok", len(okno.items()) == 0, f"na platne ostalo {len(okno.items())}")

    Expected output

    dva trsy: OK
    prave tlacidlo zmaze obrazok: OK

After you submit, 1 hidden test will also check your solution: a click somewhere else.

Python starts the first time you run code.

Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.

Input (stdin)

Each line = one call to input().

Output

Hints

Try it yourself first. Each hint reveals a little more - and lowers the reward a little.

Signed out, hints are free - but no XP is awarded either.

Solution

The solution unlocks after the last hint.