def __init__(self): turtle.set_defaults( turtle_canvas_wrapper=document['pydiv'], canvwidth=600, # default is 500 canvheight=400, # default is 500 ) #window = turtle.Screen() #window.setup(width=800, height=600, startx=10, starty=0.5) self.blahaj = blahaj = turtle.Turtle("turtle") blahaj.shape("turtle") blahaj.penup() blahaj.setpos(-390, 0) blahaj.pendown()
def run_turtle(): # Reset the canvas try: del doc["turtle-canvas"] except: pass # Initialize the turtle import turtle canvas_size = doc["turtle-panel"].getBoundingClientRect().width turtle.set_defaults(canvwidth=canvas_size, canvheight=canvas_size, turtle_canvas_wrapper=doc["container"], turtle_canvas_id="turtle-canvas") t = turtle.Turtle() # Get the user code from ace code = editor.getValue() try: # Clear the previous error doc["error"].innerHTML = "" # Execute the code exec(code) except Exception as e: # If the code is wrong, display the error panel text = str(e) if isinstance(e, SyntaxError): a = e.args text = "At line {}, char {}: {}: \"{}\"".format(a[2], a[3], a[0], a[-1]) html = """ <div class="panel panel-danger"> <div class="panel-heading"> <h3 class="panel-title">{}</h3> </div> <div class="panel-body">{}</div> </div>""".format(e.__name__, text) doc["error"].innerHTML = html # Finalize the drawing turtle.Screen().end() # Brython's turtle is impossible to reset... # F**k this shit, delete the whole module. import sys del sys.modules["turtle"]
from browser import document, html # 設定 Python 執行結果的容器 container = document['python'] # Python 執行結果 <div id="python"></div> for c in "w3-container w3-half w3-margin-top".split(' '): # 設定基本版型 container.classList.add(c) # 小海龜繪圖模組 import turtle import myTurtle container <= html.DIV(html.H2('小海龜繪圖模組'), Class="w3-container w3-blue w3-margin-top") turtleDiv = html.DIV(Class="w3-border") turtle.set_defaults( turtle_canvas_wrapper=turtleDiv ) screen = turtle.Screen() # screen.setup(40, 40) turtle.tracer(1) # Turns off screen updates grid = turtle.Turtle() grid.penup() grid.width(1) grid.color('lightgrey') grid.speed(0) STEP = 30 OFFSET = 15 LENGTH = 300 grid.home()
""" Brython-Server turtle import wrapper Author: E Dennison """ from browser import document from turtle import * from turtle import set_defaults, FormattedTuple set_defaults(turtle_canvas_wrapper=document["graphics-column"]) # Redefine done _done = done def done(): _done() Screen().reset() Turtle._pen = None # Redefine FormattedTuple to support abs() _FormattedTuple = FormattedTuple class FormattedTuple(_FormattedTuple): def __abs__(self): return (self[0] ** 2 + self[1] ** 2) ** 0.5
# roberta.danae.turtle.py # SPDX-License-Identifier: GPL-3.0-or-later """ Projeto sem descrição, (mude esta linha). .. codeauthor:: Nome Sobrenome <*****@*****.**> Changelog --------- .. versionadded:: 20.09 Descreva o que você adicionou no código. """ from browser import document import turtle turtle.set_defaults(turtle_canvas_wrapper=document['pydiv'], canvwidth=200, canvheight=200) t = turtle.Turtle() t.width(5) for c in ['red', '#00ff00', '#fa0', 'rgb(0,0,200)']: t.color(c) t.forward(50) t.left(90) #turtle.done()
# Editor setting. editor.getSession().setMode('ace/mode/python') editor.setOptions({ 'behavioursEnabled': False, }) editor.focus() # Turtle graphics # NOTE: the following code might need to be rewritten for the next version of # Brython. _turtles = set() turtle.set_defaults(canvwidth=420, canvheight=420, turtle_canvas_wrapper=document['turtle-div']) _turtle_orig_goto = turtle.Turtle._goto def _turtle_new_goto(self, *args): _turtle_orig_goto(self, *args) _turtles.add(self) turtle.Turtle._goto = _turtle_new_goto def clear_turtle(): """Clear the turtle graphics."""