Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Testing latest pari + WASM + node.js... and it works?! Wow.

28485 views
License: GPL3
ubuntu2004
1
/* Copyright (C) 2000 The PARI group.
2
3
This file is part of the PARI/GP package.
4
5
PARI/GP is free software; you can redistribute it and/or modify it under the
6
terms of the GNU General Public License as published by the Free Software
7
Foundation; either version 2 of the License, or (at your option) any later
8
version. It is distributed in the hope that it will be useful, but WITHOUT
9
ANY WARRANTY WHATSOEVER.
10
11
Check the License for details. You should have received a copy of it, along
12
with the package; see the file 'COPYING'. If not, write to the Free Software
13
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
14
/////////////////////////////////////////////////////////////////////////////
15
//
16
// High resolution plot using FLTK library
17
// Bill Allombert 2003
18
//
19
// Based on plotQt by Nils-Peter Skoruppa (www.countnumber.de)
20
/////////////////////////////////////////////////////////////////////////////
21
extern "C" {
22
#include "pari.h"
23
#include "rect.h"
24
}
25
26
#include <FL/Fl.H>
27
#include <FL/Fl_Window.H>
28
#include <FL/fl_draw.H>
29
30
class Plotter: public Fl_Window {
31
32
public:
33
Plotter(PARI_plot *T, GEN w, GEN x, GEN y);
34
35
private:
36
void draw();
37
int handle(int event);
38
39
private:
40
PARI_plot *T;
41
GEN my_w, my_x, my_y;
42
};
43
44
static Fl_Color
45
rgb_color(long c)
46
{
47
int r, g, b; long_to_rgb(c, &r, &g, &b);
48
return fl_color_cube(r*FL_NUM_RED/256, g*FL_NUM_GREEN/256, b*FL_NUM_BLUE/256);
49
}
50
Plotter::Plotter(PARI_plot *T, GEN w, GEN x, GEN y)
51
: Fl_Window(T->width, T->height, "PARI/GP")
52
{
53
this->T = T;
54
this->my_w = w;
55
this->my_x = x;
56
this->my_y = y;
57
}
58
59
static void
60
DrawPoint(void *data, long x, long y)
61
{ (void)data; fl_point(x,y); }
62
63
static void
64
DrawLine(void *data, long x1, long y1, long x2, long y2)
65
{ (void)data; fl_line(x1,y1, x2,y2); }
66
67
static void
68
DrawRectangle(void *data, long x, long y, long w, long h)
69
{ (void)data; fl_rect(x,y,w,h); }
70
static void
71
FillRectangle(void *data, long x, long y, long w, long h)
72
{ (void)data; fl_rectf(x,y,w,h); }
73
static void
74
DrawPoints(void *data, long nb, struct plot_points *p)
75
{
76
long i; (void)data;
77
for (i=0; i<nb; i++) fl_point(p[i].x, p[i].y);
78
}
79
static void
80
SetForeground(void *data, long col)
81
{
82
(void)data; fl_color(rgb_color(col));
83
}
84
static void
85
DrawLines(void *data, long nb, struct plot_points *p)
86
{
87
long i;
88
(void)data;
89
for (i=1; i<nb; i++) fl_line(p[i-1].x, p[i-1].y, p[i].x, p[i].y);
90
}
91
static void
92
DrawString(void *data, long x, long y, char *text, long numtext)
93
{ (void)data; fl_draw(text,numtext,x,y); }
94
95
void
96
Plotter::draw()
97
{
98
struct plot_eng pl;
99
double xs = double(this->w()) / T->width;
100
double ys = double(this->h()) / T->height;
101
102
fl_font(FL_COURIER, int(T->fheight * xs));
103
fl_color(rgb_color(0xffffff)); // transparent window on Windows otherwise
104
fl_rectf(0, 0, this->w(), this->h());
105
pl.sc = &SetForeground;
106
pl.pt = &DrawPoint;
107
pl.ln = &DrawLine;
108
pl.bx = &DrawRectangle;
109
pl.fb = &FillRectangle;
110
pl.mp = &DrawPoints;
111
pl.ml = &DrawLines;
112
pl.st = &DrawString;
113
pl.pl = T;
114
pl.data = NULL;
115
gen_draw(&pl, my_w, my_x, my_y, xs, ys);
116
}
117
118
int Plotter::handle(int event)
119
{
120
switch(event)
121
{
122
case FL_PUSH:
123
switch(Fl::event_button())
124
{
125
case 1:
126
exit(0);
127
case 2:
128
{
129
static int flag = 0, my_x, my_y, my_w, my_h;
130
flag = 1-flag;
131
if (flag)
132
{
133
my_x = this->x();
134
my_y = this->y();
135
my_w = this->w();
136
my_h = this->h();
137
this->fullscreen();
138
}
139
else
140
{
141
this->fullscreen_off(my_x, my_y, my_w, my_h);
142
this->size_range(1,1);
143
}
144
return 1;
145
}
146
}
147
case FL_KEYUP:
148
switch(Fl::event_key())
149
{
150
case 'q':
151
switch(Fl::event_shift())
152
{
153
case 0:
154
case FL_CTRL: exit(0);
155
}
156
break;
157
case 'c':
158
if (Fl::event_state() == FL_CTRL) exit(0);
159
break;
160
}
161
default:
162
return 0;
163
}
164
}
165
166
static void
167
draw(PARI_plot *T, GEN w, GEN x, GEN y)
168
{
169
Plotter *win;
170
171
if (pari_daemon()) return; // parent process returns
172
pari_close();
173
174
Fl::visual(FL_DOUBLE|FL_INDEX);
175
win = new Plotter(T, w, x, y);
176
win->size_range(1,1);
177
win->box(FL_FLAT_BOX);
178
win->end();
179
win->show();
180
Fl::run();
181
exit(0);
182
}
183
184
INLINE void
185
gp_get_display_sizes(long *dwidth, long *dheight, long *fwidth, long *fheight)
186
{
187
*dwidth = 800;
188
*dheight = 600;
189
*fwidth = 6;
190
*fheight = 9;
191
}
192
193
void
194
gp_get_plot(PARI_plot *T)
195
{
196
gp_get_plot_generic(T,gp_get_display_sizes);
197
T->draw = &draw;
198
}
199
200