実現したいこと
c++を使って書かれたプログラムから、matplotlibを用いて図形を描写すること。
樹形図を書くプログラムを使用しています。
###前提
プログラムを
g++ tree.cpp -o tree -std=c++11 -I/usr/include/python2.7 \ -lpython2.7
でコンパイルし、
./tree ```で実行しました。 ### 発生している問題・エラーメッセージ 実行すると、 ```ここに言語を入力 Level of the tree?:
と出てくるため、適当な数字を打ち込むのですが、何も起こらずにコマンドの入力に戻ってしまいます。
該当のソースコード
c++
1 2// tree.cpp 3 4#define _USE_MATH_DEFINES 5#include <iostream> 6#include <cmath> 7#include "matplotlibcpp.h" 8using namespace std; 9namespace plt = matplotlibcpp; 10 11void draw(double x1, double y1, double x2, double y2) 12{ 13 std::vector<double>xa(2), ya(2); 14 xa[0]=x1; xa[1]=x2; 15 ya[0]=y1; ya[1]=y2; 16 std::map<std::string,std::string> keywords; 17 keywords["linewidth"]="1"; 18 keywords["color"]="black"; 19 plt::plot(xa,ya, keywords); 20} 21 22void tree(int n, double x, double y, double angle, double length) 23{ 24 double x1, y1; 25 if (n>0){ 26 x1 = x + length*cos(angle); 27 y1 = y - length*sin(angle); 28 draw(x,y,x1,y1); 29 tree(n-1,x1,y1,angle + 0.25,length*0.7); 30 tree(n-1,x1,y1,angle - 0.25,length*0.7); 31 } 32} 33 34int main() 35{ 36 int n; 37 plt::xlim(0,1); 38 plt::ylim(0,1); 39 cerr << "Level of the tree? :"; 40 cin >> n; 41 tree(n, 0.5, 0.0, -M_PI/2, 0.25); 42 plt::show(); 43} 44
補足情報(FW/ツールのバージョンなど)
windows 10
ubuntu 18.04
を使っています。
最近C言語の勉強を始めたばかりで、このようなサイトの利用も初めてのため、至らぬ点も多いかとも思いますが、ご回答いただけましたら幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/26 03:27