# Tracking Selected Objects

**URL:** <https://cl.desmos.com/t/tracking-selected-objects/3922>\
**Category:** Examples\
**Created:** [January 3, 2022, 4:51pm UTC](https://cl.desmos.com/t/tracking-selected-objects/3922 "2022-01-03T16:51:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alain\_Mangan](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/alain_mangan/32/3174_2.png) [@Alain\_Mangan](https://cl.desmos.com/u/Alain_Mangan)\
**Post date:** [January 3, 2022, 4:51pm UTC](https://cl.desmos.com/t/tracking-selected-objects/3922/1 "2022-01-03T16:51:24Z")

</div>

Hi.

Trying to wrap my head around how to make create more involved activities (ex: where students click on objects).

Got something working reasonably well now that desmos supports the `→` (assignment?) operator :  
 → [SelectingObjects | Desmos](https://www.desmos.com/calculator/oxu0zx4fjz)

### Interesting programming model

Many features of Desmos feels very LISP-y to me. Very interesting.

### Problem

I find it very difficult to work with evolving state in Desmos. Although my example works well, it is quite involved to figure out how to do this.

I get the impression teachers would create better content if the barrier for saving/manipulating state was lowered somehow.

Though I agree that concepts from LISP seem to model problems encountered in math very well, I think most people (including myself) have difficulty thinking in this LISP-like state-less fashion.

**edit1:** More accurately: it is difficult to modify state programmatically (There is, of course, state in the graphs variables).

**edit2:** Desmos programs seem to be declarative in nature (so maybe Prolog is a better comparison than LISP?).

### More examples?

Maybe someone could build up a well catalogued database of examples on how to build up more complex activities?

→ So I suppose this is my first example — hoping it will make it easier for teachers to create more interesting activities.

---

<div class="post-metadata">

**Author:** ![Alain\_Mangan](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/alain_mangan/32/3174_2.png) [@Alain\_Mangan](https://cl.desmos.com/u/Alain_Mangan)\
**Post date:** [January 3, 2022, 10:08pm UTC](https://cl.desmos.com/t/tracking-selected-objects/3922/2 "2022-01-03T22:08:41Z")

</div>

Just noticed someone else posted an interesting set of examples:

> **[Ideas, Tricks, Techniques](https://www.desmos.com/calculator/0bvgiggids)**
>
> Ideas, Tricks, Techniques

---

<div class="post-metadata">

**Author:** ![aknauft](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/aknauft/32/3701_2.png) [@aknauft](https://cl.desmos.com/u/aknauft)\
**Post date:** [January 4, 2022, 6:51am UTC](https://cl.desmos.com/t/tracking-selected-objects/3922/3 "2022-01-04T06:51:49Z")

</div>

Hi, welcome to the forum!

A database of complex examples is very interesting to me – the difficulty there is finding the right way to organize things so that there is a reasonable entry point for everyone. Complex examples can get quite complex! But it’s something I like to think about not infrequently.

As for manipulating graph state, actions (-\>) are the only non-hacky way to make this sort of change. I have found lists and list operations to be key for most of my complex builds.

I like your example! Here’s my recreation, with a slightly different click update implemented in line 4: [Untitled Graph](https://www.desmos.com/calculator/p8fu7fjsrd)

---

<div class="post-metadata">

**Author:** ![Alain\_Mangan](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/alain_mangan/32/3174_2.png) [@Alain\_Mangan](https://cl.desmos.com/u/Alain_Mangan)\
**Post date:** [January 5, 2022, 1:04am UTC](https://cl.desmos.com/t/tracking-selected-objects/3922/4 "2022-01-05T01:04:21Z")

</div>

Thanks for the example.

### Conditionals for updating state

I’ve never thought you could use conditionals this way to toggle elements of “HasBeenClicked”.

Kind of nice that you don’t need extra lines to generate a “bit mask” like I’ve had to do.

Always looking for good ways to balance number of lines with the overall complexity of the code in order to keep things manageable & readable (even if I’m the only one looking at my code).

### More boolean manipulations

I’ve also never seen selection being possible by (multiplying?) a set of points by a vector of booleans (line 4):  
`(xi,yi)[1=HasBeenClicked]`

Actually, I can clearly see it is not a multiplication, because if I do:  
`(xi,yi)([1=HasBeenClicked]*2)`  
The calculation fails

### Toggle vs enable

One thing to note is that your code toggles, whereas mine simply enables (won’t re-enable). But I can surely adapt this solution to my situation. Thanks.

---

<div class="post-metadata">

**Author:** ![Alain\_Mangan](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/alain_mangan/32/3174_2.png) [@Alain\_Mangan](https://cl.desmos.com/u/Alain_Mangan)\
**Post date:** [January 5, 2022, 1:24am UTC](https://cl.desmos.com/t/tracking-selected-objects/3922/5 "2022-01-05T01:24:02Z")

</div>

Oh yeah…

I really like the idea of placing all the points in a table like you did. It seems to better group similar things & de-clutter the calculator code.

I just wish there was a way to set common restrictions on the `(x,y)` coordinates (namely step size) so students can deal with integer values to simplify mental calculations, etc.

### Column names

I would highly suggest naming the columns to something like x\_i & y\_i instead of the default x\_1 & y\_1, though. x\_1 sort of sounds like the x-coordinate of point 1 - and I find that a bit confusing.

---

<div class="post-metadata">

**Author:** ![pirsquared](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@pirsquared](https://cl.desmos.com/u/pirsquared)\
**Post date:** [January 5, 2022, 6:04pm UTC](https://cl.desmos.com/t/tracking-selected-objects/3922/6 "2022-01-05T18:04:32Z")

</div>

> [@Alain\_Mangan](#):
>
> I’ve also never seen selection being possible by (multiplying?) a set of points by a vector of booleans (line 4):  
> `(xi,yi)[1=HasBeenClicked]`

Not a multiplication as such (as you discovered) but using the ‘elements of the list that satisfy a condition’ implementation mentioned here: [https://help.desmos.com/hc/en-us/articles/4407889068557-Lists](https://help.desmos.com/hc/en-us/articles/4407889068557-Lists)

So `(x_i,y_i)` is a list of points, narrowed to only the elements of that list in the positions where `HasBeenClicked` equals 1.

---

<div class="post-metadata">

**Author:** ![Alain\_Mangan](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/alain_mangan/32/3174_2.png) [@Alain\_Mangan](https://cl.desmos.com/u/Alain_Mangan)\
**Post date:** [January 6, 2022, 12:39am UTC](https://cl.desmos.com/t/tracking-selected-objects/3922/7 "2022-01-06T00:39:00Z")

</div>

Excellent! Thanks for pointing me to the doc – and providing me with a search term (I would probably not have found the relevant snippet otherwise).

This is great! I get to use modulo arithmetic with this filtering tool:  
` L[mod(L,2)=0]`
