You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
613 B
Python
29 lines
613 B
Python
3 years ago
|
#!/usr/bin/env python3
|
||
|
|
||
|
import cairo
|
||
|
import math
|
||
|
from utils import random_color
|
||
|
|
||
|
WIDTH, HEIGHT = 256, 256
|
||
|
BLOCKS = 5
|
||
|
|
||
|
def main():
|
||
|
|
||
|
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
|
||
|
ctx = cairo.Context(surface)
|
||
|
|
||
|
ctx.scale(WIDTH, HEIGHT) # Normalizing the canvas
|
||
|
|
||
|
block_height = 1/BLOCKS
|
||
|
|
||
|
for num in range(BLOCKS):
|
||
|
r, g, b = random_color()
|
||
|
ctx.rectangle(0, num*block_height, 1, (num+1)*block_height)
|
||
|
ctx.set_source_rgb(r, g, b)
|
||
|
ctx.fill()
|
||
|
|
||
|
surface.write_to_png("out/blocks.png") # Output to PNG
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|