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.
31 lines
746 B
Python
31 lines
746 B
Python
3 years ago
|
#!/usr/bin/env python3
|
||
|
|
||
|
import cairo
|
||
|
import math
|
||
|
from utils import random_color
|
||
|
|
||
|
WIDTH, HEIGHT = 256, 256
|
||
|
|
||
|
def main():
|
||
|
|
||
|
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
|
||
|
ctx = cairo.Context(surface)
|
||
|
|
||
|
ctx.scale(WIDTH, HEIGHT) # Normalizing the canvas
|
||
|
|
||
|
pat = cairo.LinearGradient(0.0, 0.0, 0.0, 1.0)
|
||
|
r1, g1, b1 = random_color()
|
||
|
r2, g2, b2 = random_color()
|
||
|
pat.add_color_stop_rgba(1, r1, g1, b1, 1) # First stop, 50% opacity
|
||
|
pat.add_color_stop_rgba(0, r2, g2, b2, 1) # Last stop, 100% opacity
|
||
|
|
||
|
ctx.rectangle(0, 0, 1, 1) # Rectangle(x0, y0, x1, y1)
|
||
|
ctx.set_source(pat)
|
||
|
ctx.fill()
|
||
|
|
||
|
|
||
|
surface.write_to_png("out/gradient.png") # Output to PNG
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|