Displaying shapes in random locations?
Ältere Kommentare anzeigen
Hi everyone!
I am coding an experiment that requires to click the shapes on the screen with mouse clicks. However, I could not find a way to make shapes randomly located on the screen for each trial.
I use 'FillRect' or 'FillOval':
Screen('FillOval',windowPtr,[150 150 150],[? ? ? ?])
I would be very happy if you can help me out with that.
Thank you in advance.
2 Kommentare
Walter Roberson
am 27 Dez. 2019
This appears to relate to the third-party Psychtoolbox, which defines Screen()
Eren Serefoglu
am 27 Dez. 2019
Antworten (2)
Walter Roberson
am 27 Dez. 2019
Instead of filling one oval, you can also specify a list of multiple ovals to be
filled - this is much faster when you need to draw many ovals per frame. To fill
n ovals, provide “rect” as a 4 rows by n columns matrix, each column specifying
one oval, e.g., rect(1,5)=left border of 5th oval, rect(2,5)=top border of 5th
oval, rect(3,5)=right border of 5th oval, rect(4,5)=bottom border of 5th oval
We can deduce from this that a rect is defined by [left, top, right, bottom] . So choose random positions such that the left border + desired width does not exceed the right boundary, and top border + desired height does not exceed the bottom boundary. randi() can help for that.
See also the tutorials at https://peterscarfe.com/ptbtutorials.html which include a few that use randomization.
But one question I would have is whether the random shapes need to avoid the locations of existing objects in the frame? Packing randomly positioned objects in a non-overlapping way into a constrained area can get difficult.
Image Analyst
am 28 Dez. 2019
0 Stimmen
See my attached demo code that makes a bunch or randomly oriented shapes.

Kategorien
Mehr zu Image display and manipulation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!