from pathlib import Path import live HERE = Path(__file__).parent # One crop around the casting hand, two questions. The page (static/spell.js) turns the element odds into the # spell: pure, a combo of the top two, or unstable when nothing is above 40%. The menus ask about the object # only, never about the person. STATE = ("A close crop around a player's hand from a live webcam, in a spell-casting game. " "The hand may hold an object.") HELD = { "empty": "nothing, an empty hand", "cup": "a mug, cup or glass", "bottle": "a bottle or can of drink", "plant": "a plant, flower or leaves", "fruit": "a fruit or vegetable", "flame": "a lighter, candle or match", "phone": "a phone, remote or small electronic device", "cable": "a cable, charger or battery", "pen": "a pen, pencil or brush", "paper": "a book, paper or card", "metal": "keys, coins or a metal tool", "toy": "a toy, figurine or plush", "pet": "a live pet", "food": "a snack or food", "stone": "a stone, crystal or shell", "ice": "ice, ice cream, something frozen or a cold pack", "fabric": "a cloth, scarf or feather", "other": "something else", } # Each element names everyday objects, so the answer follows the object and not the room: a first version # without them read a screen or a face behind the hand as lightning or wind. ELEMENT = { "fire": "fire: flames, lighters, candles, matches, hot drinks, chilli, and red or orange things " "(a red mug, a tomato, an orange toy)", "water": "water: water bottles, glasses of water, soap, fish, and blue things (a blue cup, a blue bottle)", "nature": "nature: plants, leaves, flowers, fruit, vegetables, wood, and green things (an apple, a banana, a pot plant)", "lightning": "lightning: phones, batteries, cables, chargers, remotes, torches, and yellow things", "ice": "ice: ice, ice cream, frozen food, glass, and white or clear things (a white mug, an empty glass)", "earth": "earth: stones, keys, coins, metal tools, pens, clay, and brown or grey things (a wallet, a spoon)", "air": "wind: paper, books, feathers, tissues, fabric, balloons, and other light things", "shadow": "shadow: black things (sunglasses, a black mug, a black glove, a dark cloth), or an empty hand", } def questions(context): if context.get("images") != 1: raise ValueError("Send one crop.") return STATE, { "held": {"type": "choice", "instructions": "What is the hand holding?", "criteria": dict(HELD)}, "element": {"type": "choice", "instructions": "The object in the hand powers a spell. Which element does that object belong to, " "judging by what it is, its material, colour and use? Judge only the held object: " "ignore the background, any screen, and the person.", "criteria": dict(ELEMENT)}, } app = live.make_app(questions, HERE / "static")