MCPcopy
hub / github.com/MrNothing/AI-Blocks / SendFastGraph

Function SendFastGraph

Sources/build_scripts/global_functions.py:93–141  ·  view source on GitHub ↗
(id, data, name="", offset=0, flush=True)

Source from the content-addressed store, hash-verified

91
92SendFastGraphWarningSent = False
93def SendFastGraph(id, data, name="", offset=0, flush=True):
94 global SendFastGraphWarningSent
95
96 if EDITOR_MODE:
97 width = len(data)
98
99 if width>=1000 and not SendFastGraphWarningSent:
100 LogErr("Warning: feeding a large array to SendFastGraph can take time to render.", True)
101 SendFastGraphWarningSent = True
102
103 height = int(len(data)/2)
104
105 _max = Math.MaxValue(data)
106 _min = Math.MinValue(data)
107
108 #Log("_max: "+str(_max))
109
110 img = Image.new( 'RGBA', (width,height), "white")
111 pixels = img.load()
112
113 for x in range(width):
114 val = data[x]-_min
115
116 y = max(0, int(height*(val/abs(_max-_min))))
117 y = min(height-1, y)
118
119 pixels[x, int(height/2)] = (128, 0, 0, 255) # set the colour accordingly
120
121 state = int(height/2)
122
123 while state!=y:
124 if abs(state-y)>1:
125 pixels[x,state] = (128, 128, 255, 255) # set the colour accordingly
126 else:
127 pixels[x,state] = (0, 0, 255, 255) # set the colour accordingly
128
129 if state<y:
130 state+=1
131 else:
132 state-=1
133
134 IOHelpers.CarveNumber(pixels, _max, 10, 0)
135 IOHelpers.CarveNumber(pixels, _min, 10, height-7)
136
137 tmpDir = tempfile.gettempdir()
138 imgPath = str(tmpDir)+"/"+name+"_out_"+str(id)+"_"+str(offset)+".png"
139 img.save(imgPath)
140
141 Log("img_data,"+str(id)+","+imgPath+","+name, flush)
142
143def SendSpectrogram(id, times, frequencies, spectogram, name="", offset=0, flush=True):
144 if EDITOR_MODE:

Callers

nothing calls this directly

Calls 7

LogErrFunction · 0.85
LogFunction · 0.85
MaxValueMethod · 0.80
MinValueMethod · 0.80
loadMethod · 0.80
CarveNumberMethod · 0.80
saveMethod · 0.80

Tested by

no test coverage detected