Vous n'êtes pas identifié(e).
Pendant que je découvre et apprends à jouer avec le module PIL, j'ai codé un petit script python pour générer un wallpaper aux couleurs de votre distribution préférée.
Code
#! /usr/env python
# -*- coding:utf-8 -*-
# author : WarLocG(c) 2017
# licence : WTFPL
# description : Python script to create binary swirl wallpaper. Just for fun :)
# version : v0.2-beta
# history log
# 0.2-beta : cleaned snippet + add horizontal_gradient function
# 0.1-beta : initial release
from PIL import Image
import ImageDraw
import ImageFont
import wx
import math
import random
app = wx.App(False) # Remove 'the wx.App object must be create first' error
SAVEFILE = 'wallpaper.png'
FORMAT = 'PNG'
WIDTH = wx.GetDisplaySize()[0]
HEIGHT = wx.GetDisplaySize()[1]
OPAQUE = 255
TRANSPARENT = 0
FONT_NORMAL = '/usr/share/fonts/truetype/freefont/FreeSans.ttf'
FONT_BOLD = '/usr/share/fonts/truetype/freefont/FreeSansBold.ttf'
slackware = ( 60, 40, 80) # dark blue
mint_kde = ( 80,100,200) # blue
mint_gnome = ( 80,200,100) # green
debian = (200, 0, 60) # purple
kali = ( 0, 80,200) # blue
gentoo = (150,100,200) # mallow
manjaro = ( 40,180,120) # greenish cyan
viperr = ( 80,100, 20) # greenish olive
livarp = (120,120,120) # grey
crunchbang = ( 40, 40, 40) # grey
raspian = ( 80, 20, 40) # red
target_c= crunchbang
# Create vertical gradient
# draw : ImageDraw object
# rgb : tuple with information for red, green and blue
# inverse : colour to black if True, else black to colour
def vertical_gradient(draw=None,rgb=(0,0,0),inverse=False):
if draw is None:
pass
else:
blue = rgb[0] / 255.0
green = rgb[1] / 255.0
red = rgb[2] / 255.0
for gradient in range(255):
if inverse:
colour = (int(blue*(255-gradient)),int(green*(255-gradient)),int(red*(255-gradient)), OPAQUE)
else:
colour = (int(blue*gradient),int(green*gradient),int(red*gradient), OPAQUE)
step = HEIGHT / 255.0
pos_start = (gradient * step)
pos_end = (gradient * step) + step
draw.rectangle(((0,pos_start),(WIDTH,pos_end)), fill=colour)
return None
# Create horizontal gradient
# draw : ImageDraw object
# rgb : tuple with information for red, green and blue
# inverse : colour to black if True, else black to colour
def horizontal_gradient(draw=None,rgb=(0,0,0),inverse=False):
if draw is None:
pass
else:
blue = rgb[0] / 255.0
green = rgb[1] / 255.0
red = rgb[2] / 255.0
for gradient in range(255):
if inverse:
colour = (int(blue*(255-gradient)),int(green*(255-gradient)),int(red*(255-gradient)), OPAQUE)
else:
colour = (int(blue*gradient),int(green*gradient),int(red*gradient), OPAQUE)
step = WIDTH / 255.0
pos_start = (gradient * step)
pos_end = (gradient * step) + step
draw.rectangle(((pos_start, 0),(pos_end, HEIGHT)), fill=colour)
return None
# Create the swirl of bits
# draw : ImageDraw object
# rgb : tuple with information for red,green and blue
# angle : scale bit for n radian
# variation : scale darkness or brightness
# ttf : font in use
def binary_swirl(draw=None,rgb=(0,0,0),angle=0,variation=0,ttf=FONT_NORMAL):
if draw is None:
pass
else:
blue = rgb[0] / 255.0
green = rgb[1] / 255.0
red = rgb[2] / 255.0
for i in range(WIDTH):
alter = i / (WIDTH/30) # 0..30
font = ImageFont.truetype(ttf, 2 * int(alter))
posx = int((WIDTH *.5) - (math.sin(i+angle) * i ))
posy = int((HEIGHT *.5) + (math.cos(i+angle) * i ))
bit = str(random.randrange(2))
colour = (int((blue*255) + (30-alter*9)) + variation,
int((green*255)+ (30-alter*9)) + variation,
int((red*255) + (30-alter*9)) + variation,
OPAQUE-alter)
draw.text((posx,posy), unicode(bit,'UTF-8'), font=font, fill=colour)
return None
img = Image.new("RGBA",(WIDTH,HEIGHT))
draw = ImageDraw.Draw(img)
vertical_gradient(draw, target_c)
binary_swirl(draw, target_c, 0, 0)
binary_swirl(draw, target_c, 30, 80, FONT_BOLD)
img.save(SAVEFILE, FORMAT)
Edit: Corrections effectuées dans les snippet et le rendu devrait être encore mieux à présent.
Apercus
2.0 beta
1.0 beta
Je vous laisse découvrir les autres par vous-même
Quelques références pour PIL:
http://www.effbot.org/imagingbook/pil-index.htm
http://jlbicquelet.free.fr/scripts/python/pil/pil.php
Hors ligne
super intéréssant j'ai hate d'étudier le code
Merci
Mess With The Bests
Die Like The Rest
Hors ligne