Skip to content

exercise_6

bjornstahl edited this page Oct 14, 2021 · 1 revision

Exercise 6

The mouse support script indirectly introduced 'picking', looking for objects that exist at a certain position without having to manually keep track or iterate over existing ones yourself.

This short set dips into the functions image_hit, pick_items and image_mask_set.

1 - Where When?

Create an animated color surface that moves from the upper left corner to the lower right in 200 ticks. As part of a clock_pulse handler, use image_hit to check when it reaches the center of the window and print that it has been detected once.

2 - Needle in Haystack

Create 12 color surfaces and leave them positioned in the upper left corner but with ascending order. Use pick_items(0, 0) and dump the set. Change the call to pick items so that you only get the highest two elements.

3 - Masking on the Job

Take the set from the previous exercise and change so that all matching items gets printed. Then somehow use image_mask_set to make it so that the fourth item never appears.