Added SPDX to 30 more files - spdx-49
This commit is contained in:
parent
bfe5427a4a
commit
39e532211a
30 changed files with 429 additions and 307 deletions
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
### Adafruit logo
|
||||
|
||||
"""Adafruit logo created from bitmap,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2019 Kevin J. Walters for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
### scope-xy-adafruitlogo v1.0
|
||||
|
||||
"""Output a logo to an oscilloscope in X-Y mode on an Adafruit M4
|
||||
|
|
|
|||
|
|
@ -1,173 +1,177 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
### pngtowav v1.0
|
||||
"""Convert a list of png images to pseudo composite video in wav file form.
|
||||
|
||||
This is Python code not intended for running on a microcontroller board.
|
||||
"""
|
||||
|
||||
### MIT License
|
||||
|
||||
### Copyright (c) 2019 Kevin J. Walters
|
||||
|
||||
### 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 FROM,
|
||||
### OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
### SOFTWARE.
|
||||
|
||||
import getopt
|
||||
import sys
|
||||
import array
|
||||
import wave
|
||||
|
||||
import imageio
|
||||
|
||||
|
||||
### globals
|
||||
### pylint: disable=invalid-name
|
||||
### start_offset of 1 can help if triggering on oscilloscope
|
||||
### is missing alternate lines
|
||||
debug = 0
|
||||
verbose = False
|
||||
movie_file = False
|
||||
output_filename = "dacanim.wav"
|
||||
fps = 50
|
||||
threshold = 128 ### pixel level
|
||||
replaceforsync = False
|
||||
start_offset = 1
|
||||
|
||||
max_dac_v = 3.3
|
||||
### 16 bit wav files always use signed representation for data
|
||||
dac_offtop = 2**15-1 ### 3.30V
|
||||
dac_sync = -2**15 ### 0.00V
|
||||
### image from 3.00V to 0.30V
|
||||
dac_top = round(3.00 / max_dac_v * (2**16-1)) - 2**15
|
||||
dac_bottom = round(0.30 / max_dac_v * (2**16-1)) - 2**15
|
||||
|
||||
|
||||
def usage(exit_code): ### pylint: disable=missing-docstring
|
||||
print("pngtowav: "
|
||||
+ "[-d] [-f fps] [-h] [-m] [-o outputfilename] [-r] [-s lineoffset] [-t threshold] [-v]",
|
||||
file=sys.stderr)
|
||||
if exit_code is not None:
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
def image_to_dac(img, row_offset, first_pix, dac_y_range):
|
||||
"""Convert a single image to DAC output."""
|
||||
dac_out = array.array("h", [])
|
||||
|
||||
img_height, img_width = img.shape
|
||||
if verbose:
|
||||
print("W,H", img_width, img_height)
|
||||
|
||||
for row_o in range(img_height):
|
||||
row = (row_o + row_offset) % img_height
|
||||
### Currently using 0 to (n-1)/n range
|
||||
y_pos = round(dac_top - row / (img_height - 1) * dac_y_range)
|
||||
if verbose:
|
||||
print("Adding row", row, "at y_pos", y_pos)
|
||||
dac_out.extend(array.array("h",
|
||||
[dac_sync]
|
||||
+ [y_pos if x >= threshold else dac_offtop
|
||||
for x in img[row, first_pix:]]))
|
||||
return dac_out, img_width, img_height
|
||||
|
||||
|
||||
def write_wav(filename, data, framerate):
|
||||
"""Create one channel 16bit wav file."""
|
||||
wav_file = wave.open(filename, "w")
|
||||
nchannels = 1
|
||||
sampwidth = 2
|
||||
nframes = len(data)
|
||||
comptype = "NONE"
|
||||
compname = "not compressed"
|
||||
if verbose:
|
||||
print("Writing wav file", filename, "at rate", framerate,
|
||||
"with", nframes, "samples")
|
||||
wav_file.setparams((nchannels, sampwidth, framerate, nframes,
|
||||
comptype, compname))
|
||||
wav_file.writeframes(data)
|
||||
wav_file.close()
|
||||
|
||||
|
||||
def main(cmdlineargs): ### pylint: disable=too-many-branches
|
||||
"""main(args)"""
|
||||
global debug, fps, movie_file, output_filename, replaceforsync ### pylint: disable=global-statement
|
||||
global threshold, start_offset, verbose ### pylint: disable=global-statement
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt(cmdlineargs,
|
||||
"f:hmo:rs:t:v", ["help", "output="])
|
||||
except getopt.GetoptError as err:
|
||||
print(err,
|
||||
file=sys.stderr)
|
||||
usage(2)
|
||||
for opt, arg in opts:
|
||||
if opt == "-d": ### pylint counts these towards too-many-branches :(
|
||||
debug = 1
|
||||
elif opt == "-f":
|
||||
fps = int(arg)
|
||||
elif opt in ("-h", "--help"):
|
||||
usage(0)
|
||||
elif opt == "-m":
|
||||
movie_file = True
|
||||
elif opt in ("-o", "--output"):
|
||||
output_filename = arg
|
||||
elif opt == "-r":
|
||||
replaceforsync = True
|
||||
elif opt == "-s":
|
||||
start_offset = int(arg)
|
||||
elif opt == "-t":
|
||||
threshold = int(arg)
|
||||
elif opt == "-v":
|
||||
verbose = True
|
||||
else:
|
||||
print("Internal error: unhandled option",
|
||||
file=sys.stderr)
|
||||
sys.exit(3)
|
||||
|
||||
dac_samples = array.array("h", [])
|
||||
|
||||
### Decide whether to replace first column with sync pulse
|
||||
### or add it as an additional column
|
||||
first_pix = 1 if replaceforsync else 0
|
||||
|
||||
### Read each frame, either
|
||||
### many single image filenames in args or
|
||||
### one or more video (animated gifs) (needs -m on command line)
|
||||
dac_y_range = dac_top - dac_bottom
|
||||
row_offset = 0
|
||||
for arg in args:
|
||||
if verbose:
|
||||
print("PROCESSING", arg)
|
||||
if movie_file:
|
||||
images = imageio.mimread(arg)
|
||||
else:
|
||||
images = [imageio.imread(arg)]
|
||||
|
||||
for img in images:
|
||||
img_output, width, height = image_to_dac(img, row_offset,
|
||||
first_pix, dac_y_range)
|
||||
dac_samples.extend(img_output)
|
||||
row_offset += start_offset
|
||||
|
||||
write_wav(output_filename, dac_samples,
|
||||
(width + (1 - first_pix)) * height * fps)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
# SPDX-FileCopyrightText: 2019 Kevin J. Walters for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
#!/usr/bin/python3
|
||||
|
||||
### pngtowav v1.0
|
||||
"""Convert a list of png images to pseudo composite video in wav file form.
|
||||
|
||||
This is Python code not intended for running on a microcontroller board.
|
||||
"""
|
||||
|
||||
### MIT License
|
||||
|
||||
### Copyright (c) 2019 Kevin J. Walters
|
||||
|
||||
### 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 FROM,
|
||||
### OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
### SOFTWARE.
|
||||
|
||||
import getopt
|
||||
import sys
|
||||
import array
|
||||
import wave
|
||||
|
||||
import imageio
|
||||
|
||||
|
||||
### globals
|
||||
### pylint: disable=invalid-name
|
||||
### start_offset of 1 can help if triggering on oscilloscope
|
||||
### is missing alternate lines
|
||||
debug = 0
|
||||
verbose = False
|
||||
movie_file = False
|
||||
output_filename = "dacanim.wav"
|
||||
fps = 50
|
||||
threshold = 128 ### pixel level
|
||||
replaceforsync = False
|
||||
start_offset = 1
|
||||
|
||||
max_dac_v = 3.3
|
||||
### 16 bit wav files always use signed representation for data
|
||||
dac_offtop = 2**15-1 ### 3.30V
|
||||
dac_sync = -2**15 ### 0.00V
|
||||
### image from 3.00V to 0.30V
|
||||
dac_top = round(3.00 / max_dac_v * (2**16-1)) - 2**15
|
||||
dac_bottom = round(0.30 / max_dac_v * (2**16-1)) - 2**15
|
||||
|
||||
|
||||
def usage(exit_code): ### pylint: disable=missing-docstring
|
||||
print("pngtowav: "
|
||||
+ "[-d] [-f fps] [-h] [-m] [-o outputfilename] [-r] [-s lineoffset] [-t threshold] [-v]",
|
||||
file=sys.stderr)
|
||||
if exit_code is not None:
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
def image_to_dac(img, row_offset, first_pix, dac_y_range):
|
||||
"""Convert a single image to DAC output."""
|
||||
dac_out = array.array("h", [])
|
||||
|
||||
img_height, img_width = img.shape
|
||||
if verbose:
|
||||
print("W,H", img_width, img_height)
|
||||
|
||||
for row_o in range(img_height):
|
||||
row = (row_o + row_offset) % img_height
|
||||
### Currently using 0 to (n-1)/n range
|
||||
y_pos = round(dac_top - row / (img_height - 1) * dac_y_range)
|
||||
if verbose:
|
||||
print("Adding row", row, "at y_pos", y_pos)
|
||||
dac_out.extend(array.array("h",
|
||||
[dac_sync]
|
||||
+ [y_pos if x >= threshold else dac_offtop
|
||||
for x in img[row, first_pix:]]))
|
||||
return dac_out, img_width, img_height
|
||||
|
||||
|
||||
def write_wav(filename, data, framerate):
|
||||
"""Create one channel 16bit wav file."""
|
||||
wav_file = wave.open(filename, "w")
|
||||
nchannels = 1
|
||||
sampwidth = 2
|
||||
nframes = len(data)
|
||||
comptype = "NONE"
|
||||
compname = "not compressed"
|
||||
if verbose:
|
||||
print("Writing wav file", filename, "at rate", framerate,
|
||||
"with", nframes, "samples")
|
||||
wav_file.setparams((nchannels, sampwidth, framerate, nframes,
|
||||
comptype, compname))
|
||||
wav_file.writeframes(data)
|
||||
wav_file.close()
|
||||
|
||||
|
||||
def main(cmdlineargs): ### pylint: disable=too-many-branches
|
||||
"""main(args)"""
|
||||
global debug, fps, movie_file, output_filename, replaceforsync ### pylint: disable=global-statement
|
||||
global threshold, start_offset, verbose ### pylint: disable=global-statement
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt(cmdlineargs,
|
||||
"f:hmo:rs:t:v", ["help", "output="])
|
||||
except getopt.GetoptError as err:
|
||||
print(err,
|
||||
file=sys.stderr)
|
||||
usage(2)
|
||||
for opt, arg in opts:
|
||||
if opt == "-d": ### pylint counts these towards too-many-branches :(
|
||||
debug = 1
|
||||
elif opt == "-f":
|
||||
fps = int(arg)
|
||||
elif opt in ("-h", "--help"):
|
||||
usage(0)
|
||||
elif opt == "-m":
|
||||
movie_file = True
|
||||
elif opt in ("-o", "--output"):
|
||||
output_filename = arg
|
||||
elif opt == "-r":
|
||||
replaceforsync = True
|
||||
elif opt == "-s":
|
||||
start_offset = int(arg)
|
||||
elif opt == "-t":
|
||||
threshold = int(arg)
|
||||
elif opt == "-v":
|
||||
verbose = True
|
||||
else:
|
||||
print("Internal error: unhandled option",
|
||||
file=sys.stderr)
|
||||
sys.exit(3)
|
||||
|
||||
dac_samples = array.array("h", [])
|
||||
|
||||
### Decide whether to replace first column with sync pulse
|
||||
### or add it as an additional column
|
||||
first_pix = 1 if replaceforsync else 0
|
||||
|
||||
### Read each frame, either
|
||||
### many single image filenames in args or
|
||||
### one or more video (animated gifs) (needs -m on command line)
|
||||
dac_y_range = dac_top - dac_bottom
|
||||
row_offset = 0
|
||||
for arg in args:
|
||||
if verbose:
|
||||
print("PROCESSING", arg)
|
||||
if movie_file:
|
||||
images = imageio.mimread(arg)
|
||||
else:
|
||||
images = [imageio.imread(arg)]
|
||||
|
||||
for img in images:
|
||||
img_output, width, height = image_to_dac(img, row_offset,
|
||||
first_pix, dac_y_range)
|
||||
dac_samples.extend(img_output)
|
||||
row_offset += start_offset
|
||||
|
||||
write_wav(output_filename, dac_samples,
|
||||
(width + (1 - first_pix)) * height * fps)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
|
|
|
|||
|
|
@ -1,134 +1,138 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
### svgtopy v1.0
|
||||
"""Print vectors from an SVG input file in python list format
|
||||
for easy pasting into a program.
|
||||
|
||||
This is Python code not intended for running on a microcontroller board.
|
||||
"""
|
||||
|
||||
### MIT License
|
||||
|
||||
### Copyright (c) 2019 Kevin J. Walters
|
||||
|
||||
### 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 FROM,
|
||||
### OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
### SOFTWARE.
|
||||
|
||||
|
||||
### it only understands M and L in SVG
|
||||
|
||||
### Worth looking at SVG libraries to see if they
|
||||
### can parse/transform SVG data
|
||||
|
||||
import getopt
|
||||
import sys
|
||||
import re
|
||||
##import fileinput
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
### globals
|
||||
### pylint: disable=invalid-name
|
||||
debug = 0
|
||||
verbose = False
|
||||
|
||||
|
||||
def usage(exit_code): ### pylint: disable=missing-docstring
|
||||
print("""Usage: svgtopy [-d] [-h] [-v] [--help]
|
||||
Convert an svg file from from standard input to comma-separated tuples
|
||||
on standard output for inclusion as a list in a python program.""",
|
||||
file=sys.stderr)
|
||||
if exit_code is not None:
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
def search_path_d(svgdata, point_groups):
|
||||
"""Look for M and L in the SVG d attribute of a path node"""
|
||||
|
||||
points = []
|
||||
for match in re.finditer(r"([A-Za-z])([\d\.]+)\s+([\d\.]+)\s*", svgdata):
|
||||
if match:
|
||||
cmd = match.group(1)
|
||||
if cmd == "M": ### Start of a new part
|
||||
mx, my = match.group(2, 3)
|
||||
if points:
|
||||
point_groups.append(points)
|
||||
points = []
|
||||
points.append((float(mx), float(my)))
|
||||
if debug:
|
||||
print("M pos", mx, my)
|
||||
|
||||
elif cmd == "L": ### Continuation of current part
|
||||
lx, ly = match.group(2, 3)
|
||||
points.append((float(lx), float(ly)))
|
||||
if debug:
|
||||
print("L pos", lx, ly)
|
||||
|
||||
else:
|
||||
print("SVG cmd not implemented:", cmd,
|
||||
file=sys.stderr)
|
||||
else:
|
||||
print("some parsing issue",
|
||||
file=sys.stderr)
|
||||
|
||||
# Add the last part to point_groups
|
||||
if points:
|
||||
point_groups.append(points)
|
||||
points = []
|
||||
|
||||
|
||||
def main(cmdlineargs):
|
||||
"""main(args)"""
|
||||
global debug, verbose ### pylint: disable=global-statement
|
||||
|
||||
try:
|
||||
opts, _ = getopt.getopt(cmdlineargs,
|
||||
"dhv", ["help"])
|
||||
except getopt.GetoptError as err:
|
||||
print(err,
|
||||
file=sys.stderr)
|
||||
usage(2)
|
||||
for opt, _ in opts:
|
||||
if opt == "-d":
|
||||
debug = True
|
||||
elif opt == "-v":
|
||||
verbose = True
|
||||
elif opt in ("-h", "--help"):
|
||||
usage(0)
|
||||
else:
|
||||
print("Internal error: unhandled option",
|
||||
file=sys.stderr)
|
||||
sys.exit(3)
|
||||
|
||||
xml_ns = {"svg": "http://www.w3.org/2000/svg"}
|
||||
tree = ET.parse(sys.stdin)
|
||||
point_groups = []
|
||||
for path in tree.findall("svg:path", xml_ns):
|
||||
svgdata = path.attrib["d"]
|
||||
if verbose:
|
||||
print("Processing path with {0:d} length".format(len(svgdata)))
|
||||
search_path_d(svgdata, point_groups)
|
||||
|
||||
|
||||
|
||||
for idx, points in enumerate(point_groups):
|
||||
print("# Group", idx + 1)
|
||||
for point in points:
|
||||
print(" ", point, ",", sep="")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
# SPDX-FileCopyrightText: 2019 Kevin J. Walters for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
#!/usr/bin/python3
|
||||
|
||||
### svgtopy v1.0
|
||||
"""Print vectors from an SVG input file in python list format
|
||||
for easy pasting into a program.
|
||||
|
||||
This is Python code not intended for running on a microcontroller board.
|
||||
"""
|
||||
|
||||
### MIT License
|
||||
|
||||
### Copyright (c) 2019 Kevin J. Walters
|
||||
|
||||
### 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 FROM,
|
||||
### OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
### SOFTWARE.
|
||||
|
||||
|
||||
### it only understands M and L in SVG
|
||||
|
||||
### Worth looking at SVG libraries to see if they
|
||||
### can parse/transform SVG data
|
||||
|
||||
import getopt
|
||||
import sys
|
||||
import re
|
||||
##import fileinput
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
### globals
|
||||
### pylint: disable=invalid-name
|
||||
debug = 0
|
||||
verbose = False
|
||||
|
||||
|
||||
def usage(exit_code): ### pylint: disable=missing-docstring
|
||||
print("""Usage: svgtopy [-d] [-h] [-v] [--help]
|
||||
Convert an svg file from from standard input to comma-separated tuples
|
||||
on standard output for inclusion as a list in a python program.""",
|
||||
file=sys.stderr)
|
||||
if exit_code is not None:
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
def search_path_d(svgdata, point_groups):
|
||||
"""Look for M and L in the SVG d attribute of a path node"""
|
||||
|
||||
points = []
|
||||
for match in re.finditer(r"([A-Za-z])([\d\.]+)\s+([\d\.]+)\s*", svgdata):
|
||||
if match:
|
||||
cmd = match.group(1)
|
||||
if cmd == "M": ### Start of a new part
|
||||
mx, my = match.group(2, 3)
|
||||
if points:
|
||||
point_groups.append(points)
|
||||
points = []
|
||||
points.append((float(mx), float(my)))
|
||||
if debug:
|
||||
print("M pos", mx, my)
|
||||
|
||||
elif cmd == "L": ### Continuation of current part
|
||||
lx, ly = match.group(2, 3)
|
||||
points.append((float(lx), float(ly)))
|
||||
if debug:
|
||||
print("L pos", lx, ly)
|
||||
|
||||
else:
|
||||
print("SVG cmd not implemented:", cmd,
|
||||
file=sys.stderr)
|
||||
else:
|
||||
print("some parsing issue",
|
||||
file=sys.stderr)
|
||||
|
||||
# Add the last part to point_groups
|
||||
if points:
|
||||
point_groups.append(points)
|
||||
points = []
|
||||
|
||||
|
||||
def main(cmdlineargs):
|
||||
"""main(args)"""
|
||||
global debug, verbose ### pylint: disable=global-statement
|
||||
|
||||
try:
|
||||
opts, _ = getopt.getopt(cmdlineargs,
|
||||
"dhv", ["help"])
|
||||
except getopt.GetoptError as err:
|
||||
print(err,
|
||||
file=sys.stderr)
|
||||
usage(2)
|
||||
for opt, _ in opts:
|
||||
if opt == "-d":
|
||||
debug = True
|
||||
elif opt == "-v":
|
||||
verbose = True
|
||||
elif opt in ("-h", "--help"):
|
||||
usage(0)
|
||||
else:
|
||||
print("Internal error: unhandled option",
|
||||
file=sys.stderr)
|
||||
sys.exit(3)
|
||||
|
||||
xml_ns = {"svg": "http://www.w3.org/2000/svg"}
|
||||
tree = ET.parse(sys.stdin)
|
||||
point_groups = []
|
||||
for path in tree.findall("svg:path", xml_ns):
|
||||
svgdata = path.attrib["d"]
|
||||
if verbose:
|
||||
print("Processing path with {0:d} length".format(len(svgdata)))
|
||||
search_path_d(svgdata, point_groups)
|
||||
|
||||
|
||||
|
||||
for idx, points in enumerate(point_groups):
|
||||
print("# Group", idx + 1)
|
||||
for point in points:
|
||||
print(" ", point, ",", sep="")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2021 Jeff Epler for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import board
|
||||
import displayio
|
||||
import keypad
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# Gemma IO demo - analog inputs
|
||||
|
||||
import time
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# CircuitPython IO demo - analog output
|
||||
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# Gemma IO demo - captouch
|
||||
|
||||
import time
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# CircuitPython IO demo #1 - General Purpose I/O
|
||||
|
||||
import time
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# CircuitPython demo - Dotstar
|
||||
|
||||
import time
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# CircuitPlayground demo - Keyboard emu
|
||||
|
||||
import time
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# Gemma/Trinket IO demo - I2C scan
|
||||
|
||||
import time
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# I2C sensor demo
|
||||
|
||||
import time
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import time
|
||||
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import board
|
||||
import digitalio
|
||||
import storage
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# CircuitPython demo - NeoPixel
|
||||
|
||||
import time
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# Gemma IO demo - captouch to dotstar
|
||||
|
||||
import time
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# Gemma IO demo - USB/Serial echo
|
||||
|
||||
import busio
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import time
|
||||
|
||||
import adafruit_dht
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import time
|
||||
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import time
|
||||
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import time
|
||||
|
||||
import board
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2020 Noe Ruiz for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import ssl
|
||||
import board
|
||||
import neopixel
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import random
|
||||
import time
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2018 Anne Barela for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import time
|
||||
import board
|
||||
from analogio import AnalogIn
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
// SPDX-FileCopyrightText: 2018 Anne Barela for Adafruit Industries
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Read analog potentiometer on Circuit Playground Express or other board with changes
|
||||
// Anne Barela for Adafruit Industries 9/2018 based on
|
||||
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2018 Anne Barela for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import time
|
||||
import board
|
||||
from analogio import AnalogIn
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
// SPDX-FileCopyrightText: 2017 Dano Wall for Adafruit Industries
|
||||
// SPDX-FileCopyrightText: 2017 Becky Stern for Adafruit Industries
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//Random Flash animation for Neopixel circuits
|
||||
//by Dano Wall and Becky Stern for Adafruit Industries
|
||||
//based on the Sparkle Skirt, minus the accelerometer
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2020 Liz Clark for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import time
|
||||
from random import randint
|
||||
from micropython import const
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
# SPDX-FileCopyrightText: 2021 Erin St Blaine for Adafruit Industries
|
||||
# SPDX-FileCopyrightText: 2021 Dan Halbert for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
"""
|
||||
LED Sunflower Mobile with Circuit Playground Bluefruit
|
||||
Full tutorial:
|
||||
|
|
|
|||
Loading…
Reference in a new issue