This modified version of Python Turtle allows to render the turtle within a web page. See trycoding.io for more information and running examples.
It uses custom file descriptors for sending and receiving information from the client renderer.
""" | |
This backend overrides the pyplot show method for rendering mpl figures. It | |
tries to send the figure as an PNG-Image over the file descriptor 3 to a | |
listener. | |
The data is sent as binary in the following format: | |
STARTIMAGE IMAGEDATA ENDIMAGE | |
""" | |
from __future__ import (absolute_import, division, print_function, | |
unicode_literals) |
import os | |
import sys | |
import io | |
import traceback | |
# Set the current working dir to the project | |
if len(sys.argv) < 2: | |
print("No project path supplied for the tester") | |
sys.exit() |
""" | |
The MIT License (MIT) | |
Copyright (c) 2016 https://github.com/gradescope/gradescope-utils | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FR |
----- | |
from math import * | |
def differentiate(f, method, h=1.0E-5): | |
#h = float(h) # Ganzzahldivision vermeiden (in Python < 3.0.0) | |
if method == 'Forward1': |