analitics

Pages

Saturday, December 10, 2016

The python modules pygobject, pycairo and pygtk under Windows OS.

I used the python version 2.7 32 bits under .
C:\Python27>python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (
Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

The issue is to instal PyGTK python module but you can see I got errors.
C:\>cd Python27

C:\Python27>cd script
The system cannot find the path specified.

C:\Python27>cd Scripts

C:\Python27\Scripts>pip install PyGTK
Collecting PyGTK
Downloading pygtk-2.24.0.tar.bz2 (2.4MB)
100% |################################| 2.4MB 224kB/s
Complete output from command python setup.py egg_info:
ERROR: Could not import dsextras module: Make sure you have installed pygobj
ect.

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\my_account
\appdata\local\temp\pip-build-os60hf\PyGTK\

C:\Python27\Scripts>pip install pygobject
Collecting pygobject
Downloading pygobject-2.28.3.tar.bz2 (889kB)
100% |################################| 890kB 550kB/s
Complete output from command python setup.py egg_info:
ERROR: Could not find pkg-config: Please check your PATH environment variabl
e.

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\my_account
\appdata\local\temp\pip-build-lt0gbh\pygobject\

I got the pygobject-2.28.3.win32-py2.7.msi, pycairo-1.8.10.win32-py2.7.msi and pygtk-2.24.0.win32-py2.7.msi from gnome website.
I install this python modules using registry and this option: Python from another location and I set my python path: C:\Python27\
>>> import gobject
>>> dir(gobject)
['GBoxed', 'GEnum', 'GError', 'GFlags', 'GInterface', 'GObject', 'GObjectMeta',
...
>>> import cairo
>>> dir(cairo)
['ANTIALIAS_DEFAULT', 'ANTIALIAS_GRAY', 'ANTIALIAS_NONE', 'ANTIALIAS_SUBPIXEL',
>>> import pygtk
>>> dir(pygtk)
['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_
get_available_versions', '_our_dir', '_pygtk_2_0_dir', '_pygtk_dir_pat', '_pygtk
_required_version', 'fnmatch', 'glob', 'os', 'require', 'require20', 'sys']


As you can see this python modules works well.


Thursday, December 8, 2016

Noise 2D, 3D, 4D with opensimplex python module.

OpenSimplex noise is an n-dimensional gradient noise function that was developed in order to overcome the patent-related issues surrounding Simplex noise, while continuing to also avoid the visually-significant directional artifacts characteristic of Perlin noise.
Let's start with instalation:
C:\Python27\Scripts>pip install OpenSimplex
Collecting OpenSimplex
Downloading opensimplex-0.2.tar.gz
Installing collected packages: OpenSimplex
Running setup.py install for OpenSimplex ... done
Successfully installed OpenSimplex-0.2

Test some examples from official page:
C:\Python27>python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (
Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from opensimplex import OpenSimplex
>>> tmp = OpenSimplex()
>>> print (tmp.noise2d(x=10, y=10))
-0.297251513589
>>> tmp = OpenSimplex(seed=1)
>>> print (tmp.noise2d(x=10, y=10))
-0.734782324747
>>> dir(OpenSimplex)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribut
e__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_e
x__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_
_weakref__', '_extrapolate2d', '_extrapolate3d', '_extrapolate4d', 'noise2d', 'n
oise3d', 'noise4d']

Let's make a image example with noise 2D:
from opensimplex import OpenSimplex
from PIL import Image

height = int(input("Enter in the map height: "))
width = int(input("Enter in the map width: "))

def main():
    simplex = OpenSimplex()
    im = Image.new('L', (width, height))
    for y in range(0, height):
        for x in range(0, width):
            value = simplex.noise2d(x , y )
            color = int((value + 1) * 128)
            im.putpixel((x, y), color)
    im.save('noise2d.png')
    im.show()
if __name__ == '__main__':
    main()