Randomizing Shape and Location
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi Matlab community, I love you guys. I'm using psychtoolbox and I am trying to randomize four direction of an triangle in four different locations so that it 1) won't appear in same direction as any other triangle, 2) it won't appear in the same location as any other triangle.
Problem 1: If left triangle quadrant 4, then no other left triangles will appear and no other triangles will appear in the left quadrant.
colarray = [c1; c2; c3; c4];
colidx1 = randi(4,1,1);
colour1 = colarray(colidx1,:);
colidx2 = randi(4,1,1);
while ismember(colidx2, colidx1)
colidx2 = randi(4,1,1);
end
...
This will randomize the color between 4 different colors, and it works beautifully. So I know I can do the same thing for 1 feature, like direction. But I don't know how to do it for two features: direction and location.
Problem 2:
uptriangle = [50 0;0 -50;-50 0]+600
Screen('FillPoly', window, [255 255 0], uptriangle)
Screen('Flip',window);
This code creates an upwards facing triangle, but its location and its shape are defined by the same information - [50 0;0 -50;-50 0]+600. Is there anyway I can move its location without changing its shape? Maybe something like uptriangle = triangle + xyquandrant, triangle = [50 0;0 -50;-50 0], xyquadrant = [300,300]? If I cannot define its shape and location separately, I don't think I will be able to randomize them separately.
Please help,
0 comentarios
Respuesta aceptada
Walter Roberson
el 23 de Nov. de 2012
I do not understand about "direction" ?
Yes you can move an object without changing its shape:
triangle = [50 0;0 -50;-50 0];
xoffset = 350; %for example
yoffset = 192; %or example
shiftedtriangle = triangle + repmat([xoffset; yoffset], 1, 3]);
4 comentarios
Walter Roberson
el 23 de Nov. de 2012
shiftedtriangle = triangle + repmat([xoffset, yoffset], 3, 1);
Más respuestas (0)
Ver también
Categorías
Más información sobre Image display and manipulation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!