jyve icon indicating copy to clipboard operation
jyve copied to clipboard

Add brython turtle example

Open bollwyvl opened this issue 7 years ago • 2 comments

Not really packaged at present...

https://www.brython.info/gallery/turtle.html

bollwyvl avatar May 06 '18 17:05 bollwyvl

FWIW, here's a test program that works with the Brython editor (which has syntax highlighting and tab-completion) https://brython.info/tests/editor.html?lang=en

# Click "Add <div id=main>"
from browser import document
import turtle
turtle.set_defaults(turtle_canvas_wrapper=document['main'])
t = turtle.Turtle()

t.width(5)
for c in ['red', '#00ff00', '#fa0', 'rgb(0,0,200)']:
    t.color(c)
    t.forward(100)
    t.left(90)

# dot() and write() do not require the pen to be down
t.penup()
t.goto(-30, -100)
t.dot(40, 'rgba(255, 0, 0, 0.5')
t.goto(30, -100)
t.dot(40, 'rgba(0, 255, 0, 0.5')
t.goto(0, -70)
t.dot(40, 'rgba(0, 0, 255, 0.5')

t.goto(0, 125)
t.color('purple')
t.write("I love Brython!", font=("Arial", 20, "normal"))


turtle.done()

It's just the "Square with default turtle" gallery example with turtle.set_defaults(turtle_canvas_wrapper=document['main'])

westurner avatar Oct 28 '19 06:10 westurner

  • [ ] In Jyve, with this input:
from browser import document, html
import turtle
document <= html.DIV(Id="main") + "exampletext"
print(document["main"])

turtle.set_defaults(
    turtle_canvas_wrapper=document['main']
)
'''
print(dir(turtle))
t = turtle.Turtle()

t.width(5)

for c in ['red', '#00ff00', '#fa0', 'rgb(0,0,200)']:
    t.color(c)
    t.forward(100)
    t.left(90)
turtle.done()
'''

I get the following error as output on first invocation:

Error

_b_.AttributeError.$factory@about:blank line 113 > scriptElement line 6773 > eval:34:413
$B.$getattr@about:blank line 113 > scriptElement:6012:26
$module<@about:blank line 113 > scriptElement line 7554 > eval:23:48
@about:blank line 113 > scriptElement line 7554 > eval:1265:2
run_py@about:blank line 113 > scriptElement:7554:1
exec_module@about:blank line 113 > scriptElement:7613:1
cl_method@about:blank line 113 > scriptElement:5048:33
import_hooks@about:blank line 113 > scriptElement:12018:5
$B.$__import__@about:blank line 113 > scriptElement:7766:78
$B.$import@about:blank line 113 > scriptElement:7798:43
$module<@about:blank line 113 > scriptElement line 7554 > eval:14:12
@about:blank line 113 > scriptElement line 7554 > eval:6351:2
run_py@about:blank line 113 > scriptElement:7554:1
exec_module@about:blank line 113 > scriptElement:7613:1
cl_method@about:blank line 113 > scriptElement:5048:33
import_hooks@about:blank line 113 > scriptElement:12018:5
$B.$__import__@about:blank line 113 > scriptElement:7766:78
$B.$import@about:blank line 113 > scriptElement:7798:43
@https://deathbeds.github.io/jyve/lab/static/vendors~main.3d7fe7cfad7a83eaa75f.js line 25561 > eval:23:8
execute/</</<@https://deathbeds.github.io/jyve/lab/static/vendors~main.3d7fe7cfad7a83eaa75f.js:25561:37
execute/</<@https://deathbeds.github.io/jyve/lab/static/vendors~main.3d7fe7cfad7a83eaa75f.js:25562:19
execute/<@https://deathbeds.github.io/jyve/lab/static/vendors~main.3d7fe7cfad7a83eaa75f.js:25555:20
fulfilled@https://deathbeds.github.io/jyve/lab/static/vendors~main.3d7fe7cfad7a83eaa75f.js:25511:58

And then this output and error (on the turtle.set_defaults() call) when I Ctrl-Enter without restarting first:

<HTMLDivElement object>

TypeError: obj is null

$B.$getattr@about:blank line 113 > scriptElement:6001:14
@https://deathbeds.github.io/jyve/lab/static/vendors~main.3d7fe7cfad7a83eaa75f.js line 25561 > eval:26:17
execute/</</<@https://deathbeds.github.io/jyve/lab/static/vendors~main.3d7fe7cfad7a83eaa75f.js:25561:37
execute/</<@https://deathbeds.github.io/jyve/lab/static/vendors~main.3d7fe7cfad7a83eaa75f.js:25562:19
execute/<@https://deathbeds.github.io/jyve/lab/static/vendors~main.3d7fe7cfad7a83eaa75f.js:25555:20
fulfilled@https://deathbeds.github.io/jyve/lab/static/vendors~main.3d7fe7cfad7a83eaa75f.js:25511:58

  • [ ] And "exampletext" isn't showing in the sidecar
  • [ ] And 'Restart and Run All' appears to not be resetting prompt numbers to zero.

westurner avatar Oct 28 '19 07:10 westurner