Advertisement
Guest User

Random wallpaper

a guest
Sep 3rd, 2010
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. #! /usr/bin/env python
  2. #coding=utf-8
  3.  
  4. """This script generates a random circle wallpaper
  5. Range of values to get from can be adjusted below to create a more artistic wallpaper
  6. based on colour theory"""
  7. from random import randint
  8.  
  9. # Document size
  10. WIDTH, HEIGHT = (1920, 1200)
  11.  
  12. circles = []
  13. blurs = []
  14.  
  15. # Make x number of circles and blur filters
  16. for id in range(20):
  17.     # Get random values
  18.     x_position = randint(0, 1920)
  19.     y_position = randint(300, 900)
  20.    
  21.     radius = randint(20, 250)
  22.    
  23.     # The range can be limited to use more exact colours
  24.     r_colour = randint(0, 255)
  25.     g_colour = randint(0, 255)
  26.     b_colour = randint(0, 255)
  27.     colour = "#%x%x%x"%(r_colour, g_colour, b_colour)
  28.    
  29.     # I've used opacities between 20% and 80% to keep it more even
  30.     opacity = "0.%s"%(randint(20, 80))
  31.     # I have no idea what the range for this is but inkscape suggests between 0.001 and 250
  32.     blur_amount = "%s.%s"%(randint(1, 25), randint(0, 100))
  33.    
  34.     # Append circle xml to a list
  35.     circles.append("""<circle cx="%s" cy="%s" r="%s" style="stroke:black; stroke-width:2; fill:%s; opacity:%s; filter:url(#blur%s);" />"""%(x_position, y_position, radius, colour, opacity, id))
  36.     # Append filter xml to another list
  37.     blurs.append("""<filter id="blur%s" width="1.5" height="1.5">
  38. <feGaussianBlur in="SourceGraphic" stdDeviation="%s"/>
  39. </filter>"""%(id, blur_amount))
  40.  
  41. # Bring it all together
  42. svg = """<?xml version="1.0" standalone="no"?>
  43. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  44. <svg width="%s" height="%s" version="1.1" xmlns="http://www.w3.org/2000/svg">
  45. <defs>
  46. <linearGradient
  47.       id="linearGradient">
  48.  <stop
  49.     id="stop1"
  50.     style="stop-color:#08559d;stop-opacity:1"
  51.     offset="0" />
  52.  <stop
  53.     id="stop2"
  54.     style="stop-color:#741175;stop-opacity:1"
  55.     offset="1" />
  56. </linearGradient>
  57. <radialGradient
  58.    cx="733.01025"
  59.    cy="526.61871"
  60.    r="625.84656"
  61.    fx="733.01025"
  62.    fy="526.61871"
  63.    id="gradient"
  64.    xlink:href="#linearGradient"
  65.    gradientUnits="userSpaceOnUse"
  66.    gradientTransform="matrix(3.7820774,2.7550586e-8,0,2.1400777,-1812.3015,-527.00498)" />
  67. %s
  68. </defs>
  69. <rect width="%s" height="%s" style="fill:url(#gradient)" />
  70. %s
  71. </svg>"""%(WIDTH, HEIGHT, "\n".join(blurs), WIDTH, HEIGHT, "\n".join(circles))
  72.  
  73. # Save the svg
  74. wallpaper_file = open('drawing.svg', 'w')
  75. print >> wallpaper_file, svg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement