Skip to content

Instantly share code, notes, and snippets.

@torazuka
Created October 22, 2011 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torazuka/1305731 to your computer and use it in GitHub Desktop.
Save torazuka/1305731 to your computer and use it in GitHub Desktop.
Chapter15_graph_drill_PPPC++
/* 15章のグラフ描くほうのドリル */
#include "Simple_window.h"
#include "Graph.h"
double one(double x) { return 1; }
double slope(double x) { return x / 2; }
double square(double x) { return x * x; }
double sloping_cos(double x) { return cos(x)+slope(x); }
int main(){
const int xmax = 600;
const int ymax = 600;
const int xoffset = 100;
const int yoffset = 100;
const int xspace = 100;
const int yspace = 100;
const int xlength = xmax - xoffset - xspace;
const int ylength = ymax - yoffset - yspace;
Simple_window win(Point(100, 100), xmax, ymax, "Function graphs");
Axis x(Axis::x, Point(xoffset, ymax / 2), xlength, xlength / 20, "1==20 pixels");
Axis y(Axis::y, Point(xmax / 2, ymax - yoffset), ylength, ylength / 20, "1==20 pixels");
x.set_color(Color::red);
y.set_color(Color::red);
int xscale = 20; // 倍率
int yscale = 20;
const int f_min = -10;
const int f_max = 11;
const Point orig(300, 300);
const int n_points = 400;
Function f_one(one, f_min, f_max, orig, n_points, xscale, yscale);
Function f_slope(slope, f_min, f_max, orig, n_points, xscale, yscale);
Text tf_slope(Point(xoffset, orig.y + 80), "x/2");
Function f_square(square, f_min, f_max, orig, n_points, xscale, yscale);
Function f_sloping_cos(sloping_cos, f_min, f_max, orig, n_points, xscale, yscale);
f_sloping_cos.set_color(Color::blue);
win.attach(f_one);
win.attach(f_slope);
win.attach(tf_slope);
win.attach(f_square);
win.attach(f_sloping_cos);
win.attach(x);
win.attach(y);
win.wait_for_button();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment