LoginSignup
16
9

More than 3 years have passed since last update.

MATLABでポケモンの絵を書こう

Posted at

マメパトかわいい

mamepato.png
こういうのをMATLABで書こうという記事です。

まずは誰かが書いたのを探そう

さっそくズルをしましょう!
https://ja.wolframalpha.com/

ここでマメパトとかグレッグルとかウパーとかヌオーとか、ポケモン名を探せば大抵出てきます。
下の方に [コピー可能なテキスト] ってあるので、クリップボードにコピーしておきましょう。

CopyText.png

せっかくなので、あとはMATLABで。

グレッグルだと上の方に 「0 から 92π までのときのプロット」って書いてあるので、それを1行目に書きましょう。MATLAB だと clipboard コマンドを使えば、コピーしたクリップボードの内容をそのまま文字列で使ってくれます。

あとは特殊文字とか置き換えればいいね。

t = linspace(0,92*pi,20000);

clip = clipboard('paste');
txt = textscan(clip,'%s','delimiter','\n');
txt = txt{1};

txt = replace(txt,'θ','*heaviside');
txt = replace(txt,'π','*pi');
txt = replace(txt,' ','');
txt = replace(txt,'sin','*sin');
txt = replace(txt,'t','*t');
txt = replace(txt,'(*','(');
txt = replace(txt,'-*','-');
txt = replace(txt,'+*','+');
txt = replace(txt,'r*t','rt');
txt = replace(txt,'sgn','sign');
txt = replace(txt,'*','.*');

x = eval(txt{1}(6:end));
y = eval(txt{2}(6:end));

fprintf('x = %s;\n',txt{1}(6:end))
fprintf('y = %s;\n',txt{2}(6:end))

comet(x,y)
axis equal

書けた書けた、いい感じ。
greggle.png

Simulink のサブシステムにもどうぞ

 1行目のlinspaceと、コマンドウィンドウに出てきた数式と、plot(x,y) を使ってサブシステムのマスクを作れば、いい感じのサブシステムになります。

mamesub.png

16
9
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
16
9