11.55 Sample ‘fexport

Example of write to different file formats.

MGL code:

subplot 3 2 0:define y 0.95
define d 0.3:define x0 0.2:define x1 0.5:define x2 0.6
line x0 1-0*d x1 1-0*d 'k-':text x2 y-0*d 'Solid `-`' ':rL'
line x0 1-1*d x1 1-1*d 'k|':text x2 y-1*d 'Long Dash `|`' ':rL'
line x0 1-2*d x1 1-2*d 'k;':text x2 y-2*d 'Dash 1;`' ':rL'
line x0 1-3*d x1 1-3*d 'k=':text x2 y-3*d 'Small dash `=`' ':rL'
line x0 1-4*d x1 1-4*d 'kj':text x2 y-4*d 'Dash-dot `j`' ':rL'
line x0 1-5*d x1 1-5*d 'ki':text x2 y-5*d 'Small dash-dot `i`' ':rL'
line x0 1-6*d x1 1-6*d 'k:':text x2 y-6*d 'Dots `:`' ':rL'
line x0 1-7*d x1 1-7*d 'k ':text x2 y-7*d 'None ``' ':rL'
define d 0.25:define x0 -0.8:define x1 -1:define x2 -0.05
ball x1 5*d 'k.':text x0 5*d '.' ':rL'
ball x1 4*d 'k+':text x0 4*d '+' ':rL'
ball x1 3*d 'kx':text x0 3*d 'x' ':rL'
ball x1 2*d 'k*':text x0 2*d '*' ':rL'
ball x1 d 'ks':text x0 d 's' ':rL'
ball x1 0 'kd':text x0 0 'd' ':rL'
ball x1 -d 0 'ko':text x0 y-d 'o' ':rL'
ball x1 -2*d 0 'k^':text x0 -2*d '\^' ':rL'
ball x1 -3*d 0 'kv':text x0 -3*d 'v' ':rL'
ball x1 -4*d 0 'k<':text x0 -4*d '<' ':rL'
ball x1 -5*d 0 'k>':text x0 -5*d '>' ':rL'

define x0 -0.3:define x1 -0.5
ball x1 5*d 'k#.':text x0 5*d '\#.' ':rL'
ball x1 4*d 'k#+':text x0 4*d '\#+' ':rL'
ball x1 3*d 'k#x':text x0 3*d '\#x' ':rL'
ball x1 2*d 'k#*':text x0 2*d '\#*' ':rL'
ball x1 d 'k#s':text x0 d '\#s' ':rL'
ball x1 0 'k#d':text x0 0 '\#d' ':rL'
ball x1 -d 0 'k#o':text x0 -d '\#o' ':rL'
ball x1 -2*d 0 'k#^':text x0 -2*d '\#\^' ':rL'
ball x1 -3*d 0 'k#v':text x0 -3*d '\#v' ':rL'
ball x1 -4*d 0 'k#<':text x0 -4*d '\#<' ':rL'
ball x1 -5*d 0 'k#>':text x0 -5*d '\#>' ':rL'

subplot 3 2 1
define a 0.1:define b 0.4:define c 0.5
line a 1 b 1 'k-A':text c 1 'Style `A` or `A\_`' ':rL'
line a 0.8 b 0.8 'k-V':text c 0.8 'Style `V` or `V\_`' ':rL'
line a 0.6 b 0.6 'k-K':text c 0.6 'Style `K` or `K\_`' ':rL'
line a 0.4 b 0.4 'k-I':text c 0.4 'Style `I` or `I\_`' ':rL'
line a 0.2 b 0.2 'k-D':text c 0.2 'Style `D` or `D\_`' ':rL'
line a 0 b 0 'k-S':text c 0 'Style `S` or `S\_`' ':rL'
line a -0.2 b -0.2 'k-O':text c -0.2 'Style `O` or `O\_`' ':rL'
line a -0.4 b -0.4 'k-T':text c -0.4 'Style `T` or `T\_`' ':rL'
line a -0.6 b -0.6 'k-_':text c -0.6 'Style `\_` or none' ':rL'
line a -0.8 b -0.8 'k-AS':text c -0.8 'Style `AS`' ':rL'
line a -1 b -1 'k-_A':text c -1 'Style `\_A`' ':rL'

define a -1:define b -0.7:define c -0.6
line a 1 b 1 'kAA':text c 1 'Style `AA`' ':rL'
line a 0.8 b 0.8 'kVV':text c 0.8 'Style `VV`' ':rL'
line a 0.6 b 0.6 'kKK':text c 0.6 'Style `KK`' ':rL'
line a 0.4 b 0.4 'kII':text c 0.4 'Style `II`' ':rL'
line a 0.2 b 0.2 'kDD':text c 0.2 'Style `DD`' ':rL'
line a 0 b 0 'kSS':text c 0 'Style `SS`' ':rL'
line a -0.2 b -0.2 'kOO':text c -0.2 'Style `OO`' ':rL'
line a -0.4 b -0.4 'kTT':text c -0.4 'Style `TT`' ':rL'
line a -0.6 b -0.6 'k-__':text c -0.6 'Style `\_\_`' ':rL'
line a -0.8 b -0.8 'k-VA':text c -0.8 'Style `VA`' ':rL'
line a -1 b -1 'k-AV':text c -1 'Style `AV`' ':rL'

subplot 3 2 2
#LENUQ

facez -1 -1 0 0.4 0.3 'L#':text -0.8 -0.9 'L' 'w:C' -1.4
facez -0.6 -1 0 0.4 0.3 'E#':text -0.4 -0.9 'E' 'w:C' -1.4
facez -0.2 -1 0 0.4 0.3 'N#':text 0 -0.9 'N' 'w:C' -1.4
facez 0.2 -1 0 0.4 0.3 'U#':text 0.4 -0.9 'U' 'w:C' -1.4
facez 0.6 -1 0 0.4 0.3 'Q#':text 0.8 -0.9 'Q' 'w:C' -1.4
#lenuq
facez -1 -0.7 0 0.4 0.3 'l#':text -0.8 -0.6 'l' 'k:C' -1.4
facez -0.6 -0.7 0 0.4 0.3 'e#':text -0.4 -0.6 'e' 'k:C' -1.4
facez -0.2 -0.7 0 0.4 0.3 'n#':text 0 -0.6 'n' 'k:C' -1.4
facez 0.2 -0.7 0 0.4 0.3 'u#':text 0.4 -0.6 'u' 'k:C' -1.4
facez 0.6 -0.7 0 0.4 0.3 'q#':text 0.8 -0.6 'q' 'k:C' -1.4
#CMYkP
facez -1 -0.4 0 0.4 0.3 'C#':text -0.8 -0.3 'C' 'w:C' -1.4
facez -0.6 -0.4 0 0.4 0.3 'M#':text -0.4 -0.3 'M' 'w:C' -1.4
facez -0.2 -0.4 0 0.4 0.3 'Y#':text 0 -0.3 'Y' 'w:C' -1.4
facez 0.2 -0.4 0 0.4 0.3 'k#':text 0.4 -0.3 'k' 'w:C' -1.4
facez 0.6 -0.4 0 0.4 0.3 'P#':text 0.8 -0.3 'P' 'w:C' -1.4
#cmywp
facez -1 -0.1 0 0.4 0.3 'c#':text -0.8 0 'c' 'k:C' -1.4
facez -0.6 -0.1 0 0.4 0.3 'm#':text -0.4 0 'm' 'k:C' -1.4
facez -0.2 -0.1 0 0.4 0.3 'y#':text 0 0 'y' 'k:C' -1.4
facez 0.2 -0.1 0 0.4 0.3 'w#':text 0.4 0 'w' 'k:C' -1.4
facez 0.6 -0.1 0 0.4 0.3 'p#':text 0.8 0 'p' 'k:C' -1.4
#BGRHW
facez -1 0.2 0 0.4 0.3 'B#':text -0.8 0.3 'B' 'w:C' -1.4
facez -0.6 0.2 0 0.4 0.3 'G#':text -0.4 0.3 'G' 'w:C' -1.4
facez -0.2 0.2 0 0.4 0.3 'R#':text 0 0.3 'R' 'w:C' -1.4
facez 0.2 0.2 0 0.4 0.3 'H#':text 0.4 0.3 'H' 'w:C' -1.4
facez 0.6 0.2 0 0.4 0.3 'W#':text 0.8 0.3 'W' 'w:C' -1.4
#bgrhw
facez -1 0.5 0 0.4 0.3 'b#':text -0.8 0.6 'b' 'k:C' -1.4
facez -0.6 0.5 0 0.4 0.3 'g#':text -0.4 0.6 'g' 'k:C' -1.4
facez -0.2 0.5 0 0.4 0.3 'r#':text 0 0.6 'r' 'k:C' -1.4
facez 0.2 0.5 0 0.4 0.3 'h#':text 0.4 0.6 'h' 'k:C' -1.4
facez 0.6 0.5 0 0.4 0.3 'w#':text 0.8 0.6 'w' 'k:C' -1.4
#brighted
facez -1 0.8 0 0.4 0.3 '{r1}#':text -0.8 0.9 '\{r1\}' 'w:C' -1.4
facez -0.6 0.8 0 0.4 0.3 '{r3}#':text -0.4 0.9 '\{r3\}' 'w:C' -1.4
facez -0.2 0.8 0 0.4 0.3 '{r5}#':text 0 0.9 '\{r5\}' 'k:C' -1.4
facez 0.2 0.8 0 0.4 0.3 '{r7}#':text 0.4 0.9 '\{r7\}' 'k:C' -1.4
facez 0.6 0.8 0 0.4 0.3 '{r9}#':text 0.8 0.9 '\{r9\}' 'k:C' -1.4
# HEX
facez -1 -1.3 0 1 0.3 '{xff9966}#':text -0.5 -1.2 '\{xff9966\}' 'k:C' -1.4
facez 0 -1.3 0 1 0.3 '{x83CAFF}#':text 0.5 -1.2 '\{x83caff\}' 'k:C' -1.4

subplot 3 2 3
for $i 0 9
line -1 0.2*$i-1 1 0.2*$i-1 'r','0'+$i
text 1.05 0.2*$i-1 '0'+$i ':L'
next

subplot 3 2 4:title 'TriPlot sample':rotate 50 60
list tt 0 1 2 | 0 1 3 | 0 2 3 | 1 2 3
list xt -1 1 0 0:list yt -1 -1 1 0:list zt -1 -1 -1 1:light on
triplot tt xt yt zt 'b':triplot tt xt yt zt 'k#'

subplot 3 2 5:new r 4 'i+1':ranges 1 4 1 4
axis:mark r r 's':plot r 'b'
write 'fexport.jpg':#write 'fexport.png'
write 'fexport.bmp':write 'fexport.tga'
write 'fexport.eps':write 'fexport.svg'
write 'fexport.gif':write 'fexport.xyz'
write 'fexport.stl':write 'fexport.off'
write 'fexport.tex':write 'fexport.obj'
write 'fexport.prc':write 'fexport.json'
write 'fexport.mgld'

C++ code:

void smgl_fexport(mglGraph *gr)	// test file export
{
	all_prims(gr);
	gr->WriteJPEG("fexport.jpg");
//	gr->WritePNG("fexport.png");
	gr->WriteBMP("fexport.bmp");
	gr->WriteTGA("fexport.tga");
	gr->WriteEPS("fexport.eps");
	gr->WriteSVG("fexport.svg");
	gr->WriteGIF("fexport.gif");

	gr->WriteXYZ("fexport.xyz");
	gr->WriteSTL("fexport.stl");
	gr->WriteOFF("fexport.off");
	gr->WriteTEX("fexport.tex");
	gr->WriteOBJ("fexport.obj");
	gr->WritePRC("fexport.prc");
	gr->WriteJSON("fexport.json");

	gr->ExportMGLD("fexport.mgld");
	gr->Clf();
	gr->ImportMGLD("fexport.mgld");
}

Sample fexport