Advertisement
thevipershowita

Vuif.py

Nov 23rd, 2020
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.02 KB | None | 0 0
  1. # This is a sample Python script.
  2.  
  3. # Press Shift+F10 to execute it or replace it with your code.
  4. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
  5. from typing import List
  6. from pathlib import Path
  7. import random
  8. import time
  9.  
  10.  
  11. class colour:
  12.     def __init__(self, r, g, b):
  13.         self.r = r
  14.         self.g = g
  15.         self.b = b
  16.  
  17.  
  18. class pixel:
  19.     def __init__(self, x: int, y: int, colour: colour):
  20.         self.x = x
  21.         self.y = y
  22.         self.colour = colour
  23.  
  24.  
  25. class vuifContent:
  26.     def __init__(self, width, height, pixels: List[pixel]):
  27.         self.pixels = pixels
  28.         self.width = width
  29.         self.height = height
  30.  
  31.  
  32. class vuifWriter:
  33.     def __init__(self, filename: Path):
  34.         self.filename = filename
  35.  
  36.     def writeOnFile(self, vuifContent: vuifContent):
  37.         with open(self.filename, "wb") as file:
  38.             file.write(bytes(vuifContent.width))
  39.             file.write(bytes(0x20))
  40.             file.write(bytes(vuifContent.height))
  41.             file.write(bytes(0x0A))
  42.             for pixel in vuifContent.pixels:
  43.                 clr = pixel.colour
  44.                 file.write(bytes(pixel.x))
  45.                 file.write(bytes(pixel.y))
  46.                 file.write(bytes(clr.r))
  47.                 file.write(bytes(clr.g))
  48.                 file.write(bytes(clr.b))
  49.         file.close()
  50.  
  51.  
  52. def randomVuifContent(width: int, height: int):
  53.     randomPixels = []
  54.     for w in range(0, width):
  55.         for h in range(0, height):
  56.             randR = random.randint(0, 255)
  57.             randG = random.randint(0, 255)
  58.             randB = random.randint(0, 255)
  59.             print(f" R{randR}, G{randG}, B{randB}")
  60.             randomPixels.append(pixel(w, h, colour(randB, randG, randB)))
  61.     return vuifContent(width, height, randomPixels)
  62.  
  63.  
  64. print("Starting generation. . . ")
  65. startTime = int(time.time())
  66. obj = vuifWriter(Path("randomfile.vuif"))
  67. obj.writeOnFile(randomVuifContent(8, 8))
  68. print(f"Time taken: {int(time.time()) - startTime}.")
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement