so i recently started playing around with the easygraphics library, following some coding challenges. When I started my current project, I was using RENDER_MODE_MANUAL, according to some sample easygraphics code. The whole time I had trouble with clearing the screen at the right time, using delay_fps() properly and so on, so towards the end I decided to try out RENDER_MODE_AUTO. Problem is, the program refuses drawing anything for me, neither background or lines. I really don't see anything wrong with my approach and it's relatively difficult to find good information regarding easygraphics online.
My main.py code:
from easygraphics import *
import math
from branch import Branch
import time
width = 1280
height = 720
length = 150
angle = math.pi / 2
tree = []
branches = []
def mainloop():
global angle
n = 0
a = [width / 2, height]
b = [width / 2, height - length]
root = Branch(a[0], a[1], b[0], b[1])
tree.append(root)
while is_run():
if n < 5:
time.sleep(2)
brancher()
elif n == 5:
time.sleep(100)
n += 1
print(n)
for branch in tree:
branch.draw()
def brancher():
new_branches = []
for branch in tree[:]:
new_branches.append(branch.branchR())
new_branches.append(branch.branchL())
tree.extend(new_branches)
def main():
init_graph(width, height)
set_background_color("#333333")
set_color("#ffffff")
set_line_width(2)
set_render_mode(RenderMode.RENDER_AUTO)
mainloop()
close_graph()
easy_run(main)
My branch.py:
from easygraphics import *
import numpy as np
import math
sizeMult = 0.67
def rotateVector(vector, degrees):
newVector = np.empty(2)
newVector[0] = math.cos(degrees) * vector[0] - math.sin(degrees) * vector[1]
newVector[1] = math.sin(degrees) * vector[0] + math.cos(degrees) * vector[1]
return newVector
class Branch:
def __init__(self, x1, y1, x2, y2):
self.x1 = x1
self.x2 = x2
self.y1 = y1
self.y2 = y2
def draw(self):
line(self.x1, self.y1, self.x2, self.y2)
def branchR(self):
vec = np.array([self.x2, self.y2]) - np.array([self.x1, self.y1])
vec = rotateVector(vec, math.degrees(math.pi / 4))
vec[0] = vec[0] * sizeMult
vec[1] = vec[1] * sizeMult
newEnd = np.array([self.x2, self.y2]) + vec
right = Branch(self.x2, self.y2, newEnd[0], newEnd[1])
return right
def branchL(self):
vec = np.array([self.x2, self.y2]) - np.array([self.x1, self.y1])
vec = rotateVector(vec, -math.degrees(math.pi / 4))
vec[0] = vec[0] * sizeMult
vec[1] = vec[1] * sizeMult
newEnd = np.array([self.x2, self.y2]) + vec
left = Branch(self.x2, self.y2, newEnd[0], newEnd[1])
return left
I apologize for the lack of comments.
Any suggestions? I'd be open to try RENDER_MODE_MANUAL again, but I'd need some pointers as to how.
Many thanks
Edit: I'm on Ubuntu 22.04.4 LTS and I'm using PyCharm. I have the package installed through PyCharm's integrated package installer.