analitics

Pages

Thursday, October 31, 2013

News Python 2.6.9 final was released on October 29 2013.

News about python from www.python.org.
Python 2.6.9 is a security-fix source-only release for Python 2.6.8, fixing several reported security issues: issue 16037, issue 16038, issue 16039, issue 16040, issue 16041, and issue 16042 (CVE-2013-1752, long lines consuming too much memory), as well as issue 14984 (security enforcement on $HOME/.netrc files), issue 16248 (code execution vulnerability in tkinter), and issue 18709 (CVE-2013-4238, SSL module handling of NULL bytes inside subjectAltName).

Monday, October 21, 2013

Python versus Matlab - good article by Luis Pedro Coelho

Luis Pedro Coelho is a computational biologist at EMBL.
In this article Luis Pedro Coelho come with many arguments about Python versus Matlab.
Very good article ...

Thursday, October 17, 2013

How to make a color gradient and images with python script.

The Image and ImageDraw provide simple 2D graphics to create new images, annotate or retouch existing images, and to generate graphics.

Also this can help you to make on the fly images for you.

Let's see one example ...

First you need to import this modules and random python module

import Image,ImageDraw
from random import randint as rint

The next step : make one image , get some random numbers...

You need two colors : first is one random color and second is make from first color, see next source code:

img = Image.new("RGB", (500,500), "#FFFFFF")
draw = ImageDraw.Draw(img)
r,g,b = rint(0,255), rint(0,255), rint(0,255)
dr = (rint(0,255) - r)/500.
dg = (rint(0,255) - g)/500.
db = (rint(0,255) - b)/500.

Now you need to draw lines with this gradient of two colors.

    for i in range(500):
        r,g,b = r+dr, g+dg, b+db
        draw.line((i,0,i,500), fill=(int(r),int(g),int(b)))

... and the python script source code:

import Image,ImageDraw
from random import randint as rint

def random_gradient(name):
    img = Image.new("RGB", (500,500), "#FFFFFF")
    draw = ImageDraw.Draw(img)

    r,g,b = rint(0,255), rint(0,255), rint(0,255)
    dr = (rint(0,255) - r)/500.
    dg = (rint(0,255) - g)/500.
    db = (rint(0,255) - b)/500.
    for i in range(500):
        r,g,b = r+dr, g+dg, b+db
        draw.line((i,0,i,500), fill=(int(r),int(g),int(b)))

    img.save(name+".png", "PNG")

if __name__ == "__main__":
    for name in range(10):
        random_gradient(str(name))

The result of this script will make images :