#include "TrueBASIC.h" #include "csgraphics.h" #ifdef _MSC_VER void __stdcall DRAW_AXES(float *xmin, float *xmax, float *ymin, float *ymax) { draw_axes(*xmin, *xmax, *ymin, *ymax); } #endif void draw_axes(float xmin, float xmax, float ymin, float ymax) { float ty, dy, itick, tx, dx, y, y0, ntick, x, x0; // 目盛の数 ntick = 10; // dx は x 軸上の目盛の間隔 dx = (xmax - xmin)/ntick; // dy は y 軸上の目盛の間隔 dy = (ymax - ymin)/ntick; // window 文でマージン(縁)をとる GWindow(xmin - dx, ymin - dy, xmax + dx, ymax + dy); x0 = max(0,xmin); y0 = max(0,ymin); if(ymin*ymax < 0) y0 = 0; else y0 = ymin; GWline(xmin, y0, xmax, y0); // 水平軸 GWline(x0, ymin, x0, ymax); // 垂直軸 tx = 0.1f*dy; // 目盛の大きさ ty = 0.1f*dx; for(itick = 0; itick <= ntick; itick += 1) { x = xmin + itick*dx; GWline(x, y0 - tx, x, y0 + tx ); // x 軸に目盛を描く y = ymin + itick*dy; GWline(x0 - ty, y, x0 + ty, y); // y 軸に目盛を描く } } #ifdef _MSC_VER void __stdcall COMPUTE_ASPECT_RATIO(float *r, float *x, float *y) { compute_aspect_ratio(*r, x, y); } #endif void compute_aspect_ratio(float r, float *x, float *y) { float aspect_ratio, m, size; int px, py; m = 0.1f*r; // 縁をつける size = r + m; // px, py: 水平方向と垂直方向のピクセル数 GWsize(7, &px, &py); if(px > py) { aspect_ratio = (float)px/py; *x = aspect_ratio*size; *y = size; } else { aspect_ratio = (float)py/px; *x = size; *y = aspect_ratio*size; } }