Esempio n. 1
0
File: bww.py Progetto: msarch/py
def draw(canvas):
    """ {{{ 
    - dessine en boucle 
    - Args : canvas (string)
    - Returns : none
    """ 

    stroke(White) # 75% transparent black.
    strokewidth(1)

    # random position, rect rotation, color and tranparency
    x1 = random()*canvas.width
    y1 = random()*canvas.height
        #
        #  | Y
        #  | 
        #  |
        #  |            X
        #  0 ------------
        #

    rot = int(random()*4)*90
    rndColor = color(random(),random(),random(),random())
        # You pass Color objects to fill() and stroke().
        # A Color object can be created with the color command.
        # It has clr.r, clr.g, clr.b, clr.a properties :
        #   clr = color(0.25, 0.15, 0.75, 0.5) # 50% transparent purple/blue.
        #   fill(clr)
        
    translate(x1,y1)
    rotate(rot)
    fill(rndColor)
    rect(0,0,rectWidth,rectHeight)
Esempio n. 2
0
def render(args):
    from nodebox.graphics import BezierPath, strokewidth, fill, directed, push, translate, rotate, pop, drawpath
    geom2d = getPropValue(args, 'inputs', 'geometry')

    # Do the drawing here!!
    path = BezierPath()
    strokewidth(width=1)
    fill(0)

    ps = geom2d.points
    for b_path in geom2d.bezier_paths:
        if len(b_path) > 4:
            path.moveto(*geom2d.points[b_path[0]])
            for p_num in xrange((len(b_path) - 1) // 3):
                # debugPrint b_path,p_num
                path.curveto(ps[b_path[p_num * 3 + 1]][0], ps[b_path[p_num * 3 + 1]][1], ps[b_path[p_num * 3 + 2]][0], ps[b_path[p_num * 3 + 2]][1]                             , ps[b_path[p_num * 3 + 3]][0], ps[b_path[p_num * 3 + 3]][1]
                             )

            #    points = path.points(amount=len(glyphs), start=0.05, end=0.95)
            points = path.points(amount=0, start=0.05, end=0.95)
            for angle, pt in directed(points):
                push()
                translate(pt.x, pt.y)
                rotate(angle)
                pop()
            drawpath(path, fill=None, stroke=(0, 0, 0, 1))
Esempio n. 3
0
File: bww.py Progetto: msarch/py
def draw(canvas):
    """ {{{ 
    - dessine en boucle 
    - Args : canvas (string)
    - Returns : none
    """

    stroke(White)  # 75% transparent black.
    strokewidth(1)

    # random position, rect rotation, color and tranparency
    x1 = random() * canvas.width
    y1 = random() * canvas.height
    #
    #  | Y
    #  |
    #  |
    #  |            X
    #  0 ------------
    #

    rot = int(random() * 4) * 90
    rndColor = color(random(), random(), random(), random())
    # You pass Color objects to fill() and stroke().
    # A Color object can be created with the color command.
    # It has clr.r, clr.g, clr.b, clr.a properties :
    #   clr = color(0.25, 0.15, 0.75, 0.5) # 50% transparent purple/blue.
    #   fill(clr)

    translate(x1, y1)
    rotate(rot)
    fill(rndColor)
    rect(0, 0, rectWidth, rectHeight)
Esempio n. 4
0
File: bww.py Progetto: msarch/py
def draw(canvas):

    canvas.clear()
    
    # dessin des rectangles du fond
    for item in rect_list:
        clr=color(float(item[4]),float(item[5]),float(item[6]),float(item[7]))
        stroke(clr)
        fill(clr)
        rect(int(item[0]),int(item[1]),int(item[2]),int(item[3]))
Esempio n. 5
0
def draw(canvas):

    canvas.clear()

    # dessin des rectangles du fond
    for item in rect_list:
        clr = color(float(item[4]), float(item[5]), float(item[6]),
                    float(item[7]))
        stroke(clr)
        fill(clr)
        rect(int(item[0]), int(item[1]), int(item[2]), int(item[3]))
Esempio n. 6
0
def draw(canvas):
    gr.background(1)
    gr.fill(0,0.75)
    psystem.update()
    #print psystem[0].position.array
    for particle in psystem:
        gr.push()
        gr.translate(particle.position.x,particle.position.y)
        #if particle.position.y < 0:
        #    particle.position.y = 1000.0
        #   particle.color = (np.random.random(),np.random.random(),np.random.random(),np.random.random())
        #print particle.force.x
        gr.ellipse(0,0,5.0,5.0,fill = (50/abs(particle.velocity),0.1,0.5,0.5))
        gr.pop()
Esempio n. 7
0
def draw(canvas):
    background(Red)
    xc = canvas.width / 2
    yc = canvas.height / 2
    stroke(White)  # 75% transparent black.
    strokewidth(1)
    triangle(xc, yc, xc + 50, yc + 100, xc + 100, yc)

    # While rect() and ellipse() expect x, y, width, height parameters,
    # triangle() expects the coordinates of three points,
    # which are connected into a triangle.

    # Clear the current stroke,
    # otherwise it is still active in the next frame
    # when we start drawing the rectangle and the ellipse.
    # nostroke()

    # You can also pass Color objects to fill() and stroke().
    # A Color object can be created with the color command.
    # It has clr.r, clr.g, clr.b, clr.a properties :
    #   clr = color(0.25, 0.15, 0.75, 0.5) # 50% transparent purple/blue.
    #   fill(clr)

    for i in range(10):
        dx = random() * 200.0
        dy = random() * 200.0
        xs = random() * 1.6
        ys = random() * 1.6
        dr = random() * 360.0
        translate(dx, dy)
        scale(xs, ys, 1)
        rotate(dr)
        fill(1, 1, 0.9, 0.1)

        for path in paths:
            # Use copies of the paths
            # that adhere to the transformations
            # (translate, scale, rotate) we defined.
            drawpath(path)
Esempio n. 8
0
def draw(canvas):
    background(Red)
    xc=canvas.width/2
    yc=canvas.height/2
    stroke(White) # 75% transparent black.
    strokewidth(1)
    triangle(xc, yc, xc+50, yc+100, xc+100, yc)

# While rect() and ellipse() expect x, y, width, height parameters,
    # triangle() expects the coordinates of three points,
    # which are connected into a triangle.

    # Clear the current stroke,
    # otherwise it is still active in the next frame
    # when we start drawing the rectangle and the ellipse.
    # nostroke()
   
    # You can also pass Color objects to fill() and stroke().
    # A Color object can be created with the color command.
    # It has clr.r, clr.g, clr.b, clr.a properties :
    #   clr = color(0.25, 0.15, 0.75, 0.5) # 50% transparent purple/blue.
    #   fill(clr)

    for i in range(10):
        dx=random()*200.0
        dy=random()*200.0
        xs=random()*1.6
        ys=random()*1.6
        dr=random()*360.0
        translate(dx,dy)
        scale(xs,ys,1)
        rotate(dr)
        fill(1, 1, 0.9, 0.1)

        for path in paths:
            # Use copies of the paths
            # that adhere to the transformations
            # (translate, scale, rotate) we defined.
            drawpath(path)
def draw(canvas):
    collect_sample()
    
    canvas.clear()

    first = samples[0][0]
    last = samples[-1][0]
    delta = last - first
    if delta == 0.0:
        return
    
    perpixel = HEIGHT / delta

    samps = []
    for (tm,rb) in samples:
        samps.append(rb / tm)

    max = samps[0]
    average = samps[0]
    for rb in samps[1:101]:
        #average = (average + rb) / 2.0
        average += rb
    for rb in samps:
        if rb > max:
            max = rb
    average = average / float(len(samps))
            
    for (tm,mn,mx,avg,stddev) in slowsamples:
        if avg > max:
            max = avg

    if max == 0:
        return

    xrng = float(max) / WIDTH
    nb.stroke(.5,0,0)
    nb.fill(1,0,0)
    y = HEIGHT
    samps.reverse()
    for rb in samps[:FIRST]:
        if rb != 0:
            x = (float(rb)/max) * WIDTH
            if x > WIDTH:
                print "ERR",x
            nb.stroke(1,0,0)
            nb.line(0, y, x, y)
            nb.stroke(0,0,0)
            nb.line(x-1, y, x, y)
        y = y - 1
#    path.lineto(0,y)
#    path.lineto(0,HEIGHT)
#    path.closepath()
#    nb.drawpath(path)

    nb.stroke(0,0,1)
    if False:
        x0 = 0
        for i in range(10,FIRST,10):
            if i >= len(samps):
                break
            avg = 0
            for x in range(i-10,i):
                avg = avg + samps[i]
            avg = avg / 10.0
            x1 = (avg/max) * WIDTH
            nb.line(x0, HEIGHT-i-10, x1, HEIGHT-i)
            x0 = x1
            
    else:
        x1 = (average/max) * WIDTH
        nb.line(x1, HEIGHT, x1, HEIGHT-100)
    

    i = 0
    rbtot = 0
    lasttm = tm

    if False:
        ## this plots a red bar +- one std-deviation with a black bar
        ## for the average
        y = HEIGHT - FIRST - len(slowsamples)
        for (tm,mn,mx,avg,stddev) in slowsamples:
            pxdev = (stddev/max) * WIDTH
            x0 = (float(avg)/max) * WIDTH
            nb.stroke(1,0,0)
            nb.line(x0-pxdev, y, x0+pxdev, y)
            nb.stroke(0,0,0)
            nb.line(x0-1,y,x0+1,y)
            y = y + 1

    elif False:
        ## this plots a red bar between min and max and a black dot for average
        ## (commented code does that, current does line from avg->max)
        y = HEIGHT - FIRST - len(slowsamples)
        for (tm,mn,mx,avg,stddev) in slowsamples:
            x0 = (float(mn)/max) * WIDTH
            x1 = (float(mx)/max) * WIDTH
            x2 = (float(avg)/max) * WIDTH
            nb.stroke(1,0,0)
            nb.line(x2, y, x1, y)
            #nb.stroke(0,0,0)
            #nb.line(x2-1,y,x2+1,y)
            y = y + 1

    elif True:
        ## this just plots the average
        y = HEIGHT - FIRST - len(slowsamples)
        for (tm,mn,mx,avg,stddev) in slowsamples:
            x = (float(avg)/max) * WIDTH
            nb.stroke(1,0,0)
            nb.line(0, y, x, y)
#            nb.stroke(0,0,0)
#            nb.line(x-1,y,x,y)
            y = y + 1

    nb.fontsize(10)
    
    for i in range(0,FIRST+1,50):
        nb.stroke(0,0,0,0.5)
        nb.line(0, HEIGHT-i, WIDTH-22, HEIGHT-i)
        t = nb.Text("%ds"%(i/10), WIDTH-20, HEIGHT-i-4)
        nb.stroke(0,1,0)
        t.draw()
        
    for i in range(FIRST+50,HEIGHT,50):
        nb.stroke(0,0,0,0.5)
        nb.line(0, HEIGHT-i, WIDTH-32, HEIGHT-i)
        t = nb.Text("%ds"%((FIRST/10)+((i-FIRST))), WIDTH-30, HEIGHT-i-4)
        nb.stroke(0,0,1)
        t.draw()

#    nb.fill(0,0,0,.8)
#    t = nb.Text("max: " + str(max), 0, HEIGHT-50)
#    t.fontweight = nb.BOLD
#    t.draw()

    nb.fill(0,0,1,.8)
    x1 = (average/max) * WIDTH
    average = int(average)
    avgtext = str(average/1024) + " KiB/s"
    t = nb.Text(avgtext, x1+2, HEIGHT-12)
    t.fontweight = nb.BOLD
    t.draw()