Skip to content

Commit

Permalink
Format code using black
Browse files Browse the repository at this point in the history
  • Loading branch information
xzfc committed Jun 13, 2023
1 parent 4926a93 commit 666639b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 17 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.black]
line-length=79
18 changes: 13 additions & 5 deletions src/font_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3


def print_font(f):
lines = f.strip("\n").split("\n")

Expand All @@ -8,17 +9,24 @@ def print_font(f):
r = n = 0
for x in range(5):
for y in range(6):
if lines[y][x + char * (5+1)] == "#":
r |= 1<<n
if lines[y][x + char * (5 + 1)] == "#":
r |= 1 << n
n += 1
result.append(r)
print("const uint data[] = uint[](" + ",".join([f"{hex(x)}u" for x in result]) + ");")
print(
"const uint data[] = uint[]("
+ ",".join([f"{hex(x)}u" for x in result])
+ ");"
)


print_font("""
print_font(
"""
..... ..... ..... .###. ..#.. .###. .###. #...# ##### .###. ##### .###. .###.
..#.. ..... ..... #...# .##.. #...# #...# #...# #.... #.... ....# #...# #...#
.###. .###. ..... #...# ..#.. ...#. ..##. #...# ####. ####. ...#. .###. #...#
..#.. ..... ..... #...# ..#.. ..#.. ....# ##### ....# #...# ..#.. #...# .####
..... ..... ..... #...# ..#.. .#... #...# ....# #...# #...# .#... #...# ....#
..... ..... ..#.. .###. .###. ##### .###. ....# .###. .###. #.... .###. .###.
""")
"""
)
36 changes: 26 additions & 10 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self):
self.x = self.y = self.z = (0.0, 0.0, 0.0)
self.mouse_pressed = False
self.mouse_i = None
self.mouse_f = self.mouse_f_start = (float('nan'), float('nan'))
self.mouse_f = self.mouse_f_start = (float("nan"), float("nan"))
self.size = (1, 1)

def origin(self):
Expand All @@ -62,7 +62,10 @@ def move(self, x, y):

def zoom(self, z, origin=None):
if origin:
sx, sy = origin[0] - self.size[0] / 2.0, origin[1] - self.size[1] / 2.0
sx, sy = (
origin[0] - self.size[0] / 2.0,
origin[1] - self.size[1] / 2.0,
)
else:
sx, sy = (0, 0)
self.move(sx, -sy)
Expand Down Expand Up @@ -183,12 +186,16 @@ def setFragmentShader(self, shader, version):
vertexShader = "#version 130\n" + self.vertexShaderData
vertexShader = MyGL.compileShader(vertexShader, GL.GL_VERTEX_SHADER)

program = GL.shaders.compileProgram(vertexShader, fragmentShader, validate=False)
program = GL.shaders.compileProgram(
vertexShader, fragmentShader, validate=False
)

GL.glBindFragDataLocation(program, 0, "machuchu_fragColor")
positionAttrib = GL.glGetAttribLocation(program, "machuchu_position")
GL.glEnableVertexAttribArray(positionAttrib);
GL.glVertexAttribPointer(positionAttrib, 2, GL.GL_FLOAT, GL.GL_FALSE, 0, 0);
GL.glEnableVertexAttribArray(positionAttrib)
GL.glVertexAttribPointer(
positionAttrib, 2, GL.GL_FLOAT, GL.GL_FALSE, 0, 0
)

GL.glUseProgram(program)
self.program = program
Expand Down Expand Up @@ -330,7 +337,9 @@ def format_error(prep, err_text):
prev = curr
result.append("\n")
try:
result.append("{}:{}:\n".format(escape(prep.fnames[m_fno]), m_line))
result.append(
"{}:{}:\n".format(escape(prep.fnames[m_fno]), m_line)
)
result.append("%5d | " % (m_line,))
result.append(escape(prep.fcontents[m_fno][m_line - 1]))
except IndexError:
Expand Down Expand Up @@ -396,7 +405,7 @@ def initShaderDock(self):

widget.setLayout(shaderLayout)
scrollarea.setWidgetResizable(True)
scrollarea.setFrameShape(Qt.QFrame.NoFrame);
scrollarea.setFrameShape(Qt.QFrame.NoFrame)
scrollarea.setWidget(widget)
shaderDock.setWidget(scrollarea)

Expand Down Expand Up @@ -491,7 +500,9 @@ def updateUniforms(self, data, uniforms, types):
else:
if old is not None:
old.delete()
self.uniforms[name] = SliderUniform(self, name, value, min, max)
self.uniforms[name] = SliderUniform(
self, name, value, min, max
)
unpragmed.remove(name)

for name in unpragmed:
Expand Down Expand Up @@ -534,7 +545,10 @@ def loadFile(self, filename):
else:
text = escape(str(e))
mb = Qt.QMessageBox(
Qt.QMessageBox.Warning, "Error loading shader", text, Qt.QMessageBox.Ok
Qt.QMessageBox.Warning,
"Error loading shader",
text,
Qt.QMessageBox.Ok,
)
mb.setTextFormat(Qt.Qt.RichText)
mb.exec_()
Expand All @@ -547,7 +561,9 @@ def tick(self):
self.glWidget.setUniform("time", self.time_uniform)
self.time.start()
self.glWidget.tick()
self.setWindowTitle("{:d} fps".format(int(round(self.glWidget.getFps()))))
self.setWindowTitle(
"{:d} fps".format(int(round(self.glWidget.getFps())))
)

def timer_reset(self):
self.time_uniform = 0.0
Expand Down
9 changes: 7 additions & 2 deletions src/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def _one(self, fname):
findex = self.fnames.index(fname)

if findex != 0:
self.text_lines.append("#line %d %d /* %s */" % (self._shift, findex, fname))
self.text_lines.append(
"#line %d %d /* %s */" % (self._shift, findex, fname)
)

for n, line in enumerate(contents):
match = ONCE_RE.match(line)
Expand All @@ -45,7 +47,10 @@ def _one(self, fname):
if path != "":
path += "/"
self._one(path + match.groups()[0])
self.text_lines.append("#line %d %d /* %s:%d */" % (self._shift+n+1, findex, fname, n+1))
self.text_lines.append(
"#line %d %d /* %s:%d */"
% (self._shift + n + 1, findex, fname, n + 1)
)
continue
match = VERSION_RE.match(line)
if match:
Expand Down

0 comments on commit 666639b

Please sign in to comment.