Skip to content

Commit 0d97232

Browse files
committed
Update html-rendering.md
1 parent d99b9bb commit 0d97232

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

v3/docs/html-rendering.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,38 @@ to contain a single `div` of class `bigText` with the loop index as its contents
2828
the code makes one final `setHTML` call to set the canvas to an image from my personal website.
2929

3030

31+
## Creating external modules
3132

32-
33-
The best way to take advantage of HTML rendering is to define a custom
34-
module to encapsulate the rendering code:
33+
It's really tedious to write out all of the HTML rendering code in the OPT input text box.
34+
Thus, the best way to take advantage of HTML rendering is to define a custom
35+
module to encapsulate all of the rendering code. Here is an example module:
3536

3637
https://github.com/pgbovine/OnlinePythonTutor/blob/master/v3/htmlexample_module.py
38+
39+
To get this module working with OPT, you need to first add its filename
40+
(e.g., 'htmlexample_module') to the CUSTOM_MODULE_IMPORTS variable in pg_logger.py, approximately here:
41+
42+
https://github.com/pgbovine/OnlinePythonTutor/blob/master/v3/pg_logger.py#L119
43+
44+
Here is
45+
<a href="http://pythontutor.com/visualize.html#code=from+htmlexample_module+import+ColorTable%0A%0At+%3D+ColorTable(3,+4)%0A%0At.set_color(0,+0,+'red')%0At.render_HTML()%0A%0At.set_color(1,+1,+'green')%0At.render_HTML()%0A%0At.set_color(2,+2,+'blue')%0At.render_HTML()%0A%0Afor+i+in+range(3)%3A%0A++++for+j+in+range(4)%3A%0A++++++++t.set_color(i,+j,+'gray')%0A++++++++t.render_HTML()&mode=display&cumulative=false&heapPrimitives=false&drawParentPointers=false&textReferences=false&showOnlyOutputs=false&py=2&curInstr=0">an example</a>
46+
of this module in action:
47+
48+
from htmlexample_module import ColorTable
49+
50+
t = ColorTable(3, 4)
51+
52+
t.set_color(0, 0, 'red')
53+
t.render_HTML()
54+
55+
t.set_color(1, 1, 'green')
56+
t.render_HTML()
57+
58+
t.set_color(2, 2, 'blue')
59+
t.render_HTML()
60+
61+
for i in range(3):
62+
for j in range(4):
63+
t.set_color(i, j, 'gray')
64+
t.render_HTML()
65+

0 commit comments

Comments
 (0)