ducky-python-module 0.1.4__tar.gz → 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/PKG-INFO +10 -3
- ducky_python_module-1.0.0/README.md +14 -0
- {ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/pyproject.toml +1 -1
- {ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/src/ducky/main.py +291 -315
- {ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/src/ducky_python_module.egg-info/PKG-INFO +10 -3
- ducky_python_module-0.1.4/README.md +0 -7
- {ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/LICENSE.txt +0 -0
- {ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/setup.cfg +0 -0
- {ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/src/ducky/__init__.py +0 -0
- {ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/src/ducky_python_module.egg-info/SOURCES.txt +0 -0
- {ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/src/ducky_python_module.egg-info/dependency_links.txt +0 -0
- {ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/src/ducky_python_module.egg-info/requires.txt +0 -0
- {ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/src/ducky_python_module.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ducky-python-module
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Ducky Python module
|
|
5
5
|
Author: Tom
|
|
6
6
|
License: Creative Commons Attribution-NonCommercial 4.0 International Public
|
|
@@ -346,8 +346,15 @@ Dynamic: license-file
|
|
|
346
346
|
|
|
347
347
|
# Ducky-Python-Module
|
|
348
348
|
A collection of tools for python
|
|
349
|
-
Still in progress
|
|
349
|
+
Still in progress and will be releasing fully soon
|
|
350
350
|
Credit:
|
|
351
351
|
Turtle library has been used and modified. I did not make it and I did include the text from the original library explaining rights to the Turtle program which I am not allowed to remove.
|
|
352
352
|
Nltk has been imported but not modified.
|
|
353
|
-
|
|
353
|
+
Full import list:
|
|
354
|
+
import random, time, os, tkinter as TK, types, math, inspect, sys, requests, json, numpy, ast, logging
|
|
355
|
+
from os.path import isfile, split, join
|
|
356
|
+
from copy import deepcopy
|
|
357
|
+
from tkinter import simpledialog
|
|
358
|
+
from turtle import Turtle
|
|
359
|
+
from nltk.tokenize import word_tokenize
|
|
360
|
+
from nltk.stem import LancasterStemmer
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Ducky-Python-Module
|
|
2
|
+
A collection of tools for python
|
|
3
|
+
Still in progress and will be releasing fully soon
|
|
4
|
+
Credit:
|
|
5
|
+
Turtle library has been used and modified. I did not make it and I did include the text from the original library explaining rights to the Turtle program which I am not allowed to remove.
|
|
6
|
+
Nltk has been imported but not modified.
|
|
7
|
+
Full import list:
|
|
8
|
+
import random, time, os, tkinter as TK, types, math, inspect, sys, requests, json, numpy, ast, logging
|
|
9
|
+
from os.path import isfile, split, join
|
|
10
|
+
from copy import deepcopy
|
|
11
|
+
from tkinter import simpledialog
|
|
12
|
+
from turtle import Turtle
|
|
13
|
+
from nltk.tokenize import word_tokenize
|
|
14
|
+
from nltk.stem import LancasterStemmer
|
|
@@ -102,6 +102,15 @@ def stem(string):
|
|
|
102
102
|
def array(lst):
|
|
103
103
|
return numpy.array(lst)
|
|
104
104
|
|
|
105
|
+
def dot_product(mat1,mat2):
|
|
106
|
+
return numpy.dot(mat1,mat2)
|
|
107
|
+
|
|
108
|
+
def scale_matrices(mat,val):
|
|
109
|
+
return mat*val
|
|
110
|
+
|
|
111
|
+
def average_matrices(mat):
|
|
112
|
+
return numpy.average(mat)
|
|
113
|
+
|
|
105
114
|
def calc(param):
|
|
106
115
|
try:
|
|
107
116
|
return ast.literal_eval(param)
|
|
@@ -164,6 +173,68 @@ def modify(func,modifier):
|
|
|
164
173
|
|
|
165
174
|
#classes
|
|
166
175
|
|
|
176
|
+
class Tester:
|
|
177
|
+
_instances = []
|
|
178
|
+
@classmethod
|
|
179
|
+
def average(cls):
|
|
180
|
+
total_success = 0
|
|
181
|
+
total_errors = 0
|
|
182
|
+
for instance in cls._instances:
|
|
183
|
+
total_success += len(instance.success)
|
|
184
|
+
total_errors += len(instance.errors)
|
|
185
|
+
total_tests = total_success + total_errors
|
|
186
|
+
if total_tests == 0:
|
|
187
|
+
return 0
|
|
188
|
+
return (total_success / total_tests) * 100
|
|
189
|
+
def __init__(self):
|
|
190
|
+
self.errors = []
|
|
191
|
+
self.success = []
|
|
192
|
+
Tester._instances.append(self)
|
|
193
|
+
print("\033[0m")
|
|
194
|
+
def test(self,code, name="Unnamed"):
|
|
195
|
+
try:
|
|
196
|
+
exec(code, globals())
|
|
197
|
+
self.success.append(name)
|
|
198
|
+
print(f"\033[32mCode:\n{code}\n({name}) executed successfully\n")
|
|
199
|
+
|
|
200
|
+
except Exception as error:
|
|
201
|
+
print(f"\033[31m{error}\n")
|
|
202
|
+
self.errors.append(f"Line: {len(self.errors)+len(self.success)+1} {error}")
|
|
203
|
+
|
|
204
|
+
def results(self):
|
|
205
|
+
total = len(self.success) + len(self.errors)
|
|
206
|
+
if total == 0:
|
|
207
|
+
percent = 0
|
|
208
|
+
else:
|
|
209
|
+
percent = (len(self.success) / total) * 100
|
|
210
|
+
|
|
211
|
+
if percent == 100:
|
|
212
|
+
print("\033[92m------------------------------------------------------------")
|
|
213
|
+
print("\033[92mCompleted 100% successfully:\n")
|
|
214
|
+
|
|
215
|
+
elif percent >= 90:
|
|
216
|
+
print("\033[32m------------------------------------------------------------")
|
|
217
|
+
print("\033[32mCompleted 90% or more successfully:\n")
|
|
218
|
+
|
|
219
|
+
elif percent >= 80:
|
|
220
|
+
print("\033[33m------------------------------------------------------------")
|
|
221
|
+
print("\033[33mCompleted 80% or more successfully:\n")
|
|
222
|
+
elif percent >= 70:
|
|
223
|
+
print("\033[38;5;208m------------------------------------------------------------")
|
|
224
|
+
print("\033[38;5;208mCompleted 70% or more successfully:\n")
|
|
225
|
+
else:
|
|
226
|
+
print("\033[91m------------------------------------------------------------")
|
|
227
|
+
print(f"\033[91mCompleted {percent}% successfully:\n")
|
|
228
|
+
if self.success:
|
|
229
|
+
print(f"\033[32mSuccessful tests:\n")
|
|
230
|
+
for s in self.success:
|
|
231
|
+
print(f"\033[32m{s}")
|
|
232
|
+
if len(self.errors) > 0:
|
|
233
|
+
print(f"\n\033[31mFailed tests:\n")
|
|
234
|
+
for e in self.errors:
|
|
235
|
+
print(f"\033[31m{e}")
|
|
236
|
+
|
|
237
|
+
|
|
167
238
|
class MatrixManager:
|
|
168
239
|
def __init__(self,background,fps,mat=None,wrapping=False,sprite_condition=1):
|
|
169
240
|
self.mat = mat
|
|
@@ -361,6 +432,221 @@ class Chatbot:
|
|
|
361
432
|
return 1
|
|
362
433
|
return None
|
|
363
434
|
|
|
435
|
+
|
|
436
|
+
#AI TEMPLATE
|
|
437
|
+
|
|
438
|
+
import mnist
|
|
439
|
+
import numpy
|
|
440
|
+
import abc
|
|
441
|
+
|
|
442
|
+
class ActivationFunction:
|
|
443
|
+
tanh = 0
|
|
444
|
+
sigmoid = 1
|
|
445
|
+
softmax = 2
|
|
446
|
+
@staticmethod
|
|
447
|
+
def __tanh(x: numpy.ndarray) -> numpy.ndarray:
|
|
448
|
+
return numpy.tanh(x)
|
|
449
|
+
|
|
450
|
+
@staticmethod
|
|
451
|
+
def __tanh_derivative(x: numpy.ndarray) -> numpy.ndarray:
|
|
452
|
+
return 1 - numpy.tanh(x) ** 2
|
|
453
|
+
|
|
454
|
+
@staticmethod
|
|
455
|
+
def use_tanh():
|
|
456
|
+
return ActivationFunction.tanh, ActivationFunction.__tanh, ActivationFunction.__tanh_derivative
|
|
457
|
+
|
|
458
|
+
@staticmethod
|
|
459
|
+
def __sigmoid(x):
|
|
460
|
+
return 1 / (1 + numpy.exp(-x))
|
|
461
|
+
|
|
462
|
+
@staticmethod
|
|
463
|
+
def __sigmoid_derivative(x):
|
|
464
|
+
s = 1 / (1 + numpy.exp(-x))
|
|
465
|
+
return s * (1 - s)
|
|
466
|
+
|
|
467
|
+
@staticmethod
|
|
468
|
+
def use_sigmoid():
|
|
469
|
+
return ActivationFunction.sigmoid, ActivationFunction.__sigmoid, ActivationFunction.__sigmoid_derivative
|
|
470
|
+
|
|
471
|
+
@staticmethod
|
|
472
|
+
def __softmax(x):
|
|
473
|
+
x = numpy.array(x)
|
|
474
|
+
e_x = numpy.exp(x - numpy.max(x))
|
|
475
|
+
return e_x / e_x.sum(axis=-1, keepdims=True)
|
|
476
|
+
|
|
477
|
+
@staticmethod
|
|
478
|
+
def __softmax_derivative(s):
|
|
479
|
+
s = s.reshape(-1, 1)
|
|
480
|
+
return numpy.diagflat(s) - numpy.dot(s, s.T)
|
|
481
|
+
|
|
482
|
+
@staticmethod
|
|
483
|
+
def use_softmax():
|
|
484
|
+
return ActivationFunction.softmax, ActivationFunction.__softmax, ActivationFunction.__softmax_derivative
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
class CostFunctions:
|
|
488
|
+
mse = 0
|
|
489
|
+
cross_entropy = 1
|
|
490
|
+
@staticmethod
|
|
491
|
+
def __mean_squared_error(actual: numpy.ndarray, predicted: numpy.ndarray):
|
|
492
|
+
return numpy.mean(numpy.power((actual - predicted), 2))
|
|
493
|
+
|
|
494
|
+
@staticmethod
|
|
495
|
+
def __mean_squared_error_derivative(actual: numpy.ndarray, predicted: numpy.ndarray) -> numpy.ndarray:
|
|
496
|
+
return 2 * (predicted - actual)/actual.size
|
|
497
|
+
|
|
498
|
+
@staticmethod
|
|
499
|
+
def use_mean_squared_error():
|
|
500
|
+
return CostFunctions.mse, CostFunctions.__mean_squared_error, CostFunctions.__mean_squared_error_derivative
|
|
501
|
+
|
|
502
|
+
@staticmethod
|
|
503
|
+
def __categorical_cross_entropy(actual: numpy.ndarray, predicted: numpy.ndarray):
|
|
504
|
+
epsilon = 1e-12
|
|
505
|
+
predicted = numpy.clip(predicted, epsilon, 1. - epsilon)
|
|
506
|
+
return -numpy.mean(numpy.sum(actual * numpy.log(predicted), axis=1))
|
|
507
|
+
|
|
508
|
+
@staticmethod
|
|
509
|
+
def __categorical_cross_entropy_derivative(actual: numpy.ndarray, predicted: numpy.ndarray):
|
|
510
|
+
return (predicted - actual) / actual.shape[0]
|
|
511
|
+
|
|
512
|
+
@staticmethod
|
|
513
|
+
def use_categorical_cross_entropy():
|
|
514
|
+
return CostFunctions.cross_entropy, CostFunctions.__categorical_cross_entropy, CostFunctions.__categorical_cross_entropy_derivative
|
|
515
|
+
|
|
516
|
+
class Layer(abc.ABC):
|
|
517
|
+
def __init__(self):
|
|
518
|
+
self.input = None
|
|
519
|
+
self.output = None
|
|
520
|
+
|
|
521
|
+
@abc.abstractmethod
|
|
522
|
+
def feed_forward(self, inputs: numpy.ndarray) -> numpy.ndarray:
|
|
523
|
+
pass
|
|
524
|
+
|
|
525
|
+
@abc.abstractmethod
|
|
526
|
+
def back_propagate(self, error: numpy.ndarray, learning_rate: float) -> numpy.ndarray:
|
|
527
|
+
pass
|
|
528
|
+
|
|
529
|
+
class FullyConnectedLayer(Layer):
|
|
530
|
+
def __init__(self, input_size: int, output_size: int):
|
|
531
|
+
super().__init__()
|
|
532
|
+
random_bound = 1.0 / numpy.sqrt(input_size)
|
|
533
|
+
self.weights = numpy.random.uniform(-random_bound, random_bound, (input_size, output_size))
|
|
534
|
+
self.bias = numpy.zeros((1, output_size))
|
|
535
|
+
|
|
536
|
+
def feed_forward(self, inputs: numpy.ndarray) -> numpy.ndarray:
|
|
537
|
+
self.input = inputs
|
|
538
|
+
self.output = numpy.dot(inputs, self.weights) + self.bias
|
|
539
|
+
return self.output
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
def back_propagate(self, error: numpy.ndarray, learning_rate: float) -> numpy.ndarray:
|
|
543
|
+
input_error = numpy.dot(error, self.weights.T)
|
|
544
|
+
weights_error = numpy.dot(self.input.T, error)
|
|
545
|
+
self.weights -= learning_rate * weights_error
|
|
546
|
+
self.bias -= learning_rate * numpy.mean(error, axis=0, keepdims=True)
|
|
547
|
+
return input_error
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
class ActivationLayer(Layer):
|
|
551
|
+
def __init__(self, ID, activation_function, activation_derivative):
|
|
552
|
+
super().__init__()
|
|
553
|
+
self.ID = ID
|
|
554
|
+
self.activation_function = activation_function
|
|
555
|
+
self.activation_derivative = activation_derivative
|
|
556
|
+
|
|
557
|
+
def feed_forward(self, inputs: numpy.ndarray) -> numpy.ndarray:
|
|
558
|
+
self.input = inputs
|
|
559
|
+
self.output = self.activation_function(inputs)
|
|
560
|
+
return self.output
|
|
561
|
+
|
|
562
|
+
def back_propagate(self, error: numpy.ndarray, learning_rate: float) -> numpy.ndarray:
|
|
563
|
+
if self.ID == ActivationFunction.softmax:
|
|
564
|
+
return error
|
|
565
|
+
else:
|
|
566
|
+
return self.activation_derivative(self.input) * error
|
|
567
|
+
|
|
568
|
+
class NeuralNetwork:
|
|
569
|
+
def __init__(self, ID, cost_function, cost_derivative):
|
|
570
|
+
self.ID = ID
|
|
571
|
+
self.layers = []
|
|
572
|
+
self.cost_function = cost_function
|
|
573
|
+
self.cost_derivative = cost_derivative
|
|
574
|
+
|
|
575
|
+
def add_layer(self, layer: Layer):
|
|
576
|
+
self.layers.append(layer)
|
|
577
|
+
|
|
578
|
+
def predict(self, inputs: numpy.ndarray) -> numpy.ndarray:
|
|
579
|
+
for layer in self.layers:
|
|
580
|
+
inputs = layer.feed_forward(inputs)
|
|
581
|
+
return inputs
|
|
582
|
+
|
|
583
|
+
def train(self, inputs: numpy.ndarray, outputs: numpy.ndarray, n_epochs: int, batch_size: int, learning_rate: float):
|
|
584
|
+
for epoch in range(n_epochs):
|
|
585
|
+
batch_index = 0
|
|
586
|
+
while batch_index < inputs.shape[0]:
|
|
587
|
+
if batch_index + batch_size < inputs.shape[0]:
|
|
588
|
+
output = inputs[batch_index:batch_index + batch_size, ]
|
|
589
|
+
actual = outputs[batch_index:batch_index + batch_size, ]
|
|
590
|
+
else:
|
|
591
|
+
output = inputs[batch_index:, ]
|
|
592
|
+
actual = outputs[batch_index:, ]
|
|
593
|
+
output = self.predict(output)
|
|
594
|
+
cost = self.cost_function(actual, output)
|
|
595
|
+
error = self.cost_derivative(actual, output)
|
|
596
|
+
for layer in reversed(self.layers):
|
|
597
|
+
error = layer.back_propagate(error, learning_rate)
|
|
598
|
+
print(f"Epoch: {epoch+1}/{n_epochs} | Batch: {batch_index}/{inputs.shape[0]} | Cost: {cost}")
|
|
599
|
+
batch_index += batch_size
|
|
600
|
+
|
|
601
|
+
def save(self, path: str):
|
|
602
|
+
with open(f"{path}.nn", "w") as save_file:
|
|
603
|
+
save_file.write(f"{self.ID}\n")
|
|
604
|
+
for index, layer in enumerate(self.layers):
|
|
605
|
+
if isinstance(layer, FullyConnectedLayer):
|
|
606
|
+
save_file.write(f"F|{index}|{layer.weights.shape[0]}|{layer.weights.shape[1]}\n")
|
|
607
|
+
numpy.save(f"{path}_{index}_w", layer.weights)
|
|
608
|
+
numpy.save(f"{path}_{index}_b", layer.bias)
|
|
609
|
+
elif isinstance(layer, ActivationLayer):
|
|
610
|
+
if layer.ID == ActivationFunction.tanh:
|
|
611
|
+
save_file.write(f"A|{index}|{ActivationFunction.tanh}\n")
|
|
612
|
+
elif layer.ID == ActivationFunction.sigmoid:
|
|
613
|
+
save_file.write(f"A|{index}|{ActivationFunction.sigmoid}\n")
|
|
614
|
+
elif layer.ID == ActivationFunction.softmax:
|
|
615
|
+
save_file.write(f"A|{index}|{ActivationFunction.softmax}\n")
|
|
616
|
+
else:
|
|
617
|
+
save_file.write(f"A|{index}|{ActivationFunction.tanh}\n")
|
|
618
|
+
@staticmethod
|
|
619
|
+
def load(path: str):
|
|
620
|
+
with open(f"{path}.nn", "r") as file:
|
|
621
|
+
lines = file.readlines()
|
|
622
|
+
cost_function_id = int(lines[0])
|
|
623
|
+
if cost_function_id == CostFunctions.mse:
|
|
624
|
+
neural_network = NeuralNetwork(*CostFunctions.use_mean_squared_error())
|
|
625
|
+
else:
|
|
626
|
+
neural_network = NeuralNetwork(*CostFunctions.use_mean_squared_error())
|
|
627
|
+
for line in lines[1:]:
|
|
628
|
+
if line != "":
|
|
629
|
+
parts = line.split("|")
|
|
630
|
+
if parts[0] == "F":
|
|
631
|
+
weights = numpy.load(f"{path}_{parts[1]}_w.npy")
|
|
632
|
+
bias = numpy.load(f"{path}_{parts[1]}_b.npy")
|
|
633
|
+
layer = FullyConnectedLayer(weights.shape[0], weights.shape[1])
|
|
634
|
+
layer.weights = weights
|
|
635
|
+
layer.bias = bias
|
|
636
|
+
neural_network.add_layer(layer)
|
|
637
|
+
elif parts[0] == "A":
|
|
638
|
+
activation_id = int(parts[2])
|
|
639
|
+
if activation_id == ActivationFunction.tanh:
|
|
640
|
+
neural_network.add_layer(ActivationLayer(*ActivationFunction.use_tanh()))
|
|
641
|
+
elif activation_id == ActivationFunction.sigmoid:
|
|
642
|
+
neural_network.add_layer(ActivationLayer(*ActivationFunction.use_sigmoid()))
|
|
643
|
+
elif activation_id == ActivationFunction.softmax:
|
|
644
|
+
neural_network.add_layer(ActivationLayer(*ActivationFunction.use_softmax()))
|
|
645
|
+
else:
|
|
646
|
+
neural_network.add_layer(ActivationLayer(*ActivationFunction.use_tanh()))
|
|
647
|
+
return neural_network
|
|
648
|
+
|
|
649
|
+
|
|
364
650
|
#turtlel
|
|
365
651
|
|
|
366
652
|
def dots(turt_name, number, random_colours=True, colours=None, minimum=20, maximum=100):
|
|
@@ -1087,13 +1373,7 @@ class TurtleScreenBase(object):
|
|
|
1087
1373
|
return self.cv.type(item)
|
|
1088
1374
|
|
|
1089
1375
|
def _pointlist(self, item):
|
|
1090
|
-
|
|
1091
|
-
Example (for insiders):
|
|
1092
|
-
>>> from turtle import *
|
|
1093
|
-
>>> getscreen()._pointlist(getturtle().turtle._item)
|
|
1094
|
-
[(0.0, 9.9999999999999982), (0.0, -9.9999999999999982),
|
|
1095
|
-
(9.9999999999999982, 0.0)]
|
|
1096
|
-
>>> """
|
|
1376
|
+
#returns list of coordinate-pairs of points of item
|
|
1097
1377
|
cl = self.cv.coords(item)
|
|
1098
1378
|
pl = [(cl[i], -cl[i+1]) for i in range(0, len(cl), 2)]
|
|
1099
1379
|
return pl
|
|
@@ -1383,10 +1663,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1383
1663
|
'standard' to the right (east) counterclockwise
|
|
1384
1664
|
'logo' upward (north) clockwise
|
|
1385
1665
|
|
|
1386
|
-
Examples:
|
|
1387
|
-
>>> mode('logo') # resets turtle heading to north
|
|
1388
|
-
>>> mode()
|
|
1389
|
-
'logo'
|
|
1390
1666
|
"""
|
|
1391
1667
|
if mode is None:
|
|
1392
1668
|
return self._mode
|
|
@@ -1416,11 +1692,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1416
1692
|
But ATTENTION: in user-defined coordinatesystems angles may appear
|
|
1417
1693
|
distorted. (see Screen.mode())
|
|
1418
1694
|
|
|
1419
|
-
Example (for a TurtleScreen instance named screen):
|
|
1420
|
-
>>> screen.setworldcoordinates(-10,-0.5,50,1.5)
|
|
1421
|
-
>>> for _ in range(36):
|
|
1422
|
-
... left(10)
|
|
1423
|
-
... forward(0.5)
|
|
1424
1695
|
"""
|
|
1425
1696
|
if self.mode() != "world":
|
|
1426
1697
|
self.mode("world")
|
|
@@ -1458,9 +1729,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1458
1729
|
call: register_shape("turtle.gif")
|
|
1459
1730
|
--or: register_shape("tri", ((0,0), (10,10), (-10,10)))
|
|
1460
1731
|
|
|
1461
|
-
Example (for a TurtleScreen instance named screen):
|
|
1462
|
-
>>> screen.register_shape("triangle", ((5,-3),(0,5),(-5,-3)))
|
|
1463
|
-
|
|
1464
1732
|
"""
|
|
1465
1733
|
if shape is None:
|
|
1466
1734
|
# image
|
|
@@ -1514,17 +1782,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1514
1782
|
|
|
1515
1783
|
def colourmode(self, cmode=None):
|
|
1516
1784
|
"""Return the colourmode or set it to 1.0 or 255.
|
|
1517
|
-
|
|
1518
|
-
Optional argument:
|
|
1519
|
-
cmode -- one of the values 1.0 or 255
|
|
1520
|
-
|
|
1521
|
-
r, g, b values of colourtriples have to be in range 0..cmode.
|
|
1522
|
-
|
|
1523
|
-
Example (for a TurtleScreen instance named screen):
|
|
1524
|
-
>>> screen.colourmode()
|
|
1525
|
-
1.0
|
|
1526
|
-
>>> screen.colourmode(255)
|
|
1527
|
-
>>> pencolour(240,160,80)
|
|
1528
1785
|
"""
|
|
1529
1786
|
if cmode is None:
|
|
1530
1787
|
return self._colourmode
|
|
@@ -1538,8 +1795,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1538
1795
|
|
|
1539
1796
|
No argument.
|
|
1540
1797
|
|
|
1541
|
-
Example (for a TurtleScreen instance named screen):
|
|
1542
|
-
>>> screen.reset()
|
|
1543
1798
|
"""
|
|
1544
1799
|
for turtle in self._turtles:
|
|
1545
1800
|
turtle._setmode(self._mode)
|
|
@@ -1548,9 +1803,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1548
1803
|
def turtles(self):
|
|
1549
1804
|
"""Return the list of turtles on the screen.
|
|
1550
1805
|
|
|
1551
|
-
Example (for a TurtleScreen instance named screen):
|
|
1552
|
-
>>> screen.turtles()
|
|
1553
|
-
[<turtle.Turtle object at 0x00E11FB0>]
|
|
1554
1806
|
"""
|
|
1555
1807
|
return self._turtles
|
|
1556
1808
|
|
|
@@ -1560,12 +1812,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1560
1812
|
Arguments (if given): a colour string or three numbers
|
|
1561
1813
|
in the range 0..colourmode or a 3-tuple of such numbers.
|
|
1562
1814
|
|
|
1563
|
-
Example (for a TurtleScreen instance named screen):
|
|
1564
|
-
>>> screen.bgcolour("orange")
|
|
1565
|
-
>>> screen.bgcolour()
|
|
1566
|
-
'orange'
|
|
1567
|
-
>>> screen.bgcolour(0.5,0,0.5)
|
|
1568
|
-
>>> screen.bgcolour()
|
|
1569
1815
|
'#800080'
|
|
1570
1816
|
"""
|
|
1571
1817
|
if args:
|
|
@@ -1588,13 +1834,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1588
1834
|
(Can be used to accelerate the drawing of complex graphics.)
|
|
1589
1835
|
Second arguments sets delay value (see RawTurtle.delay())
|
|
1590
1836
|
|
|
1591
|
-
Example (for a TurtleScreen instance named screen):
|
|
1592
|
-
>>> screen.tracer(8, 25)
|
|
1593
|
-
>>> dist = 2
|
|
1594
|
-
>>> for i in range(200):
|
|
1595
|
-
... fd(dist)
|
|
1596
|
-
... rt(90)
|
|
1597
|
-
... dist += 2
|
|
1598
1837
|
"""
|
|
1599
1838
|
if n is None:
|
|
1600
1839
|
return self._tracing
|
|
@@ -1611,10 +1850,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1611
1850
|
Optional argument:
|
|
1612
1851
|
delay -- positive integer
|
|
1613
1852
|
|
|
1614
|
-
Example (for a TurtleScreen instance named screen):
|
|
1615
|
-
>>> screen.delay(15)
|
|
1616
|
-
>>> screen.delay()
|
|
1617
|
-
15
|
|
1618
1853
|
"""
|
|
1619
1854
|
if delay is None:
|
|
1620
1855
|
return self._delayvalue
|
|
@@ -1643,8 +1878,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1643
1878
|
def window_width(self):
|
|
1644
1879
|
""" Return the width of the turtle window.
|
|
1645
1880
|
|
|
1646
|
-
Example (for a TurtleScreen instance named screen):
|
|
1647
|
-
>>> screen.window_width()
|
|
1648
1881
|
640
|
|
1649
1882
|
"""
|
|
1650
1883
|
return self._window_size()[0]
|
|
@@ -1652,8 +1885,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1652
1885
|
def window_height(self):
|
|
1653
1886
|
""" Return the height of the turtle window.
|
|
1654
1887
|
|
|
1655
|
-
Example (for a TurtleScreen instance named screen):
|
|
1656
|
-
>>> screen.window_height()
|
|
1657
1888
|
480
|
|
1658
1889
|
"""
|
|
1659
1890
|
return self._window_size()[1]
|
|
@@ -1663,10 +1894,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1663
1894
|
|
|
1664
1895
|
No argument.
|
|
1665
1896
|
|
|
1666
|
-
Example (for a Screen instance named screen):
|
|
1667
|
-
>>> cv = screen.getcanvas()
|
|
1668
|
-
>>> cv
|
|
1669
|
-
<turtle.ScrolledCanvas instance at 0x010742D8>
|
|
1670
1897
|
"""
|
|
1671
1898
|
return self.cv
|
|
1672
1899
|
|
|
@@ -1675,9 +1902,6 @@ class TurtleScreen(TurtleScreenBase):
|
|
|
1675
1902
|
|
|
1676
1903
|
No argument.
|
|
1677
1904
|
|
|
1678
|
-
Example (for a TurtleScreen instance named screen):
|
|
1679
|
-
>>> screen.getshapes()
|
|
1680
|
-
['arrow', 'blank', 'circle', ... , 'turtle']
|
|
1681
1905
|
"""
|
|
1682
1906
|
return sorted(self._shapes.keys())
|
|
1683
1907
|
|
|
@@ -2104,10 +2328,6 @@ class TNavigator(object):
|
|
|
2104
2328
|
180 - west 180 - south
|
|
2105
2329
|
270 - south 270 - west
|
|
2106
2330
|
|
|
2107
|
-
Example (for a Turtle instance named turtle):
|
|
2108
|
-
>>> turtle.setheading(90)
|
|
2109
|
-
>>> turtle.heading()
|
|
2110
|
-
90
|
|
2111
2331
|
"""
|
|
2112
2332
|
angle = (to_angle - self.heading())*self._angleOrient
|
|
2113
2333
|
full = self._fullcircle
|
|
@@ -2140,9 +2360,7 @@ class TNavigator(object):
|
|
|
2140
2360
|
--or: circle(radius, extent, steps)
|
|
2141
2361
|
--or: circle(radius, steps=6) # 6-sided polygon
|
|
2142
2362
|
|
|
2143
|
-
|
|
2144
|
-
>>> turtle.circle(50)
|
|
2145
|
-
>>> turtle.circle(120, 180) # semicircle
|
|
2363
|
+
|
|
2146
2364
|
"""
|
|
2147
2365
|
if self.undobuffer:
|
|
2148
2366
|
self.undobuffer.push(["seq"])
|
|
@@ -2236,10 +2454,6 @@ class TPen(object):
|
|
|
2236
2454
|
If no argument is given, return current resizemode.
|
|
2237
2455
|
resizemode("user") is called by a call of shapesize with arguments.
|
|
2238
2456
|
|
|
2239
|
-
|
|
2240
|
-
Examples (for a Turtle instance named turtle):
|
|
2241
|
-
>>> turtle.resizemode("noresize")
|
|
2242
|
-
>>> turtle.resizemode()
|
|
2243
2457
|
'noresize'
|
|
2244
2458
|
"""
|
|
2245
2459
|
if rmode is None:
|
|
@@ -2261,10 +2475,6 @@ class TPen(object):
|
|
|
2261
2475
|
the same line thickness. If no argument is given, current pensize
|
|
2262
2476
|
is returned.
|
|
2263
2477
|
|
|
2264
|
-
Example (for a Turtle instance named turtle):
|
|
2265
|
-
>>> turtle.pensize()
|
|
2266
|
-
1
|
|
2267
|
-
>>> turtle.pensize(10) # from here on lines of width 10 are drawn
|
|
2268
2478
|
"""
|
|
2269
2479
|
if width is None:
|
|
2270
2480
|
return self._pensize
|
|
@@ -2278,8 +2488,6 @@ class TPen(object):
|
|
|
2278
2488
|
|
|
2279
2489
|
No argument
|
|
2280
2490
|
|
|
2281
|
-
Example (for a Turtle instance named turtle):
|
|
2282
|
-
>>> turtle.penup()
|
|
2283
2491
|
"""
|
|
2284
2492
|
if not self._drawing:
|
|
2285
2493
|
return
|
|
@@ -2292,8 +2500,6 @@ class TPen(object):
|
|
|
2292
2500
|
|
|
2293
2501
|
No argument.
|
|
2294
2502
|
|
|
2295
|
-
Example (for a Turtle instance named turtle):
|
|
2296
|
-
>>> turtle.pendown()
|
|
2297
2503
|
"""
|
|
2298
2504
|
if self._drawing:
|
|
2299
2505
|
return
|
|
@@ -2304,13 +2510,6 @@ class TPen(object):
|
|
|
2304
2510
|
|
|
2305
2511
|
No argument.
|
|
2306
2512
|
|
|
2307
|
-
Example (for a Turtle instance named turtle):
|
|
2308
|
-
>>> turtle.penup()
|
|
2309
|
-
>>> turtle.isdown()
|
|
2310
|
-
False
|
|
2311
|
-
>>> turtle.pendown()
|
|
2312
|
-
>>> turtle.isdown()
|
|
2313
|
-
True
|
|
2314
2513
|
"""
|
|
2315
2514
|
return self._drawing
|
|
2316
2515
|
|
|
@@ -2338,8 +2537,6 @@ class TPen(object):
|
|
|
2338
2537
|
speed = 0 : *no* animation takes place. forward/back makes turtle jump
|
|
2339
2538
|
and likewise left/right make the turtle turn instantly.
|
|
2340
2539
|
|
|
2341
|
-
Example (for a Turtle instance named turtle):
|
|
2342
|
-
>>> turtle.speed(3)
|
|
2343
2540
|
"""
|
|
2344
2541
|
speeds = {'fastest':0, 'fast':10, 'normal':6, 'slow':3, 'slowest':1 }
|
|
2345
2542
|
if speed is None:
|
|
@@ -2375,14 +2572,6 @@ class TPen(object):
|
|
|
2375
2572
|
is drawn with the newly set colours.
|
|
2376
2573
|
For more info see: pencolour, fillcolour
|
|
2377
2574
|
|
|
2378
|
-
Example (for a Turtle instance named turtle):
|
|
2379
|
-
>>> turtle.colour('red', 'green')
|
|
2380
|
-
>>> turtle.colour()
|
|
2381
|
-
('red', 'green')
|
|
2382
|
-
>>> colourmode(255)
|
|
2383
|
-
>>> colour((40, 80, 120), (160, 200, 240))
|
|
2384
|
-
>>> colour()
|
|
2385
|
-
('#285078', '#a0c8f0')
|
|
2386
2575
|
"""
|
|
2387
2576
|
if args:
|
|
2388
2577
|
l = len(args)
|
|
@@ -2420,12 +2609,6 @@ class TPen(object):
|
|
|
2420
2609
|
If turtleshape is a polygon, the outline of that polygon is drawn
|
|
2421
2610
|
with the newly set pencolour.
|
|
2422
2611
|
|
|
2423
|
-
Example (for a Turtle instance named turtle):
|
|
2424
|
-
>>> turtle.pencolour('brown')
|
|
2425
|
-
>>> tup = (0.2, 0.8, 0.55)
|
|
2426
|
-
>>> turtle.pencolour(tup)
|
|
2427
|
-
>>> turtle.pencolour()
|
|
2428
|
-
'#33cc8c'
|
|
2429
2612
|
"""
|
|
2430
2613
|
if args:
|
|
2431
2614
|
colour = self._colourstr(args)
|
|
@@ -2457,11 +2640,6 @@ class TPen(object):
|
|
|
2457
2640
|
If turtleshape is a polygon, the interior of that polygon is drawn
|
|
2458
2641
|
with the newly set fillcolour.
|
|
2459
2642
|
|
|
2460
|
-
Example (for a Turtle instance named turtle):
|
|
2461
|
-
>>> turtle.fillcolour('violet')
|
|
2462
|
-
>>> col = turtle.pencolour()
|
|
2463
|
-
>>> turtle.fillcolour(col)
|
|
2464
|
-
>>> turtle.fillcolour(0, .5, 0)
|
|
2465
2643
|
"""
|
|
2466
2644
|
if args:
|
|
2467
2645
|
colour = self._colourstr(args)
|
|
@@ -2478,9 +2656,6 @@ class TPen(object):
|
|
|
2478
2656
|
|
|
2479
2657
|
No argument.
|
|
2480
2658
|
|
|
2481
|
-
Example (for a Turtle instance named turtle):
|
|
2482
|
-
>>> turtle.hideturtle()
|
|
2483
|
-
>>> turtle.showturtle()
|
|
2484
2659
|
"""
|
|
2485
2660
|
self.pen(shown=True)
|
|
2486
2661
|
|
|
@@ -2495,8 +2670,6 @@ class TPen(object):
|
|
|
2495
2670
|
middle of a complicated drawing, because hiding
|
|
2496
2671
|
the turtle speeds up the drawing observably.
|
|
2497
2672
|
|
|
2498
|
-
Example (for a Turtle instance named turtle):
|
|
2499
|
-
>>> turtle.hideturtle()
|
|
2500
2673
|
"""
|
|
2501
2674
|
self.pen(shown=False)
|
|
2502
2675
|
|
|
@@ -2537,25 +2710,6 @@ class TPen(object):
|
|
|
2537
2710
|
or more of these attributes can be provided as keyword-arguments.
|
|
2538
2711
|
This can be used to set several pen attributes in one statement.
|
|
2539
2712
|
|
|
2540
|
-
|
|
2541
|
-
Examples (for a Turtle instance named turtle):
|
|
2542
|
-
>>> turtle.pen(fillcolour="black", pencolour="red", pensize=10)
|
|
2543
|
-
>>> turtle.pen()
|
|
2544
|
-
{'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
|
|
2545
|
-
'pencolour': 'red', 'pendown': True, 'fillcolour': 'black',
|
|
2546
|
-
'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
|
|
2547
|
-
>>> penstate=turtle.pen()
|
|
2548
|
-
>>> turtle.colour("yellow","")
|
|
2549
|
-
>>> turtle.penup()
|
|
2550
|
-
>>> turtle.pen()
|
|
2551
|
-
{'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
|
|
2552
|
-
'pencolour': 'yellow', 'pendown': False, 'fillcolour': '',
|
|
2553
|
-
'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
|
|
2554
|
-
>>> p.pen(penstate, fillcolour="green")
|
|
2555
|
-
>>> p.pen()
|
|
2556
|
-
{'pensize': 10, 'shown': True, 'resizemode': 'auto', 'outline': 1,
|
|
2557
|
-
'pencolour': 'red', 'pendown': True, 'fillcolour': 'green',
|
|
2558
|
-
'stretchfactor': (1,1), 'speed': 3, 'shearfactor': 0.0}
|
|
2559
2713
|
"""
|
|
2560
2714
|
_pd = {"shown" : self._shown,
|
|
2561
2715
|
"pendown" : self._drawing,
|
|
@@ -2741,16 +2895,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
2741
2895
|
Delete the turtle's drawings from the screen, re-center the turtle
|
|
2742
2896
|
and set variables to the default values.
|
|
2743
2897
|
|
|
2744
|
-
Example (for a Turtle instance named turtle):
|
|
2745
|
-
>>> turtle.position()
|
|
2746
|
-
(0.00,-22.00)
|
|
2747
|
-
>>> turtle.heading()
|
|
2748
|
-
100.0
|
|
2749
|
-
>>> turtle.reset()
|
|
2750
|
-
>>> turtle.position()
|
|
2751
|
-
(0.00,0.00)
|
|
2752
|
-
>>> turtle.heading()
|
|
2753
|
-
0.0
|
|
2754
2898
|
"""
|
|
2755
2899
|
TNavigator.reset(self)
|
|
2756
2900
|
TPen._reset(self)
|
|
@@ -2769,8 +2913,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
2769
2913
|
by the undo() function.
|
|
2770
2914
|
If size is None, no undobuffer is present.
|
|
2771
2915
|
|
|
2772
|
-
Example (for a Turtle instance named turtle):
|
|
2773
|
-
>>> turtle.setundobuffer(42)
|
|
2774
2916
|
"""
|
|
2775
2917
|
if size is None or size <= 0:
|
|
2776
2918
|
self.undobuffer = None
|
|
@@ -2782,9 +2924,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
2782
2924
|
|
|
2783
2925
|
No argument.
|
|
2784
2926
|
|
|
2785
|
-
Example (for a Turtle instance named turtle):
|
|
2786
|
-
>>> while undobufferentries():
|
|
2787
|
-
... undo()
|
|
2788
2927
|
"""
|
|
2789
2928
|
if self.undobuffer is None:
|
|
2790
2929
|
return 0
|
|
@@ -2813,8 +2952,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
2813
2952
|
State and position of the turtle as well as drawings of other
|
|
2814
2953
|
turtles are not affected.
|
|
2815
2954
|
|
|
2816
|
-
Examples (for a Turtle instance named turtle):
|
|
2817
|
-
>>> turtle.clear()
|
|
2818
2955
|
"""
|
|
2819
2956
|
self._clear()
|
|
2820
2957
|
self._update()
|
|
@@ -2856,13 +2993,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
2856
2993
|
(Can be used to accelerate the drawing of complex graphics.)
|
|
2857
2994
|
Second arguments sets delay value (see RawTurtle.delay())
|
|
2858
2995
|
|
|
2859
|
-
Example (for a Turtle instance named turtle):
|
|
2860
|
-
>>> turtle.tracer(8, 25)
|
|
2861
|
-
>>> dist = 2
|
|
2862
|
-
>>> for i in range(200):
|
|
2863
|
-
... turtle.fd(dist)
|
|
2864
|
-
... turtle.rt(90)
|
|
2865
|
-
... dist += 2
|
|
2866
2996
|
"""
|
|
2867
2997
|
return self.screen.tracer(flag, delay)
|
|
2868
2998
|
|
|
@@ -2940,12 +3070,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
2940
3070
|
'arrow', 'turtle', 'circle', 'square', 'triangle', 'classic'.
|
|
2941
3071
|
To learn about how to deal with shapes see Screen-method register_shape.
|
|
2942
3072
|
|
|
2943
|
-
Example (for a Turtle instance named turtle):
|
|
2944
|
-
>>> turtle.shape()
|
|
2945
|
-
'arrow'
|
|
2946
|
-
>>> turtle.shape("turtle")
|
|
2947
|
-
>>> turtle.shape()
|
|
2948
|
-
'turtle'
|
|
2949
3073
|
"""
|
|
2950
3074
|
if name is None:
|
|
2951
3075
|
return self.turtle.shapeIndex
|
|
@@ -2968,12 +3092,8 @@ class RawTurtle(TPen, TNavigator):
|
|
|
2968
3092
|
stretched according to its stretchfactors:
|
|
2969
3093
|
stretch_wid is stretchfactor perpendicular to orientation
|
|
2970
3094
|
stretch_len is stretchfactor in direction of turtles orientation.
|
|
2971
|
-
outline determines the width of the shapes'
|
|
3095
|
+
outline determines the width of the shapes' outline.
|
|
2972
3096
|
|
|
2973
|
-
Examples (for a Turtle instance named turtle):
|
|
2974
|
-
>>> turtle.resizemode("user")
|
|
2975
|
-
>>> turtle.shapesize(5, 5, 12)
|
|
2976
|
-
>>> turtle.shapesize(outline=8)
|
|
2977
3097
|
"""
|
|
2978
3098
|
if stretch_wid is stretch_len is outline is None:
|
|
2979
3099
|
stretch_wid, stretch_len = self._stretchfactor
|
|
@@ -3002,16 +3122,10 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3002
3122
|
Shear the turtleshape according to the given shearfactor shear,
|
|
3003
3123
|
which is the tangent of the shear angle. DO NOT change the
|
|
3004
3124
|
turtle's heading (direction of movement).
|
|
3005
|
-
If shear is not given: return the current shearfactor, i.
|
|
3125
|
+
If shear is not given: return the current shearfactor, i.e. the
|
|
3006
3126
|
tangent of the shear angle, by which lines parallel to the
|
|
3007
3127
|
heading of the turtle are sheared.
|
|
3008
3128
|
|
|
3009
|
-
Examples (for a Turtle instance named turtle):
|
|
3010
|
-
>>> turtle.shape("circle")
|
|
3011
|
-
>>> turtle.shapesize(5,2)
|
|
3012
|
-
>>> turtle.shearfactor(0.5)
|
|
3013
|
-
>>> turtle.shearfactor()
|
|
3014
|
-
>>> 0.5
|
|
3015
3129
|
"""
|
|
3016
3130
|
if shear is None:
|
|
3017
3131
|
return self._shearfactor
|
|
@@ -3026,16 +3140,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3026
3140
|
regardless of its current tilt-angle. DO NOT change the turtle's
|
|
3027
3141
|
heading (direction of movement).
|
|
3028
3142
|
|
|
3029
|
-
|
|
3030
|
-
Examples (for a Turtle instance named turtle):
|
|
3031
|
-
>>> turtle.shape("circle")
|
|
3032
|
-
>>> turtle.shapesize(5,2)
|
|
3033
|
-
>>> turtle.settiltangle(45)
|
|
3034
|
-
>>> stamp()
|
|
3035
|
-
>>> turtle.fd(50)
|
|
3036
|
-
>>> turtle.settiltangle(-45)
|
|
3037
|
-
>>> stamp()
|
|
3038
|
-
>>> turtle.fd(50)
|
|
3039
3143
|
"""
|
|
3040
3144
|
tilt = -angle * self._degreesPerAU * self._angleOrient
|
|
3041
3145
|
tilt = math.radians(tilt) % math.tau
|
|
@@ -3056,11 +3160,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3056
3160
|
(Incorrectly marked as deprecated since Python 3.1, it is really
|
|
3057
3161
|
settiltangle that is deprecated.)
|
|
3058
3162
|
|
|
3059
|
-
Examples (for a Turtle instance named turtle):
|
|
3060
|
-
>>> turtle.shape("circle")
|
|
3061
|
-
>>> turtle.shapesize(5,2)
|
|
3062
|
-
>>> turtle.tilt(45)
|
|
3063
|
-
>>> turtle.tiltangle()
|
|
3064
3163
|
"""
|
|
3065
3164
|
if angle is None:
|
|
3066
3165
|
tilt = -math.degrees(self._tilt) * self._angleOrient
|
|
@@ -3077,13 +3176,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3077
3176
|
Rotate the turtleshape by angle from its current tilt-angle,
|
|
3078
3177
|
but do NOT change the turtle's heading (direction of movement).
|
|
3079
3178
|
|
|
3080
|
-
Examples (for a Turtle instance named turtle):
|
|
3081
|
-
>>> turtle.shape("circle")
|
|
3082
|
-
>>> turtle.shapesize(5,2)
|
|
3083
|
-
>>> turtle.tilt(30)
|
|
3084
|
-
>>> turtle.fd(50)
|
|
3085
|
-
>>> turtle.tilt(30)
|
|
3086
|
-
>>> turtle.fd(50)
|
|
3087
3179
|
"""
|
|
3088
3180
|
self.settiltangle(angle + self.tiltangle())
|
|
3089
3181
|
|
|
@@ -3100,11 +3192,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3100
3192
|
Modify stretchfactor, shearfactor and tiltangle according to the
|
|
3101
3193
|
given matrix.
|
|
3102
3194
|
|
|
3103
|
-
Examples (for a Turtle instance named turtle):
|
|
3104
|
-
>>> turtle.shape("square")
|
|
3105
|
-
>>> turtle.shapesize(4,2)
|
|
3106
|
-
>>> turtle.shearfactor(-0.5)
|
|
3107
|
-
>>> turtle.shapetransform()
|
|
3108
3195
|
(4.0, -1.0, -0.0, 2.0)
|
|
3109
3196
|
"""
|
|
3110
3197
|
if t11 is t12 is t21 is t22 is None:
|
|
@@ -3143,13 +3230,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3143
3230
|
"""Return the current shape polygon as tuple of coordinate pairs.
|
|
3144
3231
|
|
|
3145
3232
|
No argument.
|
|
3146
|
-
|
|
3147
|
-
Examples (for a Turtle instance named turtle):
|
|
3148
|
-
>>> turtle.shape("square")
|
|
3149
|
-
>>> turtle.shapetransform(4, -1, 0, 2)
|
|
3150
|
-
>>> turtle.get_shapepoly()
|
|
3151
|
-
((50, -20), (30, 20), (-50, 20), (-30, -20))
|
|
3152
|
-
|
|
3153
3233
|
"""
|
|
3154
3234
|
shape = self.screen._shapes[self.turtle.shapeIndex]
|
|
3155
3235
|
if shape._type == "polygon":
|
|
@@ -3218,11 +3298,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3218
3298
|
turtle position. Return a stamp_id for that stamp, which can be
|
|
3219
3299
|
used to delete it by calling clearstamp(stamp_id).
|
|
3220
3300
|
|
|
3221
|
-
Example (for a Turtle instance named turtle):
|
|
3222
|
-
>>> turtle.colour("blue")
|
|
3223
|
-
>>> turtle.stamp()
|
|
3224
|
-
13
|
|
3225
|
-
>>> turtle.fd(50)
|
|
3226
3301
|
"""
|
|
3227
3302
|
screen = self.screen
|
|
3228
3303
|
shape = screen._shapes[self.turtle.shapeIndex]
|
|
@@ -3282,11 +3357,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3282
3357
|
Argument:
|
|
3283
3358
|
stampid - an integer, must be return value of previous stamp() call.
|
|
3284
3359
|
|
|
3285
|
-
Example (for a Turtle instance named turtle):
|
|
3286
|
-
>>> turtle.colour("blue")
|
|
3287
|
-
>>> astamp = turtle.stamp()
|
|
3288
|
-
>>> turtle.fd(50)
|
|
3289
|
-
>>> turtle.clearstamp(astamp)
|
|
3290
3360
|
"""
|
|
3291
3361
|
self._clearstamp(stampid)
|
|
3292
3362
|
self._update()
|
|
@@ -3301,13 +3371,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3301
3371
|
else if n > 0 delete first n stamps
|
|
3302
3372
|
else if n < 0 delete last n stamps.
|
|
3303
3373
|
|
|
3304
|
-
Example (for a Turtle instance named turtle):
|
|
3305
|
-
>>> for i in range(8):
|
|
3306
|
-
... turtle.stamp(); turtle.fd(30)
|
|
3307
|
-
...
|
|
3308
|
-
>>> turtle.clearstamps(2)
|
|
3309
|
-
>>> turtle.clearstamps(-2)
|
|
3310
|
-
>>> turtle.clearstamps()
|
|
3311
3374
|
"""
|
|
3312
3375
|
if n is None:
|
|
3313
3376
|
toDelete = self.stampItems[:]
|
|
@@ -3476,12 +3539,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3476
3539
|
|
|
3477
3540
|
No argument.
|
|
3478
3541
|
|
|
3479
|
-
Example (for a Turtle instance named turtle):
|
|
3480
|
-
>>> turtle.begin_fill()
|
|
3481
|
-
>>> if turtle.filling():
|
|
3482
|
-
... turtle.pensize(5)
|
|
3483
|
-
... else:
|
|
3484
|
-
... turtle.pensize(3)
|
|
3485
3542
|
"""
|
|
3486
3543
|
return isinstance(self._fillpath, list)
|
|
3487
3544
|
|
|
@@ -3490,11 +3547,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3490
3547
|
|
|
3491
3548
|
No argument.
|
|
3492
3549
|
|
|
3493
|
-
Example (for a Turtle instance named turtle):
|
|
3494
|
-
>>> turtle.colour("black", "red")
|
|
3495
|
-
>>> turtle.begin_fill()
|
|
3496
|
-
>>> turtle.circle(60)
|
|
3497
|
-
>>> turtle.end_fill()
|
|
3498
3550
|
"""
|
|
3499
3551
|
if not self.filling():
|
|
3500
3552
|
self._fillitem = self.screen._createpoly()
|
|
@@ -3511,11 +3563,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3511
3563
|
|
|
3512
3564
|
No argument.
|
|
3513
3565
|
|
|
3514
|
-
Example (for a Turtle instance named turtle):
|
|
3515
|
-
>>> turtle.colour("black", "red")
|
|
3516
|
-
>>> turtle.begin_fill()
|
|
3517
|
-
>>> turtle.circle(60)
|
|
3518
|
-
>>> turtle.end_fill()
|
|
3519
3566
|
"""
|
|
3520
3567
|
if self.filling():
|
|
3521
3568
|
if len(self._fillpath) > 2:
|
|
@@ -3536,9 +3583,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3536
3583
|
Draw a circular dot with diameter size, using colour.
|
|
3537
3584
|
If size is not given, the maximum of pensize+4 and 2*pensize is used.
|
|
3538
3585
|
|
|
3539
|
-
Example (for a Turtle instance named turtle):
|
|
3540
|
-
>>> turtle.dot()
|
|
3541
|
-
>>> turtle.fd(50); turtle.dot(20, "blue"); turtle.fd(50)
|
|
3542
3586
|
"""
|
|
3543
3587
|
if not colour:
|
|
3544
3588
|
if isinstance(size, (str, tuple)):
|
|
@@ -3599,9 +3643,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3599
3643
|
If move is True, the pen is moved to the bottom-right corner
|
|
3600
3644
|
of the text. By default, move is False.
|
|
3601
3645
|
|
|
3602
|
-
Example (for a Turtle instance named turtle):
|
|
3603
|
-
>>> turtle.write('Home = ', True, align="center")
|
|
3604
|
-
>>> turtle.write((0,0), True)
|
|
3605
3646
|
"""
|
|
3606
3647
|
if self.undobuffer:
|
|
3607
3648
|
self.undobuffer.push(["seq"])
|
|
@@ -3621,8 +3662,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3621
3662
|
Start recording the vertices of a polygon. Current turtle position
|
|
3622
3663
|
is first point of polygon.
|
|
3623
3664
|
|
|
3624
|
-
Example (for a Turtle instance named turtle):
|
|
3625
|
-
>>> turtle.begin_poly()
|
|
3626
3665
|
"""
|
|
3627
3666
|
self._poly = [self._position]
|
|
3628
3667
|
self._creatingPoly = True
|
|
@@ -3635,8 +3674,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3635
3674
|
Stop recording the vertices of a polygon. Current turtle position is
|
|
3636
3675
|
last point of polygon. This will be connected with the first point.
|
|
3637
3676
|
|
|
3638
|
-
Example (for a Turtle instance named turtle):
|
|
3639
|
-
>>> turtle.end_poly()
|
|
3640
3677
|
"""
|
|
3641
3678
|
self._creatingPoly = False
|
|
3642
3679
|
|
|
@@ -3645,9 +3682,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3645
3682
|
|
|
3646
3683
|
No argument.
|
|
3647
3684
|
|
|
3648
|
-
Example (for a Turtle instance named turtle):
|
|
3649
|
-
>>> p = turtle.get_poly()
|
|
3650
|
-
>>> turtle.register_shape("myFavouriteShape", p)
|
|
3651
3685
|
"""
|
|
3652
3686
|
## check if there is any poly?
|
|
3653
3687
|
if self._poly is not None:
|
|
@@ -3661,11 +3695,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3661
3695
|
Return the TurtleScreen object, the turtle is drawing on.
|
|
3662
3696
|
So TurtleScreen-methods can be called for that object.
|
|
3663
3697
|
|
|
3664
|
-
Example (for a Turtle instance named turtle):
|
|
3665
|
-
>>> ts = turtle.getscreen()
|
|
3666
|
-
>>> ts
|
|
3667
|
-
<turtle.TurtleScreen object at 0x0106B770>
|
|
3668
|
-
>>> ts.bgcolour("pink")
|
|
3669
3698
|
"""
|
|
3670
3699
|
return self.screen
|
|
3671
3700
|
|
|
@@ -3676,13 +3705,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3676
3705
|
|
|
3677
3706
|
Only reasonable use: as a function to return the 'anonymous turtle':
|
|
3678
3707
|
|
|
3679
|
-
Example:
|
|
3680
|
-
>>> pet = getturtle()
|
|
3681
|
-
>>> pet.fd(50)
|
|
3682
|
-
>>> pet
|
|
3683
|
-
<turtle.Turtle object at 0x0187D810>
|
|
3684
|
-
>>> turtles()
|
|
3685
|
-
[<turtle.Turtle object at 0x0187D810>]
|
|
3686
3708
|
"""
|
|
3687
3709
|
return self
|
|
3688
3710
|
|
|
@@ -3708,13 +3730,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3708
3730
|
add -- True or False. If True, new binding will be added, otherwise
|
|
3709
3731
|
it will replace a former binding.
|
|
3710
3732
|
|
|
3711
|
-
Example for the anonymous turtle, i. e. the procedural way:
|
|
3712
|
-
|
|
3713
|
-
>>> def turn(x, y):
|
|
3714
|
-
... left(360)
|
|
3715
|
-
...
|
|
3716
|
-
>>> onclick(turn) # Now clicking into the turtle will turn it.
|
|
3717
|
-
>>> onclick(None) # event-binding will be removed
|
|
3718
3733
|
"""
|
|
3719
3734
|
self.screen._onclick(self.turtle._item, fun, btn, add)
|
|
3720
3735
|
self._update()
|
|
@@ -3727,17 +3742,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3727
3742
|
the coordinates of the clicked point on the canvas.
|
|
3728
3743
|
btn -- number of the mouse-button defaults to 1 (left mouse button).
|
|
3729
3744
|
|
|
3730
|
-
Example (for a MyTurtle instance named joe):
|
|
3731
|
-
>>> class MyTurtle(Turtle):
|
|
3732
|
-
... def glow(self,x,y):
|
|
3733
|
-
... self.fillcolour("red")
|
|
3734
|
-
... def unglow(self,x,y):
|
|
3735
|
-
... self.fillcolour("")
|
|
3736
|
-
...
|
|
3737
|
-
>>> joe = MyTurtle()
|
|
3738
|
-
>>> joe.onclick(joe.glow)
|
|
3739
|
-
>>> joe.onrelease(joe.unglow)
|
|
3740
|
-
|
|
3741
3745
|
Clicking on joe turns fillcolour red, unclicking turns it to
|
|
3742
3746
|
transparent.
|
|
3743
3747
|
"""
|
|
@@ -3755,9 +3759,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3755
3759
|
Every sequence of mouse-move-events on a turtle is preceded by a
|
|
3756
3760
|
mouse-click event on that turtle.
|
|
3757
3761
|
|
|
3758
|
-
Example (for a Turtle instance named turtle):
|
|
3759
|
-
>>> turtle.ondrag(turtle.goto)
|
|
3760
|
-
|
|
3761
3762
|
Subsequently clicking and dragging a Turtle will move it
|
|
3762
3763
|
across the screen thereby producing handdrawings (if pen is
|
|
3763
3764
|
down).
|
|
@@ -3806,13 +3807,6 @@ class RawTurtle(TPen, TNavigator):
|
|
|
3806
3807
|
Number of available undo actions is determined by the size of
|
|
3807
3808
|
the undobuffer.
|
|
3808
3809
|
|
|
3809
|
-
Example (for a Turtle instance named turtle):
|
|
3810
|
-
>>> for i in range(4):
|
|
3811
|
-
... turtle.fd(50); turtle.lt(80)
|
|
3812
|
-
...
|
|
3813
|
-
>>> for i in range(8):
|
|
3814
|
-
... turtle.undo()
|
|
3815
|
-
...
|
|
3816
3810
|
"""
|
|
3817
3811
|
if self.undobuffer is None:
|
|
3818
3812
|
return
|
|
@@ -3884,14 +3878,6 @@ class _Screen(TurtleScreen):
|
|
|
3884
3878
|
edge of the screen, if negative from the bottom edge
|
|
3885
3879
|
Default, starty=None is to center window vertically.
|
|
3886
3880
|
|
|
3887
|
-
Examples (for a Screen instance named screen):
|
|
3888
|
-
>>> screen.setup (width=200, height=200, startx=0, starty=0)
|
|
3889
|
-
|
|
3890
|
-
sets window to 200x200 pixels, in upper left of screen
|
|
3891
|
-
|
|
3892
|
-
>>> screen.setup(width=.75, height=0.5, startx=None, starty=None)
|
|
3893
|
-
|
|
3894
|
-
sets window to 75% of screen by 50% of screen and centers
|
|
3895
3881
|
"""
|
|
3896
3882
|
if not hasattr(self._root, "set_geometry"):
|
|
3897
3883
|
return
|
|
@@ -3918,8 +3904,6 @@ class _Screen(TurtleScreen):
|
|
|
3918
3904
|
This is a method of Screen-class. Not available for TurtleScreen-
|
|
3919
3905
|
objects.
|
|
3920
3906
|
|
|
3921
|
-
Example (for a Screen instance named screen):
|
|
3922
|
-
>>> screen.title("Welcome to the turtle-zoo!")
|
|
3923
3907
|
"""
|
|
3924
3908
|
if _Screen._root is not None:
|
|
3925
3909
|
_Screen._root.title(titlestring)
|
|
@@ -3936,11 +3920,7 @@ class _Screen(TurtleScreen):
|
|
|
3936
3920
|
root.destroy()
|
|
3937
3921
|
|
|
3938
3922
|
def bye(self):
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
Example (for a TurtleScreen instance named screen):
|
|
3942
|
-
>>> screen.bye()
|
|
3943
|
-
"""
|
|
3923
|
+
#Shut the turtlegraphics window.
|
|
3944
3924
|
self._destroy()
|
|
3945
3925
|
|
|
3946
3926
|
def exitonclick(self):
|
|
@@ -3957,10 +3937,6 @@ class _Screen(TurtleScreen):
|
|
|
3957
3937
|
|
|
3958
3938
|
This is a method of the Screen-class and not available for
|
|
3959
3939
|
TurtleScreen instances.
|
|
3960
|
-
|
|
3961
|
-
Example (for a Screen instance named screen):
|
|
3962
|
-
>>> screen.exitonclick()
|
|
3963
|
-
|
|
3964
3940
|
"""
|
|
3965
3941
|
def exitGracefully(x, y):
|
|
3966
3942
|
"""Screen.bye() with two dummy-parameters"""
|
{ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/src/ducky_python_module.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ducky-python-module
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Ducky Python module
|
|
5
5
|
Author: Tom
|
|
6
6
|
License: Creative Commons Attribution-NonCommercial 4.0 International Public
|
|
@@ -346,8 +346,15 @@ Dynamic: license-file
|
|
|
346
346
|
|
|
347
347
|
# Ducky-Python-Module
|
|
348
348
|
A collection of tools for python
|
|
349
|
-
Still in progress
|
|
349
|
+
Still in progress and will be releasing fully soon
|
|
350
350
|
Credit:
|
|
351
351
|
Turtle library has been used and modified. I did not make it and I did include the text from the original library explaining rights to the Turtle program which I am not allowed to remove.
|
|
352
352
|
Nltk has been imported but not modified.
|
|
353
|
-
|
|
353
|
+
Full import list:
|
|
354
|
+
import random, time, os, tkinter as TK, types, math, inspect, sys, requests, json, numpy, ast, logging
|
|
355
|
+
from os.path import isfile, split, join
|
|
356
|
+
from copy import deepcopy
|
|
357
|
+
from tkinter import simpledialog
|
|
358
|
+
from turtle import Turtle
|
|
359
|
+
from nltk.tokenize import word_tokenize
|
|
360
|
+
from nltk.stem import LancasterStemmer
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# Ducky-Python-Module
|
|
2
|
-
A collection of tools for python
|
|
3
|
-
Still in progress but it will be releasing fully soon
|
|
4
|
-
Credit:
|
|
5
|
-
Turtle library has been used and modified. I did not make it and I did include the text from the original library explaining rights to the Turtle program which I am not allowed to remove.
|
|
6
|
-
Nltk has been imported but not modified.
|
|
7
|
-
And a few other libraries which I'll mention when this is complete
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ducky_python_module-0.1.4 → ducky_python_module-1.0.0}/src/ducky_python_module.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|