Felix Pankratz 3 years ago
parent 3ac7f2f663
commit af8052514c

@ -0,0 +1,28 @@
#!/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()

@ -0,0 +1,30 @@
#!/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()

@ -0,0 +1,8 @@
#!/usr/bin/env python3
import random
def random_color():
red = random.uniform(0, 1)
green = random.uniform(0, 1)
blue = random.uniform(0, 1)
return red, green, blue

@ -0,0 +1,39 @@
#!/usr/bin/env python3
import cairo
import math
from utils import random_color
WIDTH, HEIGHT = 256, 256
WAVES = 8
def main():
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context(surface)
ctx.scale(WIDTH, HEIGHT) # Normalizing the canvas
wave_height = 1/WAVES
for num in range(WAVES):
r, g, b = random_color()
points = []
x = 0
while x < 1:
y = math.sin(x*50) * 0.1
points.append((x, ( (y/4) + ((0.5+num)*wave_height))))
x += 0.001
print(points)
ctx.move_to(*points[0])
for p in points[1:]:
ctx.line_to(*p)
ctx.set_line_width(0.002)
ctx.set_source_rgb(r, g, b)
ctx.stroke()
surface.write_to_png("out/waves.png") # Output to PNG
if __name__ == '__main__':
main()
Loading…
Cancel
Save