14
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MATLAB で、あの目玉を作ろう。

Last updated at Posted at 2020-01-17

金曜の夕方はやる気が出ない。

 誰かに見られてたらやる気が出るかもしれない!ということで、あいつの出番ですね。

MATLAB で、こっちを見るアイツを作ってみよう。

 数分でできますね。rectangle で丸を描く。

meyes.m
function meyes

F = figure(66);
A = axes;
L = rectangle('Position',[1 0 2 4],'Curvature',[1 1],'LineWidth',9);
R = rectangle('Position',[4 0 2 4],'Curvature',[1 1],'LineWidth',9);
Lb = rectangle('Position',[2 2 0.2 0.2],'Curvature',[1 1],'LineWidth',5,'FaceColor','k');
Rb = rectangle('Position',[5 2 0.2 0.2],'Curvature',[1 1],'LineWidth',5,'FaceColor','k');

A.Position = [0 0 1 1];
axis([0 7 0 4])
axis off
axis equal

いい感じ。

eyes.png

けど正面しか見ないし、瞳孔が開いてる。

カーソルを追わせよう。

WindowButtonMotionFcn を書けばいいね。

meyes.m
function meyes

F = figure(66);
A = axes;
L = rectangle('Position',[1 0 2 4],'Curvature',[1 1],'LineWidth',9);
R = rectangle('Position',[4 0 2 4],'Curvature',[1 1],'LineWidth',9);
Lb = rectangle('Position',[2 2 0.2 0.2],'Curvature',[1 1],'LineWidth',5,'FaceColor','k');
Rb = rectangle('Position',[5 2 0.2 0.2],'Curvature',[1 1],'LineWidth',5,'FaceColor','k');

F.WindowButtonMotionFcn = @Move;
A.Position = [0 0 1 1];
axis([0 7 0 4])
axis off
axis equal

    function Move (~,~)
        xy = A.CurrentPoint;
        Lb.Position = [([xy(1),xy(3)] - [2,2])./[7,3]+[2 2]  0.2  0.2];
        Rb.Position = [([xy(1),xy(3)] - [5,2])./[7,3]+[5 2]  0.2  0.2];
    end
end

eye_cursor.png

追うようになりました!
終わり!

ところで、そもそも Xeyes ってなんなんだろう・・・

 Linux の動作チェックにしか使ったことがないけど、調べてみたら30年くらい前の古典プログラムですね。
https://ja.wikipedia.org/wiki/Xeyes

14
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?