Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
/* Copyright (C) 2000 The PARI group.12This file is part of the PARI/GP package.34PARI/GP is free software; you can redistribute it and/or modify it under the5terms of the GNU General Public License as published by the Free Software6Foundation; either version 2 of the License, or (at your option) any later7version. It is distributed in the hope that it will be useful, but WITHOUT8ANY WARRANTY WHATSOEVER.910Check the License for details. You should have received a copy of it, along11with the package; see the file 'COPYING'. If not, write to the Free Software12Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */13/////////////////////////////////////////////////////////////////////////////14//15// High resolution plot using FLTK library16// Bill Allombert 200317//18// Based on plotQt by Nils-Peter Skoruppa (www.countnumber.de)19/////////////////////////////////////////////////////////////////////////////20extern "C" {21#include "pari.h"22#include "rect.h"23}2425#include <FL/Fl.H>26#include <FL/Fl_Window.H>27#include <FL/fl_draw.H>2829class Plotter: public Fl_Window {3031public:32Plotter(PARI_plot *T, GEN w, GEN x, GEN y);3334private:35void draw();36int handle(int event);3738private:39PARI_plot *T;40GEN my_w, my_x, my_y;41};4243static Fl_Color44rgb_color(long c)45{46int r, g, b; long_to_rgb(c, &r, &g, &b);47return fl_color_cube(r*FL_NUM_RED/256, g*FL_NUM_GREEN/256, b*FL_NUM_BLUE/256);48}49Plotter::Plotter(PARI_plot *T, GEN w, GEN x, GEN y)50: Fl_Window(T->width, T->height, "PARI/GP")51{52this->T = T;53this->my_w = w;54this->my_x = x;55this->my_y = y;56}5758static void59DrawPoint(void *data, long x, long y)60{ (void)data; fl_point(x,y); }6162static void63DrawLine(void *data, long x1, long y1, long x2, long y2)64{ (void)data; fl_line(x1,y1, x2,y2); }6566static void67DrawRectangle(void *data, long x, long y, long w, long h)68{ (void)data; fl_rect(x,y,w,h); }69static void70FillRectangle(void *data, long x, long y, long w, long h)71{ (void)data; fl_rectf(x,y,w,h); }72static void73DrawPoints(void *data, long nb, struct plot_points *p)74{75long i; (void)data;76for (i=0; i<nb; i++) fl_point(p[i].x, p[i].y);77}78static void79SetForeground(void *data, long col)80{81(void)data; fl_color(rgb_color(col));82}83static void84DrawLines(void *data, long nb, struct plot_points *p)85{86long i;87(void)data;88for (i=1; i<nb; i++) fl_line(p[i-1].x, p[i-1].y, p[i].x, p[i].y);89}90static void91DrawString(void *data, long x, long y, char *text, long numtext)92{ (void)data; fl_draw(text,numtext,x,y); }9394void95Plotter::draw()96{97struct plot_eng pl;98double xs = double(this->w()) / T->width;99double ys = double(this->h()) / T->height;100101fl_font(FL_COURIER, int(T->fheight * xs));102fl_color(rgb_color(0xffffff)); // transparent window on Windows otherwise103fl_rectf(0, 0, this->w(), this->h());104pl.sc = &SetForeground;105pl.pt = &DrawPoint;106pl.ln = &DrawLine;107pl.bx = &DrawRectangle;108pl.fb = &FillRectangle;109pl.mp = &DrawPoints;110pl.ml = &DrawLines;111pl.st = &DrawString;112pl.pl = T;113pl.data = NULL;114gen_draw(&pl, my_w, my_x, my_y, xs, ys);115}116117int Plotter::handle(int event)118{119switch(event)120{121case FL_PUSH:122switch(Fl::event_button())123{124case 1:125exit(0);126case 2:127{128static int flag = 0, my_x, my_y, my_w, my_h;129flag = 1-flag;130if (flag)131{132my_x = this->x();133my_y = this->y();134my_w = this->w();135my_h = this->h();136this->fullscreen();137}138else139{140this->fullscreen_off(my_x, my_y, my_w, my_h);141this->size_range(1,1);142}143return 1;144}145}146case FL_KEYUP:147switch(Fl::event_key())148{149case 'q':150switch(Fl::event_shift())151{152case 0:153case FL_CTRL: exit(0);154}155break;156case 'c':157if (Fl::event_state() == FL_CTRL) exit(0);158break;159}160default:161return 0;162}163}164165static void166draw(PARI_plot *T, GEN w, GEN x, GEN y)167{168Plotter *win;169170if (pari_daemon()) return; // parent process returns171pari_close();172173Fl::visual(FL_DOUBLE|FL_INDEX);174win = new Plotter(T, w, x, y);175win->size_range(1,1);176win->box(FL_FLAT_BOX);177win->end();178win->show();179Fl::run();180exit(0);181}182183INLINE void184gp_get_display_sizes(long *dwidth, long *dheight, long *fwidth, long *fheight)185{186*dwidth = 800;187*dheight = 600;188*fwidth = 6;189*fheight = 9;190}191192void193gp_get_plot(PARI_plot *T)194{195gp_get_plot_generic(T,gp_get_display_sizes);196T->draw = &draw;197}198199200