I am just going to show the while loop for the pygame run process, it’s a big file.
Wondering if anyone can spot why my CPU is running loud, (sounds like fan kicking in) whenever I run it?
It has a delay to when the fan starts, and when it stops. I tried adding a sleep to maybe pause whatever is running so hard, but to no avail. Can anyone give me some insight?
def run_draw(self):
red = 0
green = 0
blue = 0
on = False
off = False
new = False
color_pick = False
color = (red, green, blue)
screen.fill(globals.background_color)
picker_window = False
new_window = None
while self.running:
#sleep(1) <---- no circles drawn to screen
#sleep(0.1) <---- slight lag, circles being draw, CPU still Whirring during run
animation_timer.tick(60)
screen.fill(globals.background_color)
self.center_surface.draw_surface()
pg.draw.rect(screen, globals.menu_bar_color, (0, 0, globals.WIDTH, globals.HEIGHT//20), 0)
pg.draw.rect(screen, globals.menu_bar_color, (0, globals.HEIGHT - globals.HEIGHT//20, globals.WIDTH, globals.HEIGHT//20), 0)
for rects in self.rect_list:
rects.place_rect()
for circs in self.drawn_circs:
circs.add_circle()
for window in self.windows:
window.run(red, green, blue)
mousedown = False
events = pg.event.get()
for event in events:
if event.type == pg.QUIT:
self.running = False
pg.quit()
exit(0)
if event.type == pg.MOUSEBUTTONDOWN:
position = pg.mouse.get_pos()
# cbd = Current Button Dimensions
# list returned = [x position, y postion, x postion + width, y position + height]
for rects in self.rect_list:
cbd = rects.get_rect_place()
if cbd[0] < position[0] < cbd[2]:
if cbd[1] < position[1] < cbd[3]:
#print("IN BUTTON", rects.name)
if rects.name == "ON":
on = True
off = False
if rects.name == "OFF":
off = True
on = False
color_pick = False
if len(self.windows) > 0:
self.windows.pop()
if rects.name == "NEW":
new = True
color_pick = False
if rects.name == 'COLOR':
on = True
new = False
color_pick = True
off = False
new_window = ColorPicker()
self.windows.append(new_window)
else:
pass
for event in events:
if event.type == pg.MOUSEBUTTONDOWN and not off and on and new and not color_pick:
radius = 20
(x, y) = pg.mouse.get_pos()
# dsp = Drawn Screen Parameters
limit_x_left = self.dsp[0] - radius
limit_x_right = self.dsp[2] - radius
limit_y_top = self.dsp[1] - radius
limit_y_bottom = self.dsp[3] - radius
if limit_x_left < x < limit_x_right:
if limit_y_top < y < limit_y_bottom:
color = (red, green, blue)
circle = DrawCircle(screen, x, y, radius, color)
self.drawn_circs.append(circle)
for rects in self.rect_list:
cbd = rects.get_rect_place()
if cbd[0] < position[0] < cbd[2]:
if cbd[1] < position[1] < cbd[3]:
#print("IN BUTTON", rects.name)
if rects.name == "ON":
on = True
off = False
if rects.name == "OFF":
off = True
on = False
color_pick = False
if len(self.windows) > 0:
self.windows.pop()
if rects.name == "NEW":
new = True
color_pick = False
if rects.name == 'COLOR':
on = True
new = False
color_pick = True
off = False
new_window = ColorPicker()
self.windows.append(new_window)
else:
pass
if event.type == pg.MOUSEBUTTONDOWN and on and color_pick and not off and not new:
(gx, gy, gdx, gdy) = new_window.get_button_place("plus green")
(g2x, g2y, g2dx, g2dy) = new_window.get_button_place("minus green")
(bx, by, bdx, bdy) = new_window.get_button_place("plus blue")
(b2x, b2y, b2dx, b2dy) = new_window.get_button_place("minus blue")
(rx, ry, rdx, rdy) = new_window.get_button_place("plus red")
(r2x, r2y, r2dx, r2dy) = new_window.get_button_place("minus red")
(shx, shy, shdx, shdy) = new_window.get_button_place("plus shade")
(sh2x, sh2y, sh2dx, sh2dy) = new_window.get_button_place("minus shade")
position = pg.mouse.get_pos()
if gx < position[0] < gdx and gy < position[1] < gdy:
if 0 <= green <= 250:
green += 5
elif g2x < position[0] < g2dx and g2y < position[1] < g2dy:
if 255 >= green >= 5:
green -= 5
elif bx < position[0] < bdx and by < position[1] < bdy:
if 0 <= blue <= 250:
blue += 5
elif b2x < position[0] < b2dx and b2y < position[1] < b2dy:
if 255 >= blue >= 5:
blue -= 5
elif rx < position[0] < rdx and ry < position[1] < rdy:
if 0 <= red <= 250:
red += 5
elif r2x < position[0] < r2dx and r2y < position[1] < r2dy:
if 255 >= red >= 5:
red -= 5
elif shx < position[0] < shdx and shy < position[1] < shdy:
# I tried increments of 10, shade difference was much more dramatic
if 0 <= red <= 250:
red += 5
if 0 <= green <= 250:
green += 5
if 0 <= blue <= 250:
blue += 5
elif sh2x < position[0] < sh2dx and sh2y < position[1] < sh2dy:
if 255 >= red >= 5:
red -= 5
if 255 >= green >= 5:
green -= 5
if 255 >= blue >= 5:
blue -= 5
else:
print("-----color picker event else clause----")
for rects in self.rect_list:
cbd = rects.get_rect_place()
if cbd[0] < position[0] < cbd[2]:
if cbd[1] < position[1] < cbd[3]:
#print("IN BUTTON", rects.name)
if rects.name == "ON":
on = True
off = False
if rects.name == "OFF":
# I have to double click to get color picker off... need fixed
off = True
on = False
color_pick = False
if len(self.windows) > 0:
self.windows.pop()
if rects.name == "NEW":
new = True
color_pick = False
if rects.name == 'COLOR':
on = True
new = False
color_pick = True
off = False
new_window = ColorPicker()
self.windows.append(new_window)
else:
pass
if on:
item = self.object_list[0]
item.draw_circle()
if off:
item = self.object_list[1]
item.draw_circle()
#print(" object_list length ==========", len(self.object_list))
pg.display.flip()