All pastes #477182 Raw Edit

jesterKing

public python v1 · immutable
·published 2007-05-08 14:33 UTC
rendered paste body
#!/usr/bin/env python# Jotain nodeimport Blenderimport Blender.Nodeimport Blender.Mathutils as muimport mathimport randomclass Halftone(Blender.Node.node):	def __init__(self, indef, outdef):		strength=[Blender.Node.VALUE, 0.08, 1.0, 1.0, 1.0, 0.0, 100.0]		clr=[Blender.Node.RGBA, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0]		color= ['color']		base= ['base']		outline_weight= ['outline']		color.extend(clr)		base.extend(clr)		outline_weight.extend(strength)		outline_weight[2]= 70.0		indef.definitions = [color, base, outline_weight]		outdef.definitions = [color]		random.seed(15042007)				def create_cross(amount):			white= (1.0, 1.0, 1.0, 0.0)			black= (0.0, 0.0, 0.0, 0.0)			cross= [[white for i in range(10)] for j in range(10)]			for i in range(amount):				x= int(random.uniform(0,9))#random.randint(0,9)				y= int(random.uniform(0,9))#random.randint(0,9)				cross[x][y] = black			return cross				self.cross= []				self.cross.append(create_cross(1))		self.cross.append(create_cross(5))		self.cross.append(create_cross(10))		self.cross.append(create_cross(20))		self.cross.append(create_cross(30))		self.cross.append(create_cross(50))				#print self.cross4	def __call__(self):		"""		the exec func		"""		def shade(x, y, level):			#crossname= "cross" + str(level)			#cross= im.Get(crossname)			black= (0.0, 0.0, 0.0, 0.0)			white= (1.0, 1.0, 1.0, 0.0)			x= x % 10			y= y % 10			pixel= (x, y)			col= white			if level==1:				col= self.cross[0][x][y]			elif level==2:				col= self.cross[0][x][y]				col= self.cross[1][x][y]			elif level==3:				#col= self.cross[0][x][y]				col= self.cross[1][x][y]				col= self.cross[2][x][y]			elif level==4:				#col= self.cross[0][x][y]				#col= self.cross[1][x][y]				col= self.cross[2][x][y]				col= self.cross[3][x][y]			elif level==5:				#col= self.cross[0][x][y]				#col= self.cross[1][x][y]				#col= self.cross[2][x][y]				col= self.cross[3][x][y]				col= self.cross[4][x][y]			elif level==6:				#col= self.cross[0][x][y]				#col= self.cross[1][x][y]				#col= self.cross[2][x][y]				#col= self.cross[3][x][y]				col= self.cross[4][x][y]				col= self.cross[5][x][y]			if col==black:				col= self.ins['color']			elif col==white:				col= self.ins['base']			return col				texcoord = self.shi.texture		pixel= self.shi.pixel		colr= self.ins['color']		col= colr		colvec= mu.Vector(colr)				col= self.ins['base']				shicolvec= mu.Vector(self.shi.color)		nVec = mu.Vector(1.0, 1.0, 1.0, 0.0)		shicollen= shicolvec.length / nVec.length		collen= colvec.length / nVec.length				vec1= mu.Vector(self.shi.surface_view_vec)		vec2= mu.Vector(self.shi.view_normal)		#print vec1, vec2		vangle=mu.AngleBetweenVecs(vec2, vec1)				colnormorig= collen / shicollen		if colnormorig<0.2:			col= shade(pixel[0], pixel[1], 6)		elif colnormorig<0.3:			col= shade(pixel[0], pixel[1], 5)		elif colnormorig<0.4:			col= shade(pixel[0], pixel[1], 4)		elif colnormorig<0.5:			col= shade(pixel[0], pixel[1], 3)		elif colnormorig<0.6:			col= shade(pixel[0], pixel[1], 2)		elif colnormorig<0.7:			col= shade(pixel[0], pixel[1], 1)		#elif colnormorig<0.8:		#	colnorm= 0.8		#elif colnormorig<0.9:		#	colnorm= 0.9		#else:		#	colnorm= 1.0		#newcol= (col[0] * colnorm, col[1] * colnorm, col[2] * colnorm, 0.0)		if vangle > self.ins['outline']:			col= self.ins['color']		self.outs['color'] = col