CELLNOISE_____________________Blender 2.28+
_ Jimmy Haze (script nr.2)
_ 9/2003
_
_ Thank’s to mr.Selleri (S68) for his wonderful “BWF”.py,
_ which inspired me to write this cellnoise script. _
1_ You have to download CGKit 1.0+ (by: Matthias Baas)
from : http://sourceforge.net/projects/cgkit/
2_ Install CGKit…
3_ then copy “noise.pyd” and “cgtypes.pyd”
(on my pc they were in : c:\Python\Lib\site-packages)
and paste to your blender directory.
Cellnoise produces a “blocky” deformed plane with 3 layers of noise,
you have control over frequency ,x-y-z offset, and randomised edges.
#############################################################
#############################################################
##
## CELLNOISE
## _ Jimmy Haze
## _ 9/2003
## _
## _ Thank's to mr.Selleri (S68) for his wonderful "BWF".py,
## _ which inspired me to write this cellnoise script.
## _
##
#############################################################
#############################################################
##
## 1_ You have to download CGKit 1.0+ (by: Matthias Baas)
## ----------
## from : www.sourceforge.net
## -------------------
##
## 2_ Install CGKit...
##
## 3_ then copy "noise.pyd" and "cgtypes.pyd"
## (on my pc they were in : c:\Python\Lib\site-packages\)
## and paste to your blender directory.
##
#############################################################
#############################################################
#
import Blender
from Blender import *
from Blender.Draw import *
from Blender.BGL import *
from math import *
from whrandom import *
#
import noise
#
#############################################################
#
#############################################################
xres=Create(32)
yres=Create(32)
cellf =Create(2)
cex =Create(1.0)
cey =Create(1.0)
cez =Create(0)
cezz =Create(0)
offz =Create(0)
offx =Create(0.0)
offy =Create(0.0)
offz1 =Create(1)
offz2 =Create(1)
rx=Create(0.0)
ry=Create(0.0)
rz=Create(0)
#############################################################
#
#############################################################
def Cell():
global cex, cey, cez, cezz, offx, offy, offz1, offz2
global xres, yres, cellf, rx, ry, rz, offz
####
me=NMesh.GetRaw()
####
i=0.0
j=0.0
x=0.0
y=0.0
z=0.0
xmax = xres.val
ymax = yres.val
########
for i in range(0, xmax, 1):
for j in range(0, ymax, 1):
#
xv = (i-xmax/2.0)/10.0
yv = (j-ymax/2.0)/10.0
#
xn=(xv/2)*cex.val*cellf.val+offx.val
xn+=0.25*rx.val*random()
yn=(yv/2)*cey.val*cellf.val+offy.val
yn+=0.25*ry.val*random()
#
xm=(xv/2)*cez.val*0.5*cellf.val+offz.val
xm+=0.25*rx.val*random()
ym=(yv/2)*cezz.val*0.5*cellf.val+offz.val
ym+=0.25*ry.val*random()
#
vn= noise.cellnoise(xn,yn)
vm= noise.cellnoise(xm,ym)
vo= noise.noise(xm,yn)
#
z = vn *offz1.val
z +=vm *offz2.val
z +=0.2*rz.val*sin(vn/vm*rz.val<vo*2.0+1.5*rz.val)
#
#
#
v=NMesh.Vert(i, j, z)
me.verts.append(v)
#
########
for i in range(0,ymax-1):
for j in range(0,xmax-1):
#
a=i+j*ymax
#
f= NMesh.Face()
f.v.append(me.verts[a])
f.v.append(me.verts[a+ymax])
f.v.append(me.verts[a+ymax+1])
f.v.append(me.verts[a+1])
#
me.faces.append(f)
#
NMesh.PutRaw(me, "Cellnoise", 1)
Blender.Redraw()
#############################################################
# Gui
#############################################################
def Warn():
BGL.glRasterPos2d(20, 230)
Blender.Window.Redraw(Blender.Window.Const.TEXT)
####
def draw():
global xres, yres, cex, cey, cez, cezz, cellf
global offx, offy, offz, offz1, offz2, rx, ry, rz
####
BGL.glClearColor(0.6, 0.6, 0.6, 1)
BGL.glColor3f(1,1,1)
BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
#
glColor3f(0.2, 0.3, 0.4)
glRectf(5, 1, 265, 235)
glColor3f(0.5, 0.5, 0.5)
glRectf(10, 6, 260, 190)
#
BGL.glColor3f(0.8, 0.8, 0.8)
BGL.glRasterPos2d(60, 210)
Text("CELLNOISE")
#
rx=Number("raX=",2,20,170,65,15,rx.val,0.0,16.0,"X*random")
ry=Number("raY=",2,92.5,170,65,15,ry.val,0.0,16.0,"Y*random")
rz=Number("",2,165,170,85,15,rz.val,-96.0,96.0)
cex=Number("X =",2,20,140,65,25,cex.val,0.0,16.0,"cell x freq.")
cey=Number("Y =",2,92.5,140,65,25,cey.val,0.0,16.0,"cell y freq.")
cez=Number("X2 =",2,165,140,85,25,cez.val,0.0,16.0,"cell x freq.")
cezz=Number("Y2 =",2,165,110,85,25,cezz.val,0.0,16.0,"cell y freq.")
offz=Number("XY2=",2,165,80,85,25,offz.val,-96.0,96.0,"cell xy offset")
offx=Number("<X>=",2,20,80,65,25,offx.val,-96.0,96.0,"cell X offset")
offy=Number("<Y>=",2,92.5,80,65,25,offy.val,-96.0,96.0,"cell Y offset")
offz1=Number("Z1=",2,20,45,137.5,25,offz1.val,-32.0,32.0)
offz2=Number("Z2=",2,165,45,85,25,offz2.val,-32.0,32.0)
cellf=Number("frequency =",2,20,110,137.5,25,cellf.val,0.0,64.0,"freq.")
xres=Number("X Size =",2,20, 10, 110, 25, xres.val, 2, 128)
yres=Number("Y Size =",2,140, 10, 110, 25, yres.val, 2, 128)
#
Button("Exit ", 1, 165, 200, 85, 25)
###
def event(evt, val):
if (evt== QKEY and not val):
Exit()
def bevent(evt):
if (evt== 1):
Exit()
elif (evt== 2):
Cell()
Draw()
elif (evt== 3):
Cell()
Redraw()
Cell()
Register(draw, event, bevent)
Blender.Redraw()