Thread: PyNode cookbook
View Single Post
T.K. T.K. is online now
Member
 
Join Date: Sep 2008
Posts: 148
Thank you blenderificus for the comments. Here is the PyNodes script I made.

Code:
from Blender import Node import math sqrt_2 = math.sqrt(2) class DotsNode(Node.Scripted): def __init__(self, sockets): radius = Node.Socket('radius', val=4*[1.0]) grid = Node.Socket('grid', val=10.0, min=1.0, max=100.0) fg_color = Node.Socket('fg_color', val=3*[0.0]+[1.0]) bg_color = Node.Socket('bg_color', val=4*[1.0]) color = Node.Socket('color', val=4*[1.0]) sockets.input = [radius, grid, fg_color, bg_color] sockets.output = [color] def nearest(self, coords, grid): """Return the nearest grid coordinate to coords.""" x, y = coords gx, mx = divmod(x, grid) gy, my = divmod(y, grid) x = gx * grid y = gy * grid if gx % 2 == gy % 2: if grid - mx > my: return x, y else: return x+grid, y+grid else: if mx > my: return x+grid, y else: return x, y+grid def __call__(self): input = self.input coords = [self.shi.pixel[0], self.shi.pixel[1]] grid = input.grid # pixels radius = (1.0 - input.radius[0]) * grid # Get the square distance from coords to nearest grid point nearest = self.nearest(coords, int(grid / sqrt_2)) sqdist = (coords[0]-nearest[0])**2 + (coords[1]-nearest[1])**2 # if sqdist is less than the scaled radius squared than color one if sqdist < radius**2: self.output.color = self.input.fg_color else: self.output.color = self.input.bg_color __node__ = DotsNode
I also uploaded the movie clip to Vimeo and added a new link to it to the last post.
IMHO the compression quality is not satisfactory. I will learn more how to upload
movie clips to Vimeo in a better quality.
#147   Old 16-Oct-08, 19:17   
Reply With Quote