Skip to content

Instantly share code, notes, and snippets.

View gerryjenkinslb's full-sized avatar

Gerry Jenkins gerryjenkinslb

  • Retired
  • Long Beach, CA
View GitHub Profile
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 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
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
@gerryjenkinslb
gerryjenkinslb / PointV.txt
Last active July 27, 2018 22:15
Showing dynamic Class/Object possibilites using object.__dict__ in Python 3.6+
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
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
@gerryjenkinslb
gerryjenkinslb / event_gen.py
Last active June 27, 2018 22:53
Python code to create random events where the events have different probabilites specified by a frequence table.
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):
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
@gerryjenkinslb
gerryjenkinslb / graph.py
Created May 15, 2018 19:41
Undirected Graph with edge data (python)
# 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):
@gerryjenkinslb
gerryjenkinslb / graph_adj_list.py
Last active April 6, 2018 22:37
Python Graph implented by Adjacency List
""" 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
@gerryjenkinslb
gerryjenkinslb / graph_adj_matrix.py
Last active July 30, 2021 18:49
Python Graph implented by Adjacency Matrix
""" 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"""