Re: Turtle in browser

142 views
Skip to first unread message
Message has been deleted

Pierre Quentel

unread,
Oct 2, 2016, 3:46:01 AM10/2/16
to brython


Le samedi 1 octobre 2016 22:18:36 UTC+2, roberci...@gmail.com a écrit :
I have this code which works on Skulpt, but didn't work on Brython on local server? Why?

<!doctype html>
<html>
<head>

 
<script type=text/javascript src="../src/brython.js"></script>

<script id="python_script" type="text/python">
 from browser
import document, console
 _code
=document["div_html"].text

 exec
(_code)
 document
["processing"].style.display="none"
</script>

<style type="text/css">
.blink {
 animation
: blink 1s steps(5, start) infinite;
 
-webkit-animation: blink 1s steps(5, start) infinite;
}
@keyframes blink {
 to
{ visibility: hidden; }
}
@-webkit-keyframes blink {
 to
{ visibility: hidden; }
}
</style>

</head>

<body onload="brython(1)">
<pre id="div_html" style="float:left">
#
# SOURCE CODE
#
import random
import turtle

def tree(size, myTurtle):
 myTurtle.pensize(size / 10)

 if size < random.randint(1,2) * 20:
 myTurtle.color("green")
 else:
 myTurtle.color("brown")

 if size > 5:
 myTurtle.forward(size)
 myTurtle.left(25)
 tree(size - random.randint(10, 20), myTurtle)
 myTurtle.right(50)
 tree(size - random.randint(10, 20), myTurtle)
 myTurtle.left(25)
 myTurtle.penup()
 myTurtle.backward(size)
 myTurtle.pendown()


window = turtle.Screen()
window.bgcolor("black")

myTurtle = turtle.Turtle()
myTurtle.color("brown", "blue")
myTurtle.left(90)
myTurtle.speed(0)
myTurtle.penup()
myTurtle.setpos(0, -250)
myTurtle.pendown()

tree(120, myTurtle)

turtle._Screen().end()
</pre>

<div id="container"
 
style="float:left;border-style:solid;border-color:black;margin-left:50px"></div>
</body>

<div id="processing" class="blink"
 
style="color:red;position:absolute;z-index:100;width:250px;height:100px;top:50%;left:50%;margin 0 auto;">Processing... Please wait..
</div>

</html>



Can you help me?
When I try to run this code I get an IndentationError after the first "if". Can you send a correctly indented version ?
Message has been deleted

Pierre Quentel

unread,
Oct 2, 2016, 1:22:55 PM10/2/16
to brython


Le dimanche 2 octobre 2016 14:04:50 UTC+2, roberci...@gmail.com a écrit :
This should be work:
http://wklej.org/id/2873431/


The interface of the turtle module for Brython, written by Billy Earney, is not exactly the same. I adapted it to make it work, but Billy would probably have a better version

import random
import turtle

nb = 0


def tree(size, myTurtle):
    myTurtle.pensize(size / 10)

    if size < random.randint(1,2) * 20:
        myTurtle.color("green")
    else:
        myTurtle.color("brown")

    if size > 5:
        myTurtle.forward(size)
        myTurtle.left(25)
        tree(size - random.randint(10, 20), myTurtle)
        myTurtle.right(50)
        tree(size - random.randint(10, 20), myTurtle)
        myTurtle.left(25)
        myTurtle.penup()
        myTurtle.backward(size)
        myTurtle.pendown()

w = turtle.Screen()

w.bgcolor("black")

myTurtle = turtle.Turtle()
t1 = turtle.Turtle('turtle')

t1.color("brown", "blue")

t1.right(90)
t1.penup()
t1.backward(200)
t1.pendown()

tree(120, t1)

turtle._Screen().end()

Message has been deleted

Pierre Quentel

unread,
Oct 3, 2016, 1:50:38 AM10/3/16
to brython


Le dimanche 2 octobre 2016 19:56:58 UTC+2, roberci...@gmail.com a écrit :
I use your code in turtle.html from gallery but still have "Processing...Please wait" on my browser.
http://imgur.com/a/LsSUC
 Do you see the animation ?
To remove the message "Processing, please wait", just remove the last DIV on the page

Pierre Quentel

unread,
Oct 3, 2016, 2:06:30 AM10/3/16
to brython
I just realize that I didn't commit and push a bug fix that broke your code. Can you try with the latest development version ?

Christophe Bal

unread,
Oct 3, 2016, 2:35:36 AM10/3/16
to bry...@googlegroups.com
Hello.
$I have tried the example and I only see a black square that does not move.


Christophe BAL
Enseignant de mathématiques en Lycée et développeur Python amateur
---
French teacher of math in a high school and amateur Python developer

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+unsubscribe@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/b5ff17ac-e9ec-414c-aca8-545be8b4971a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Christophe Bal

unread,
Oct 3, 2016, 7:43:59 AM10/3/16
to bry...@googlegroups.com
Is there a CDN for the latest latest development version ?


Christophe BAL
Enseignant de mathématiques en Lycée et développeur Python amateur
---
French teacher of math in a high school and amateur Python developer

2016-10-03 13:09 GMT+02:00 <roberci...@gmail.com>:
Now works fine. Can I speed up animation of turtle?
Something like
t1.speed(0)

Also how change the drawing area?
In Skulpt I use:
window.setup(800,600)

Thanks

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+unsubscribe@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.

Kiko

unread,
Oct 3, 2016, 7:52:13 AM10/3/16
to bry...@googlegroups.com
2016-10-03 13:43 GMT+02:00 Christophe Bal <proj...@gmail.com>:
Is there a CDN for the latest latest development version ?

You can always use rawgit: https://rawgit.com/

This is the url for the latest brython_dist.js file:
https://rawgit.com/brython-dev/brython/master/www/src/brython_dist.js


 

Christophe Bal

unread,
Oct 3, 2016, 7:59:28 AM10/3/16
to bry...@googlegroups.com
Thanks for this.

The code works on Firefox but not in Safari.


Christophe BAL
Enseignant de mathématiques en Lycée et développeur Python amateur
---
French teacher of math in a high school and amateur Python developer

Pierre Quentel

unread,
Oct 3, 2016, 8:54:58 AM10/3/16
to brython


Le lundi 3 octobre 2016 13:09:59 UTC+2, roberci...@gmail.com a écrit :
Now works fine. Can I speed up animation of turtle?
Something like
t1.speed(0)

I added support of speed in the turtle module in the latest revision. Set it to 1 for slowest, 10 for fastest.
Also how change the drawing area?
In Skulpt I use:
window.setup(800,600)
I don't know. If Billy reads this, does he have the answer ?

Thanks

W dniu poniedziałek, 3 października 2016 08:06:30 UTC+2 użytkownik Pierre Quentel napisał:
Reply all
Reply to author
Forward
0 new messages