|  | 
|  | 1 | +import colorsys | 
|  | 2 | +import random | 
|  | 3 | + | 
| 1 | 4 | name = "Chase" | 
| 2 | 5 | 
 | 
| 3 | 6 | start_message = name + " started!" | 
| 4 | 7 | 
 | 
| 5 |  | -description = "The string is sequentially covered by different colors" | 
|  | 8 | +description = ( | 
|  | 9 | +    "The string is sequentially covered by random colors" | 
|  | 10 | +) | 
|  | 11 | + | 
|  | 12 | + | 
|  | 13 | +def create_heads(lights, args): | 
|  | 14 | +    num_heads = int(args["number"]) | 
|  | 15 | +    colors = [random.random() for _ in range(0, num_heads)] | 
|  | 16 | +    head_locations = [i * (-lights.size // num_heads) for i in range(0, num_heads)] | 
|  | 17 | +    return [head_locations, colors] | 
|  | 18 | + | 
| 6 | 19 | 
 | 
| 7 |  | -schema = {} | 
|  | 20 | +schema = { | 
|  | 21 | +    "number": { | 
|  | 22 | +        "value": { | 
|  | 23 | +            "type": "number",  # TODO integer type (or step) | 
|  | 24 | +            "min": 1, | 
|  | 25 | +            "max": 20, | 
|  | 26 | +            "default": 3, | 
|  | 27 | +        }, | 
|  | 28 | +        "user_input": True, | 
|  | 29 | +        "required": False, | 
|  | 30 | +        "index": 0, | 
|  | 31 | +    }, | 
|  | 32 | +    "color": { | 
|  | 33 | +        "value": { | 
|  | 34 | +            "type": "color",  # TODO integer type (or step) | 
|  | 35 | +            "default": {"type": "Random Colors"}, | 
|  | 36 | +        }, | 
|  | 37 | +        "user_input": True, | 
|  | 38 | +        "required": False, | 
|  | 39 | +    }, | 
|  | 40 | +    "heads": { | 
|  | 41 | +        "value": {"type": "tuple list", "default_gen": create_heads}, | 
|  | 42 | +        "user_input": False, | 
|  | 43 | +    }, | 
|  | 44 | +} | 
| 8 | 45 | 
 | 
| 9 | 46 | 
 | 
| 10 | 47 | def update(lights, step, state): | 
| 11 |  | -    hue = (0.2 * (step // lights.size)) % 1 | 
| 12 |  | -    lights.set_pixel_hsv(step % lights.size, hue, 1, 1) | 
|  | 48 | +    heads = state["heads"] | 
|  | 49 | +    for i in range(len(heads[0])): | 
|  | 50 | +        if heads[0][i] >= 0: | 
|  | 51 | +            lights.set_pixel_hsv(heads[0][i], heads[1][i], 1, 1) | 
|  | 52 | +        heads[0][i] += 1 | 
|  | 53 | +        if heads[0][i] >= lights.size: | 
|  | 54 | +            heads[0][i] = 0 | 
|  | 55 | +            heads[1][i] = colorsys.rgb_to_hsv(state["color"].get_color(step)) | 
0 commit comments