Pregunta

Given (x_top_left, y_top_left) and (x_low_right, y_low_right) in the Netlogo source, what should the width and height of the saved Netlogo applet be?

Background

I have a ton of authentic Netlogo files, prepared for courses and demos. Using Perl or Ruby, I'd like to export them in batch as an applet in different files, possibly related by a table of contents in a left frame or so. Much like "save as applet", but then in batch, to different HTML files.

All is trivial to do were it not that I got stuck in finding out which applet dimensions I am supposed to use in writing

<applet code="org.nlogo.lite.Applet" archive="NetLogoLite.jar"
       width="???" height="???">
<param name="DefaultModel" value="netlogofile.nlogo">
</applet>

Notice the ???. I searched for other Netlogo file parsers and encountered https://github.com/NetLogo/NetLogo/wiki/Model-file-format, which is not specific enough and https://github.com/rikblok/dokuwiki-plugin-netlogo/blob/master/syntax/applet.php which is a parser but yields results which appear useless to me. (I got it running but it seems to parse the Netlogo source wrongly.)

Netlogo file format

I figured out that the Netlogo file format is like the following (comments after semicolon)

@#$#@#$#@
GRAPHICS-WINDOW
210 ; x-coord of upper left corner
10  ; y-coord of upper left corner
544 ; x-coord of lower right corner?
215 ; y-coord of lower right corner?
-1
-1
2.77 ; patch size
1
10 ; font size
1
1
1
0
1
0 ; world-wrap
1 world-wrap
-45 ; min-pxcor
71 ; max-pcor
-33 ; min-pycor
29 max-pycor
0
0
1 ; show tick counter
ticks ; tick counter label

To get a feeling for the logics I parsed a few saved applets and got the following results:

(x_top_left, y_top_left) = (210, 10).
(x_low_right, y_low_right) = (649, 470).
Netlogo saves applet with width x height: 794 x 480.

(x_top_left, y_top_left) = (96, 10).
(x_low_right, y_low_right) = (535, 470).
Netlogo saves applet with width x height: 629 x 480.

(x_top_left, y_top_left) = (96, 10).
(x_low_right, y_low_right) = (483, 340).
Netlogo saves applet with width x height: 575 x 350.

(x_top_left, y_top_left) = (96, 10).
(x_low_right, y_low_right) = (396, 271).
Netlogo saves applet with width x height: 690 x 300.

From these data I tried to discover a pattern in these numbers but the relation between them frankly is beyond me.

My question is: given (x_top_left, y_top_left) and (x_low_right, y_low_right) in the Netlogo source, what should the width and height of the saved Netlogo applet be?

¿Fue útil?

Solución

You have to look at the dimensions of all of the widgets in the Interface tab, compute the bounding box for all of them together, and then add some slop.

I know of two implementations of this calculation, both pretty craptastic.

One is the one in NetLogo itself. It's here, split across two files:

The other is on the Perl scripts (Perl? yeah, it was 2002, barely been touched since) on the NetLogo website that serve up the applet versions of the Models Library models. Those scripts are in a private repo, but I made a gist of the relevant section:

I haven't looked at this stuff in donkey's years, but if you have questions about it, it's possible my memory could be jogged.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top