canvas.insert now returns canvas wrapping item if attrs are given
[PyX.git] / design / palettetest.py
blob3fb0fd6a05dba49ce16307ce68688dd5411be1c0
1 #!/usr/bin/env python
2 # -*- coding: ISO-8859-15 -*-
3 import sys
4 sys.path.insert(0, "..")
6 import math
7 from math import *
8 from pyx import *
9 from pyx.graph import axis, data
11 # define some functions for the color values:
12 def red(x): return 2*x*(1-x)**5 + 3.5*x**2*(1-x)**3 + 2.1*x*x*(1-x)**2 + 3.0*x**3*(1-x)**2 + x**0.5*(1-(1-x)**2)
13 def green(x): return 1.5*x**2*(1-x)**3 - 0.8*x**3*(1-x)**2 + 2.0*x**4*(1-x) + x**4
14 def blue(x): return 5*x*(1-x)**5 - 0.5*x**2*(1-x)**3 + 0.3*x*x*(1-x)**2 + 5*x**3*(1-x)**2 + 0.5*x**6
16 # use the implemented converter for the grey value:
17 def grey(x): return color.rgb(red(x), green(x), blue(x)).grey().color["gray"]
19 # plot the color values
20 g = graph.graphxy(width=10, ratio=1)
21 g.plot(data.function("y(x)=red(x)", min=0, max=1, context=locals()), [graph.style.line([color.rgb.red])])
22 g.plot(data.function("y(x)=green(x)", min=0, max=1, context=locals()), [graph.style.line([color.rgb.green])])
23 g.plot(data.function("y(x)=blue(x)", min=0, max=1, context=locals()), [graph.style.line([color.rgb.blue])])
24 g.plot(data.function("y(x)=grey(x)", min=0, max=1, context=locals()))
26 # plot the colors
27 n = 200
28 x = 0
29 for i in range(n):
30 t = i * 1.0 / (n-1)
31 g.fill(path.rect(x, -2, 10.5/(n-1), 1), [color.rgb(red(t), green(t), blue(t))])
32 x += 10.0 / n
34 g.writeEPSfile("palettetest", paperformat=document.paperformat.A4)
35 g.writePDFfile("palettetest")