How to create randomly distributed triangles

1 次查看(过去 30 天)
I need to create a moving visual display consisting of 500 randomly distributed white triangles (3.4 × 3.4 × 3 cm) on a black background. The frame rate of the visual display needs to be 60 Hz, triangles move in fore-aft direction. Could you please help me figure this out? Thank you.
  10 个评论
Rik
Rik 2020-9-2
You can write videos with Matlab. I have never done that before, so I would have to do the same as you: google 'write video Matlab'. You can produce each frame as an image and write it to a video file.
Syncing with an external device might be tricky though. That depends mostly on how that sync should work.
Ron
Ron 2020-9-3
Thank you, Rik. I'll look into making a video. And then use a DAQ to connect with other device.

请先登录,再进行评论。

采纳的回答

Rik
Rik 2020-9-2
Slightly editing your code gets me to a max framerate of just under 200. Results will vary for different systems.
w = 3 ;
ar=0.866; % Aspect ratio for equilateral triangle
h=ar*w;%height of triangle
p=[];origins=cell(1,10);
figure(1),clf(1)
for k=1:10
x=[0 w w/2];%x coordinates of vertices
y=[0 0 h];%y coordinates of vertices
x=x+15*rand-5;y=y+15*rand-5;%add random
p(k)= patch(x,y,'white'); %#ok<SAGROW> plotting triangle in white color
origins{k}=[mean(x) mean(y) 0];%store explicitly to prevent having to retrieve it from an object
end
set(gca,'Color','k','xticklabel',[],'yticklabel',[])%setting background black and removing labels
daspect([1 1 1]);%equal data unit length along x and y axis
xlim([-5 15]),ylim([-5 15])
rotation_per_frame_in_deg=0.8;
target_fps=60;
frametime=1/target_fps;
h_tic=tic;
for n=1:60%do 60 frames
tic
for k=1:numel(p)
rotate(p(k),[0 0 1],rotation_per_frame_in_deg,origins{k})
end
drawnow
pause(frametime-toc)%comment this line to see the max framerate
end
t=toc(h_tic);
fprintf('the fps was %.1f Hz\n',n/t)
  3 个评论
Ron
Ron 2020-9-2
编辑:Rik 2020-10-3
Thanks so much for your help with the code above! Specially that I can appreciate the frame rate change.
Rik
Rik 2020-10-3
编辑:Rik 2020-10-3
Why did you remove part of your question? Now my answer is much less useful to others with a similar problem.
Luckily there is a copy of this thread on the Wayback Machine, so I could undo your edits.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by