-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathblockheight.py
110 lines (94 loc) Β· 4.65 KB
/
blockheight.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#! /usr/bin/env python3
from PIL import Image, ImageColor, ImageDraw
from vicariouspanel import NodeyezPanel
import sys
import vicariousbitcoin
import vicarioustext
class BlockHeightPanel(NodeyezPanel):
def __init__(self):
"""Instantiates a new Block Height panel"""
# Define which additional attributes we have
self.configAttributes = {
# legacy key name mappings
"colorBackground": "backgroundColor",
"colorTextFG": "textColor",
"sleepInterval": "interval",
# panel specific key names
"textShadowColor": "textShadowColor",
"textShadowPercent": "textShadowPercent",
}
# Define our defaults (all panel specific key names should be listed)
self._defaultattr("headerEnabled", False)
self._defaultattr("interval", 300)
self._defaultattr("textShadowColor", "#f2a90020")
self._defaultattr("textShadowPercent", 10)
# Initialize
super().__init__(name="blockheight")
def fetchData(self):
"""Fetches all the data needed for this panel"""
self.blocknumber = vicariousbitcoin.getcurrentblock()
def run(self):
super().startImage()
# Background effects based on block height
if self.blocknumber % 210000 == 0:
# last block of halving
pass
elif self.blocknumber % 210000 == 1:
# first block of halving
pass
elif self.blocknumber % 210000 == 145782:
# 69.420% through the halving cycle
pass
elif self.blocknumber % 2016 == 0:
# last block of difficulty period
pass
elif self.blocknumber % 2016 == 1:
# first block of difficulty period
pass
elif self.blocknumber % 2100 == 0:
# whole percentage towards halving
pass
# Block height drawn as an alpha layer on top
blocklayer = Image.new(mode="RGBA", size=(self.canvas.width, self.canvas.height), color=(0,0,0,0))
blockdraw = ImageDraw.Draw(blocklayer)
maxFontSize = 128
minFontSize = 8
sizeFound = False
blocknumbertext = f" {self.blocknumber} "
fs, sw, sh = vicarioustext.getmaxfontsize(self.draw, blocknumbertext, self.width, self.height, True, maxFontSize, minFontSize)
textFits = fs >= minFontSize
textShadowSize = ((self.textShadowPercent * fs) // 100)
textShadowSize = 1 if textShadowSize < 1 else textShadowSize
textShadowAlphaStart = int(self.textShadowColor[-2:],16)
textShadowAlphaPerStep = (255 - textShadowAlphaStart) // textShadowSize
# shadowing
for shadowStep in range(textShadowSize, 1, -1):
textShadowAlpha = textShadowAlphaStart + ((1 + textShadowSize - shadowStep) * textShadowAlphaPerStep)
#print(f"textShadowAlphaPerStep: {textShadowAlphaPerStep}, textShadowSize: {textShadowSize}, shadowStep: {shadowStep}, textShadowAlpha: {textShadowAlpha}")
shadowColor = ImageColor.getrgb(self.textShadowColor[0:7] + hex(textShadowAlpha)[-2:])
if textFits:
vicarioustext.drawcenteredtext(draw=blockdraw, s=blocknumbertext, fontsize=fs, x=(self.width//2) + shadowStep, y=(self.height//2) + shadowStep, textcolor=shadowColor, isbold=True)
else:
vicarioustext.drawlefttext(draw=blockdraw, s=blocknumbertext, fontsize=fs, x=0 + shadowStep, y=(self.height//2) + shadowStep, textcolor=shadowColor, isbold=True)
# normal text
if textFits:
vicarioustext.drawcenteredtext(draw=blockdraw, s=blocknumbertext, fontsize=fs, x=(self.width//2), y=(self.height//2), textcolor=ImageColor.getrgb(self.textColor), isbold=True)
else:
vicarioustext.drawlefttext(draw=blockdraw, s=blocknumbertext, fontsize=fs, x=0, y=(self.height//2), textcolor=ImageColor.getrgb(self.textColor), isbold=True)
self.canvas.alpha_composite(blocklayer)
blocklayer.close()
super().finishImage()
# --------------------------------------------------------------------------------------
# Entry point if running this script directly
# --------------------------------------------------------------------------------------
if __name__ == '__main__':
# If arguments were passed in, treat as a single run
if len(sys.argv) > 1:
if sys.argv[1] in ['-h','--help']:
print(f"Generates an image based on the blockheight")
print(f"Usage:")
print(f"1) Call without arguments to run continuously using the configured defaults")
exit(0)
# Continuous run
p = BlockHeightPanel()
p.runContinuous()