-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpointer1.py
More file actions
61 lines (48 loc) · 2.08 KB
/
pointer1.py
File metadata and controls
61 lines (48 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# pointer1.py -- Gauge pointer generator,
# outputs "pointer-red-basic.bmp" file for use with CircuitPython
#
# Translated directly from bikerglen's "gauge-generator":
# https://github.com/bikerglen/round-lcd-gauges/tree/main/gauge-generator
#
# To use, install ImageMagic drawing API:
# brew install imagemagick
# pip3 install Wand
# python3 gauage1.py
#
import math
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
def draw_pointer_knub(draw, color, center_x, center_y, radius, opacity):
draw.fill_color = color
draw.stroke_color = Color('#333333')
draw.stroke_opacity = 0.5
draw.stroke_width = 2
draw.fill_opacity = opacity
draw.circle( (center_x, center_y), (center_x - radius, center_y))
# draw.stroke_color=Color('#aaaaaa')
# draw.circle( (center_x, center_y), (center_x - radius + 3, center_y))
def draw_pointer_needle(draw, color, stroke_width, tip_radius, tail_radius, opacity):
# draw.stroke_opacity = 0.5
# draw.stroke_color = Color('#333333')
# draw.stroke_width = stroke_width+2
# draw.line( (120, 120 + tail_radius+1), (120,120-tip_radius-1))
draw.stroke_width = stroke_width
draw.stroke_color = color
draw.stroke_opacity = opacity
draw.line( (120, 120 + tail_radius), (120,120-tip_radius))
#draw.line( (119.5, 119.5 + tail_radius), (119.5,119.5-tip_radius))
with Image(width=240, height=240, background=Color('none')) as img:
with Drawing() as draw:
# draw_pointer_needle(draw, Color("#F45700"), 2.25, 100, 30, 1);
draw_pointer_needle(draw, Color("#F45700"), 2.25, 102.5, 30.5, 1);
draw_pointer_knub(draw, Color("#F45700"), 120, 120, 10, 1);
# draw_pointer_knub(draw, Color("#F45700"), 119.5, 119.5, 10.1, 1);
draw.draw(img)
img.crop( 105, 15, 135, 155)
fname = 'pointer-red-basic-30x140-c15x105'
img.save(filename=fname+'.png')
img.type = 'palette' # CircuitPython can only do palette BMP3
img.quantize(16) # reduce colors for size
img.save(filename='BMP3:'+fname+'.bmp')