analitics

Pages

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()

Tuesday, December 6, 2016

The python-nmap python module fail.

You can read about this python module here.

First let's install this python module.
C:\Python27>cd Scripts

C:\Python27\Scripts>pip install python-nmap
Collecting python-nmap
Downloading python-nmap-0.6.1.tar.gz (41kB)
100% |################################| 51kB 240kB/s
Installing collected packages: python-nmap
Running setup.py install for python-nmap ... done
Successfully installed python-nmap-0.6.1

About this python-nmap version you can read here.
I try to run the example source code but not of this example working.
For example I got this:
>>> nm.scan('127.0.0.1', '22-443')
{'nmap': {'scanstats': {'uphosts': '1', 'timestr': 'Wed Dec 07 08:13:01 2016', '
downhosts': '-1', 'totalhosts': '0', 'elapsed': '10.74'}, 'scaninfo': {'tcp': {'
services': '22-443', 'method': 'syn'}, 'error': [u'dnet: Failed to open device l
o0\r\nQUITTING!\r\n', u'dnet: Failed to open device lo0\r\nQUITTING!\r\n']}, 'co
mmand_line': 'nmap -oX - -p 22-443 -sV 127.0.0.1'}, 'scan': {}}