# Arc in MWorks

**URL:** <https://mworks.discourse.group/t/arc-in-mworks/764>\
**Category:** Support\
**Created:** [November 17, 2020, 1:53pm UTC](https://mworks.discourse.group/t/arc-in-mworks/764 "2020-11-17T13:53:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 17, 2020, 1:53pm UTC](https://mworks.discourse.group/t/arc-in-mworks/764/1 "2020-11-17T13:53:35Z")

</div>

Dear Chris,

Is there a way of drawing an arc in MWorks? something like the red object you can see in the attached image.  
We would like for the arc to change color, luminance, position, and size like any other object.

thank you in advance

LG  
a

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 17, 2020, 1:53pm UTC](https://mworks.discourse.group/t/arc-in-mworks/764/2 "2020-11-17T13:53:35Z")

</div>

Attachment: [Screenshot\_2020-11-15\_at\_16.50.01.png](https://mworks.discourse.group/uploads/short-url/3Ws9sauONqPgYfbHNXgEMSsuHy0.png) (142 KB)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 17, 2020, 2:11pm UTC](https://mworks.discourse.group/t/arc-in-mworks/764/3 "2020-11-17T14:11:17Z")

</div>

Hi Antonino,

There’s no direct support for drawing arcs, but it should be possible to construct one via a combination of circular and rectangular [masks](https://mworks.github.io/documentation/latest/components/mask_stimulus.html). I can try to make an example of that for you, if it would be helpful.

I could also add built-in support for drawing arcs to MWorks, although that will take some time and will require you to upgrade to the latest [nightly build](https://mworks.github.io/downloads/) to make use of it.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 17, 2020, 3:07pm UTC](https://mworks.discourse.group/t/arc-in-mworks/764/4 "2020-11-17T15:07:09Z")

</div>

It would be helpful if you could make a little example if that does not require too much of your time.

Adding a built-in support for future experiments would also be useful. At the moment we are drawing an arc with a plugin that Ralf wrote, but utilising a plugin that is not native to mworks, makes it impractical and difficult to handle.

Thanks for the help

LG

a

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 19, 2020, 9:16pm UTC](https://mworks.discourse.group/t/arc-in-mworks/764/5 "2020-11-19T21:16:47Z")

</div>

Hi Antonino,

I’ve attached an example. The arc stimulus is implemented as an [MWEL macro](https://mworks.github.io/documentation/latest/mwel/index.html#statement) in a separate file (`arc_stimulus.mwel`) [included](https://mworks.github.io/documentation/latest/mwel/index.html#includes) by the main experiment file (`arc_demo.mwel`). This makes it easier to use in multiple experiments, should you wish to do so.

The only limitation with the stimulus as constructed is that theta\_max-theta\_min can be at most 180 degrees.

> Adding a built-in support for future experiments would also be useful. At the moment we are drawing an arc with a plugin that Ralf wrote, but utilising a plugin that is not native to mworks, makes it impractical and difficult to handle.

If Ralf wants to give me the source code for his plugin, I’d be happy to add this to the standard MWorks distribution. Otherwise, I can write a new one.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 19, 2020, 9:16pm UTC](https://mworks.discourse.group/t/arc-in-mworks/764/6 "2020-11-19T21:16:47Z")

</div>

Attachment: [arc\_demo.zip](https://mworks.discourse.group/uploads/short-url/efUaMej7KaH1QTPch7Fh5Ar7Izq.zip) (1.16 KB)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 20, 2020, 9:10am UTC](https://mworks.discourse.group/t/arc-in-mworks/764/7 "2020-11-20T09:10:43Z")

</div>

Hey Chris,

the arc works perfectly and implementing it as a separate file is very  
useful for us!

thanks again  
Antonino

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 20, 2020, 9:16am UTC](https://mworks.discourse.group/t/arc-in-mworks/764/8 "2020-11-20T09:16:36Z")

</div>

Also, I am very interested in how you actually implemented the arc itself.  
Could you either explain or point me to somewhere in the documentation so  
that I can understand better how you drew it?

thanks  
lg  
a

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 23, 2020, 3:55pm UTC](https://mworks.discourse.group/t/arc-in-mworks/764/9 "2020-11-23T15:55:10Z")

</div>

Hi Antonino,

The arc is implemented by combining a circle with three [masks](https://mworks.github.io/documentation/latest/components/mask_stimulus.html). The first is an [inverted](https://mworks.github.io/documentation/latest/components/mask_stimulus.html#inverted) circular mask, which removes the center of the circle out to radius\_inner, creating a ring. The other two are [gratings](https://mworks.github.io/documentation/latest/components/drifting_grating_stimulus.html) configured as [masks](https://mworks.github.io/documentation/latest/components/drifting_grating_stimulus.html#mask). The parameters of each grating are chosen so that half of the grating’s on-screen area is 100% visible, while the other half is 0% visible. Adjusting the [direction](https://mworks.github.io/documentation/latest/components/drifting_grating_stimulus.html#direction) parameter of each grating creates a 100% visible wedge that turns the ring into an arc.

To better see how the gratings work, you can remove `mask = true` from both of the grating definitions and add `alpha_multiplier = 0.5` to the second one. Then, when the stimulus is drawn, the 100% white region is the portion of the underlying ring that the combined grating masks let through. All other areas are masked out. This is also an easy way to see why you can’t use this technique to make an arc greater than 180 degrees.

Finally, in order for the masking to work, both the base circle and the three masks must be part of a [layer](https://mworks.github.io/documentation/latest/components/layer_stimulus.html). This is actually very convenient, as the layer serves as a single, top-level stimulus that can be queued and dequeued without worrying about managing its constituents individually.

I hope that makes sense. If you need more info, please let me know.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 23, 2020, 5:02pm UTC](https://mworks.discourse.group/t/arc-in-mworks/764/10 "2020-11-23T17:02:43Z")

</div>

Hi Chris,

yes that makes a lot of sense, thanks for the detailed explanation.

I have another question for you (sorry to bother you so much).

We are planning to conduct an experiment online via a platform called  
labvanced. It is a cognitive task so we need very simple stimuli which we  
have generated with a plugin that Ralf wrote. Each stimulus has three  
features, motion, color, shape. Usually with our monkeys we generate these  
stimuli online with mworks and run the task like any other task, but in  
labvanced we cannot generate such stimuli, mostly because there is no  
motion engine on the platform.

So our current strategy is to have a little GIF or video clip for every  
combination of these features and upload those clips on labvanced as  
animated / moving stimuli.

My question for you would then be: is there a way of generating a video or  
a series of images from MWorks that I can then quickly put together in  
python or matlab to create a gif?

My plan would be to use mworks to generate the stimuli, show one stimulus  
at a time on the screen, save each frame as an image into a specific  
folder, cycle through the folders with python to generate one gif for each  
stimulus.

I am not sure if it is possible in MWorks to export a frame into a picture  
in an automatic way.

I hope this is clear, in case it is not I would also be available for a  
skype call to explain better.

thanks in any case  
best  
Antonino

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [April 2, 2024, 1:21pm UTC](https://mworks.discourse.group/t/arc-in-mworks/764/12 "2024-04-02T13:21:39Z")

</div>


