Green flag and watch Utilizes Pascal's triangle to draw Sierpinski's WIP: making my own pascal's triangle generator in Scratch instead of python
interesting yap ahead... Very simple code used to generate the list at the bottom of notes. The code utilizes the fact that odd numbers, added to an odd number, make an even one; even numbers work the same way. However, adding an odd and and even make an odd. This allows me to store the necessary information without storing thousands of digits for each row. Feel free to experiment with different lists, I was unable to save on Scratch with large lists but Turbowarp works just fine and you can draw the triangle with a scale of less than one using the custom block in the code. (python) ODD = False EVEN = True def generate_pascal_triangle(num_rows): triangle = [] for i in range(num_rows): row = [ODD] if i > 0: for j in range(i - 1): row.append(triangle[i - 1][j] == triangle[i - 1][j + 1]) row.append(ODD) triangle.append(row) return triangle def save_pascal_to_txt(triangle, filename="pascal_triangle.txt"): with open(filename, "w") as file: for row in triangle: file.write(" ".join(map(str, row)) + "\n") if __name__ == "__main__": num_rows = int(input("Enter the number of rows for Pascal's triangle: ")) pascal_triangle = generate_pascal_triangle(num_rows) save_pascal_to_txt(pascal_triangle) print(f"Pascal's triangle saved to pascal_triangle.txt")