Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is a sample Python script.
- # Press Shift+F10 to execute it or replace it with your code.
- # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
- from typing import List
- from pathlib import Path
- import random
- import time
- class colour:
- def __init__(self, r, g, b):
- self.r = r
- self.g = g
- self.b = b
- class pixel:
- def __init__(self, x: int, y: int, colour: colour):
- self.x = x
- self.y = y
- self.colour = colour
- class vuifContent:
- def __init__(self, width, height, pixels: List[pixel]):
- self.pixels = pixels
- self.width = width
- self.height = height
- class vuifWriter:
- def __init__(self, filename: Path):
- self.filename = filename
- def writeOnFile(self, vuifContent: vuifContent):
- with open(self.filename, "wb") as file:
- file.write(bytes(vuifContent.width))
- file.write(bytes(0x20))
- file.write(bytes(vuifContent.height))
- file.write(bytes(0x0A))
- for pixel in vuifContent.pixels:
- clr = pixel.colour
- file.write(bytes(pixel.x))
- file.write(bytes(pixel.y))
- file.write(bytes(clr.r))
- file.write(bytes(clr.g))
- file.write(bytes(clr.b))
- file.close()
- def randomVuifContent(width: int, height: int):
- randomPixels = []
- for w in range(0, width):
- for h in range(0, height):
- randR = random.randint(0, 255)
- randG = random.randint(0, 255)
- randB = random.randint(0, 255)
- print(f" R{randR}, G{randG}, B{randB}")
- randomPixels.append(pixel(w, h, colour(randB, randG, randB)))
- return vuifContent(width, height, randomPixels)
- print("Starting generation. . . ")
- startTime = int(time.time())
- obj = vuifWriter(Path("randomfile.vuif"))
- obj.writeOnFile(randomVuifContent(8, 8))
- print(f"Time taken: {int(time.time()) - startTime}.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement