Skip to content

Commit

Permalink
还在画彩色的IMAGE
Browse files Browse the repository at this point in the history
  • Loading branch information
pointm committed Sep 20, 2023
1 parent 75d034b commit 6669006
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
Binary file modified __pycache__/testslice.cpython-311.pyc
Binary file not shown.
Binary file modified media/images/testslice/ImageFromArray_ManimCE_v0.17.3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/images/testslice/UseRGB_ManimCE_v0.17.3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 57 additions & 5 deletions testslice.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,62 @@ def construct(self):
self.add(x)


class ImageFromArray(Scene):
import random


class ColorfulArray(Scene):
def construct(self):
image = ImageMobject(
np.uint8([[[255, 0, 0], [0, 0, 255]], [[255, 0, 0], [0, 0, 255]]])
)
image.height = 7
random_integers = [random.randint(0, 255) for _ in range(60)]
result = [random_integers[i : i + 3] for i in range(0, len(random_integers), 3)]
big_list = [result[i : i + 5] for i in range(0, len(result), 5)]
print(big_list)

image = ImageMobject(np.uint8(big_list))
image.set_resampling_algorithm(RESAMPLING_ALGORITHMS["box"])
image.height = 10
self.add(image)


class UseRGB(Scene):
def convert_to_3d_rgb(self, rgb_list):
result = []
for row in rgb_list:
new_row = []
for rgb in row:
r = (rgb >> 16) & 0xFF
g = (rgb >> 8) & 0xFF
b = rgb & 0xFF
new_row.append([r, g, b])
result.append(new_row)
return result

def convert_hex_to_int(hex_string):
return int(hex_string[1:], 16)

def construct(self):
hex_list = [
["#FF0000", "#00FF00", "#0000FF", "#FFFF00"],
["#FF00FF", "#00FFFF", "#000000", "#FFFFFF"],
["#C0C0C0", "#808080", "#800000", "#808000"],
["#008000", "#800080", "#008080", "#000080"],
["#F0F8FF", "#FAEBD7", "#7FFFD4", "#FFE4C4"],
]

int_list = []
for sub_list in hex_list:
int_sub_list = []
for hex_string in sub_list:
int_sub_list.append(int(hex_string[1:], 16))
int_list.append(int_sub_list)

print(int_list)
# hex_list = int(*hex_list[1:], 16)
hex_list = self.convert_to_3d_rgb(int_list)
random_int = hex_list
print(random_int)

image = ImageMobject(np.uint8(random_int))
image.set_resampling_algorithm(RESAMPLING_ALGORITHMS["box"])
image.height = 5
self.add(image)
return super().construct()

0 comments on commit 6669006

Please sign in to comment.