Beispiel #1
0
import sys
import os
sys.path.append(os.getcwd()) 

import supershape

from math import sqrt
from math import sin, cos, radians

from pypaint.context        import Context
from pypaint.types.color    import Color
from pypaint.utils.p_random import random

ctx = Context(width=600, height=600)

def radial_gradient(colors, x, y, radius, steps=200):
    """ Radial gradient using the given list of colors. """
    def _step(colors, i, n):
        l = len(colors)-1
        a = int(1.0*i/n*l)
        a = min(a+0, l)
        b = min(a+1, l)
        base = 1.0 * n/l * a
        d = (i-base) / (n/l)
        r = colors[a].r*(1-d) + colors[b].r*d
        g = colors[a].g*(1-d) + colors[b].g*d
        b = colors[a].b*(1-d) + colors[b].b*d
        return Color(r, g, b)
 
    for i in range(steps):
        ctx.fill(_step(colors, i, steps))
Beispiel #2
0
    for i in _range(points):
        pt = path.point(float(i)/points)
        phi = i * range / points
        dx, dy = supercalc(m, n1, n2, n3, phi)
        if first:
            ctx.beginpath(pt.x+dx, pt.y+dy)
            first = False
        else:
            ctx.lineto(pt.x+dx, pt.y+dy)
    return ctx.endpath(draw=False)



if __name__ == "__main__":
    from pypaint.context import Context
    ctx = Context(width=400, height=400)

    def setup():    
        global x, y, w, h, m, n1, n2, n3, i
        
        x, y = 200, 200
        w, h = 100, 100
        m = 6.0
        n1 = 1.0
        n2 = 1.0
        n3 = 1.0
        i = 0.0

    def draw():
        global x, y, w, h, m, n1, n2, n3, i
        
Beispiel #3
0
from pypaint.context         import Context
from pypaint.types.canvas    import BezierPath
from pypaint.utils.p_random  import random

from math import pi, sin, cos, radians

ctx = Context(width=600, height=600)

class Tendril:
    def __init__(self, x, y, width=15):
        """ 
        A new sinewy tendril at location x and y.
        Its segment width will gradually become smaller as it grows.
        """

        self.x = x
        self.y = y
        self.width = width
        self.angle = random(2*pi) - pi ## random angle in radians.
        self.segments = []
        self.v = 0
 
    def grow(self, distance=3.0, curl=1.0, step=0.02):
        """ Tendril segment growth using fluid, spiral sine functions,
        taken from the ART+COM Tendrils class for Processing.
        """
        ## Think of a tendril having a steering compass.
        ## For each new segment, the compass shifts a bit left or right.
        self.x += cos(self.angle) * distance
        self.y += sin(self.angle) * distance
        self.v += random(-step, step)