# Extensions:2.4/Py/Nodes/Cookbook/Toon

< Extensions:2.4‎ | Py‎ | Nodes‎ | Cookbook

## Recipes

### Toon 1

Example output of Toon 1 node.[.blend]

This script produces simple toony surface. Adjust zmax and zmin for interesting results. Note that zmax > zmin. Else they are swapped.

```from math import log, hypot
from Blender import Node

class Toon1Node(Node.Scripted):
def __init__(self, sockets):
zmax = Node.Socket('Zmax', val=1.0, min=0.01, max=10.0)
zmin = Node.Socket('Zmin', val=0.5, min=0.01, max=10.0)

col = Node.Socket('Color', val = 4*[1.0])

sockets.input = [col, zmax, zmin]
sockets.output = [col]

def __call__(self):
view_normal = self.shi.viewNormal
max = self.input.Zmax
min = self.input.Zmin

if min >= max: min, max = max, min

# Basic idea from X-Toon. See http://artis.inrialpes.fr/Publications/2006/BTM06a/ .
D = 1.0- log(hypot(view_normal[0], view_normal[1])/min) / log(max/min)
self.output.Color = [x * D for x in self.input.Color]

__node__ = Toon1Node
```

### Toon 2

Example output of Toon 2 node.[.blend]

Another toon shader. This is focused more on detecting sharp edges in a rudimentary way.

```from Blender import Node

class Toon2Node(Node.Scripted):
def __init__(self, sockets):
col1 = Node.Socket('Color1', val = 4*[1.0])
col2 = Node.Socket('Color2', val = 4*[1.0])
threshold = Node.Socket('Threshold', val=0.5, min=0.0, max=1.0)

col = Node.Socket('Color', val = 4*[1.0])

sockets.input = [col1, col2, threshold]
sockets.output = [col]

def __call__(self):
self.output.Color = self.input.Color1

if self.shi.surfaceNormal[2] * self.shi.viewNormal[2] > self.input.Threshold:
self.output.Color = self.input.Color2

__node__ = Toon2Node
```