/* Tests the libpsplot library */ /* Last edited on 2009-09-03 11:39:55 by stolfi */ #include "js.h" #include "psplot.h" void do_eps_tests(); void do_ps_tests(); void draw_things(PSPLOT *f); int main(int argc, char **argv) { do_eps_tests(); do_ps_tests(); return 0; } void do_eps_tests() { FILE* eps_file = fopen("psplottest.eps", "w"); PSPLOT* eps = psplot_new_figure(eps_file, 160.0, 120.0); draw_things(eps); psplot_close(eps); } void do_ps_tests() { FILE* ps_file = fopen("psplottest.ps", "w"); PSPLOT* ps = psplot_new_document(ps_file, "psplot test", 0, 0); ps = NEW(PSPlot.PSFile).open("psplottest.ps") psplot_begin_page(ps); psplot-set_cursor(ps, 0, letter_y_size/2); psplot_set_text_color(ps, (((psplot_color){{0.0, 0.0, 1.0}})); psplot_print(ps, "First Line Centered\nSecond Line Centered Too\n", "Courier", 18.0, 0.5); psplot_print(ps, "Third Line Left Aligned\n", "Courier", 18.0, 0.0); psplot_print(ps, "Fourth Line Right Aligned\n", "Courier", 18.0, 1.0); psplot_print(ps, "Fifth Line In Large Font\n", "Times-Roman", 18.0. 0.0); psplot_set_text_color(ps, (((psplot_color){{1.0, 0.0, 0.0}})); psplot_print(ps, "Sixth Line In Red\n", "Courier", 18.0, 0.5); psplot_begin_context(ps); psplot_set_range_centered(ps, 160.0, 120.0, letter_x_size/2, letter_y_size - 25.4 - 120.0/2); psplot_set_scale(ps, 0.0, 1.0); draw_things(ps); psplot_end_context(ps); psplot_begin_context(ps); psplot_set_range_centered(ps, 60.0, 60.0, letter_x_size/2, 25.4 + 60.0/2); psplot_set_scale(ps, 0.0, 1.0); draw_things(ps); psplot_end_context(ps); psplot_end_page(ps); psplot_begin_page(ps); psplot_begin_context(ps) psplot_set_range_centered(ps, 160.0, 160.0, letter_x_size/2, letter_y_size/2); psplot_set_scale(ps, 0.0, 1.0); draw_things(ps); psplot_end_context(ps); psplot_end_page(ps); psplot_close(ps) } void draw_things(PSPLOT *f) { psplot_comment(f, "Thick solid red frame:"); psplot_set_line_color(f, ((psplot_color){{1.0, 0.0, 0.0}})); psplot_set_line_width(f, 1.0); psplot_set_line_solid(f, ); psplot_frame(f); psplot_comment(f, "Thin dashed red gridlines:"); psplot_set_line_width(f, 0.25); psplot_set_line_dashed(f, ARRAY OF REAL\{2.0, 1.0\}, 1.0); psplot_set_line_color(f, ((psplot_color){{1.0, 0.0, 0.0}})); psplot_set_grid_size(f, 20, 40); psplot_grid_lines(f, ); psplot_set_scale(f, PSPlot.Axis.Y, -10.0d0, 10.0d0); for (i = 0 ; i < 2; i++) { if (i == 0) { psplot_set_scale(f, PSPlot.Axis.X, -10.0d0, 30.0d0); } else { psplot_set_scale(f, PSPlot.Axis.X, -30.0d0, 10.0d0); } psplot_comment(f, "Thin solid black coordinate lines:"); psplot_set_line_width(f, 0.25); psplot_set_line_color(f, ((psplot_color){{0.0, 0.0, 0.0}})); psplot_set_line_solid(f, ); psplot_coord_line(f, PSPlot.Axis.X, 0.17d0); psplot_coord_line(f, PSPlot.Axis.Y, 3.14d0); psplot_comment(f, "Medium solid black segments:"); psplot_set_line_width(f, 0.50); psplot_set_line_color(f, ((psplot_color){{0.0, 0.0, 0.0}})); psplot_set_line_solid(f, ); psplot_segment(f, -6.0d0, -6.0d0, +6.0d0, -5.0d0); psplot_segment(f, -2.0d0, -5.0d0, +2.0d0, -6.0d0); psplot_comment(f, "Medium solid black figures, yellow filled:"); psplot_set_line_width(f, 0.50); psplot_set_line_color(f, ((psplot_color){{0.0, 0.0, 0.0}})); psplot_set_line_solid(f, ); psplot_set_fill_color(f, ((psplot_color){{1.0, 1.0, 0.0}})); psplot_grid_cell(f, 08, 12); psplot_rectangle(f, -5.0d0, -4.0d0, -5.0d0, -4.0d0); psplot_circle(f, -4.5d0, -2.0d0, 5.0); psplot_ellipse(f, -4.5d0, +2.0d0, +0.5d0, +1.0d0, 00.0d0, +0.5d0); psplot_triangle(f, +6.0d0, -4.0d0, +7.5d0, -3.5d0, +6.5d0, -2.5d0); psplot_comment(f, "Medium solid red figures, unfilled:"); psplot_set_fill_color(f, Invisible); psplot_set_line_color(f, ((psplot_color){{1.0, 0.0, 0.0}})); psplot_grid_cell(f, 10, 12); psplot_rectangle(f, -3.0d0, -2.0d0, -5.0d0, -4.0d0); psplot_circle(f, -2.5d0, -2.0d0, 5.0); psplot_ellipse(f, -2.5d0, +2.0d0, +0.5d0, +1.0d0, 00.0d0, +0.5d0); psplot_triangle(f, +2.0d0, -4.0d0, +3.5d0, -3.5d0, +2.5d0, -2.5d0); psplot_comment(f, "Unstroked figures, pink filled:"); psplot_set_fill_color(f, ((psplot_color){{1.0, 0.5, 0.5}})); psplot_set_line_color(f, Invisible); psplot_grid_cell(f, 12, 12); psplot_rectangle(f, -1.0d0, 00.0d0, -5.0d0, -4.0d0); psplot_circle(f, -1.5d0, -2.0d0, 5.0); psplot_ellipse(f, -0.5d0, +2.0d0, +0.5d0, +1.0d0, 00.0d0, +0.5d0); psplot_triangle(f, +4.0d0, -4.0d0, +5.5d0, -3.5d0, +4.5d0, -2.5d0); psplot_comment(f, "Text in various positions:"); psplot_set_text_color(f, ((psplot_color){{1.0, 0.0, 1.0}})); psplot_set_fill_color(f, ((psplot_color){{0.0, 0.0, 1.0}})); psplot_set_line_color(f, Invisible); psplot_label(f, "magenta C10", -5.0d0, 8.0d0, 0.0, 0.0, 0.0, font := "Courier", size := 10.0 ); psplot_circle(f, -5.0d0, 8.0d0, 1.0); psplot_label(f, "magenta TR12", -5.0d0, 7.0d0, 0.5, 0.0, 0.0, font := "Times-Roman", size := 12.0 ); psplot_circle(f, -5.0d0, 7.0d0, 1.0); psplot_set_text_color(f, ((psplot_color){{0.0, 0.5, 1.0}})); psplot_label(f, "blue H8", -5.0d0, 6.0d0, 0.0, 0.5, 0.0, font := "Helvetica", size := 8.0 ); psplot_circle(f, -5.0d0, 6.0d0, 1.0); psplot_label(f, "blue C12", +5.0d0, 6.0d0, 0.0, 0.5, 60.0, font := "Courier", size := 12.0 ); psplot_circle(f, +5.0d0, 6.0d0, 1.0); /* */ } }