-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotter.gxs
104 lines (99 loc) · 2.55 KB
/
plotter.gxs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* Gunderscript Example Script
* (C) 2014 Kai Smith
*/
function abs(val){
if (val < 0)
return(0-val);
return(val);
}
function plot(xmin, xmax, width, ymin, ymax, height){
var x;
var y;
var dx;
var dy;
var xaxis;
var yaxis;
y = ymax;
dx = (xmax-xmin)/width;
dy = (ymax-ymin)/height;
sys_print("Plotting x from ", xmin, " to ", xmax, " and y from ", ymin, " to ", ymax, "\n");
while(y > ymin){
xaxis = (abs(y) <= dy/2);
x = xmin;
while(x < xmax){
yaxis = (abs(x) <= dx/2);
//FUNCTION TO BE PLOTTED IS HARD CODED IN THE LINE BELOW
//REPLACE math_sin() WITH ANOTHER FUNCTION TO CHANGE PLOT
if(abs(math_cos(x)-y) <= dy/2){
sys_print("#");
}
else if(yaxis && xaxis){
sys_print("+");
}
else if(yaxis){
sys_print("|");
}
else if(xaxis){
sys_print("-");
}
else{
sys_print(" ");
}
//sys_print(x);
//sys_print(", ");
x = x + dx;
}
sys_print("\n");
y = y - dy;
}
}
function advplot(xmin, xmax, width, ymin, ymax, height){
var x;
var y;
var dx;
var dy;
var xaxis;
var yaxis;
y = ymax;
dx = (xmax-xmin)/width;
dy = (ymax-ymin)/height;
sys_print("Plotting x from ", xmin, " to ", xmax, " and y from ", ymin, " to ", ymax, "\n");
while(y > ymin){
xaxis = (abs(y) <= dy/2);
x = xmin;
while(x < xmax){
yaxis = (abs(x) <= dx/2);
//FUNCTION TO BE PLOTTED IS HARD CODED IN THE LINE BELOW
//REPLACE math_sin() WITH ANOTHER FUNCTION TO CHANGE PLOT
if(abs(math_sin(x)-y) <= dy/2){
if(math_cos(x) <= 0-0.5){
sys_print("\\");}
else if(math_cos(x) >= 0.5){
sys_print("/");}
else{
sys_print("=");}
}
else if(yaxis && xaxis){
sys_print("+");
}
else if(yaxis){
sys_print("|");
}
else if(xaxis){
sys_print("-");
}
else{
sys_print(" ");
}
//sys_print(x);
//sys_print(", ");
x = x + dx;
}
sys_print("\n");
y = y - dy;
}
}
function exported main(){
advplot(0-7, 07, 80, 0-1.2, 1.2, 11);
}