This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division # for running in 2.7+ python | |
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path | |
import turtle | |
""" demo of using a great python module svg.path by Lennart Regebro see site: https://pypi.org/project/svg.path/ | |
to draw svg in Tkinter | |
""" | |
svgpath = """m 76,232.24998 c 81.57846,-49.53502 158.19366,-20.30271 216,27 61.26714,59.36905 79.86223,123.38417 9,156 | |
-80.84947,31.72743 -125.19991,-53.11474 -118,-91 v 0 """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This examples runs only in python 3.+ versions since Tkinter was changed | |
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path | |
from tkinter import Tk, Canvas, Frame, BOTH | |
""" demo of using a great python module svg.path by | |
Lennart Regebro see site: https://pypi.org/project/svg.path/ | |
to draw svg in Tkinter | |
""" | |
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division # we need floating division | |
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path | |
import pygame | |
""" demo of using a great python module svg.path by Lennart Regebro | |
see site: https://pypi.org/project/svg.path/ | |
to draw svg in pygame | |
""" | |
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Lessons in dynamic attributes for a class using self.__dict__ | |
From python.org documents: | |
object.__dict__ : | |
A dictionary or other mapping object | |
used to store an object’s (writable) attributes. | |
Learn to object.__dict__ for: | |
1. Setting defaults for the classes/object attributes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame as pg | |
import math | |
from pygame.locals import * | |
""" | |
thick_aaline(surface, color, point0, point1, width) | |
draw a anti-aliased line from point1 to point2 with given width | |
The algorithms computes the corners (a, b, c, and d) | |
that form the borders of the thick line and then draws a filled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
""" Create random events where event probabilities are | |
set by a frequency list | |
This shows two functional approaches, the second being more terse | |
and then a object oriented approach""" | |
# functional approach using a closure | |
# setup: x = event_gen(freq_table) | |
# get sample: x() -> sample index | |
def event_gen(freq_table): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import re | |
import requests | |
import csv | |
import time | |
import json | |
# version 1.1 added handling of youtube.com/channel/ | |
# to already handling of youtube.com/user based channels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Undirected Graph ADT with edge data stored as adj_vertices dict for each Vertex | |
# The key to each edge is a nomalized tuple of the vertex ids ordered from low to high | |
# edge id (eid) for v1, v2 is (v1,v2) or (v2,v1) such that the first tuple item is less than second | |
def edge_id(v1,v2): # normalize key v1,v2 to tuple (v_low,v_hi) | |
return (v1, v2) if v1 <= v2 else (v2, v1) | |
class Vertex(object): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Graph Data Structure: Adjacency List implementation | |
that matches the Abstract Data Type as defined in the eBook | |
https://runestone.academy/runestone/static/pythonds/index.html | |
and goes with the video course at http://youtube.com/gjenkinslbcc channel | |
This code is attributed to the book | |
"Problem Solving with Algorithms and Data Structures using Python" | |
by the Authors Bradley N. Miller and David Ranum | |
under the Creative Commons | |
Attribution-NonCommercial-ShareAlike 4.0 International License (CC-BY-NC-SA) | |
License link: https://goo.gl/m2m1ww |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" One Example of how to implement a Adjacency Matrix implementation of a Graph Data Structure | |
that matches the Abstract Data Type as defined in the eBook | |
https://runestone.academy/runestone/static/pythonds/index.html | |
and goes with the video course at http://youtube.com/gjenkinslbcc channel | |
""" | |
class Vertex(object): | |
"""vertex with key and optional data payload""" |