Once more: plot a single point



  • Re: plot a single point how?

    Hi Frederik, thank you for your clever idea! But sadly to say there is no speed improvement. It is as slow as the oval statement. It is difficult to understand that there is no dedicated command to draw a point. A picture with other python implementations like Thonney Python or Processing Python shows a picture at once.
    So to speak it seems DrawBot is useless for making interesting Computer graphics pictures (Fractals for instance) without the usage of Turtle Graphics. Graphics in an x-y System needs two operations: to draw a point and to draw a line. What a pity that DrawBot is not able to do that ?
    Here is the example with your proposal:
    (As slow as the oval statement to draw a point)
    Best regards (kalle)

    xscreen = 640
    yscreen = 480
    
    newPage(xscreen,yscreen)
    
    def f(p, k) :
        fwert = p + k * p * (1 - p)
        return fwert
     
    def input():
        global left, right, bottom, top
        global invisible, visible
        left = 1.8
        right = 3.0
        bottom = 0.0
        top = 1.5
        invisible = 200
        visible = 200
        
    def setup():
        input()
        feigenbaumIteration()
        saveImage("~/Desktop/feigenbaum.png")
            
    def setglobalpoint(xw, yw):
        p = BezierPath()
        x = (xw - left) * xscreen / (right - left)
        y = (yw - bottom) * yscreen / (top - bottom)
        #oval(round(x),round(y),1,1)
        #these lines instead of command oval(round(x),round(y),1,1) 
        p.moveTo((x,y))
        p.lineTo((x,y))
        #strokeWidth(1)
        lineCap("round")
        stroke(0)
        drawPath(p)
    
        
    def feigenbaumIteration():
        deltaxPerPixel = (right - left) / xscreen
        for section in range(0, xscreen+1, 1):
            coupling = left + section * deltaxPerPixel
            population = 0.3
            for i in range(0, invisible+1, 1):
                population = f(population, coupling)
    
            for i in range(0, visible+1, 1):
                setglobalpoint(coupling, population)
                population = f(population, coupling)
                
        
    setup()
    
    

  • admin

    use a global path instead of a creating a new path each time...

    xscreen = 640
    yscreen = 480
    
    left = 1.8
    right = 3.0
    bottom = 0.0
    top = 1.5
    invisible = 200
    visible = 200
    
        
    newPage(xscreen,yscreen)
    dotPath = BezierPath()
    
    def f(p, k) :
        fwert = p + k * p * (1 - p)
        return fwert
    
    def setglobalpoint(xw, yw):    
        x = (xw - left) * xscreen / (right - left)
        y = (yw - bottom) * yscreen / (top - bottom)
        
        dotPath.moveTo((x,y))
        dotPath.lineTo((x,y))
    
        
    def feigenbaumIteration():
        deltaxPerPixel = (right - left) / xscreen
        for section in range(0, xscreen+1, 1):
            coupling = left + section * deltaxPerPixel
            population = 0.3
            for i in range(0, invisible+1, 1):
                population = f(population, coupling)
    
            for i in range(0, visible+1, 1):
                setglobalpoint(coupling, population)
                population = f(population, coupling)
                
        
    feigenbaumIteration()
    
    lineCap("round")
    stroke(0)
    drawPath(dotPath)
    
    saveImage("~/Desktop/feigenbaum.png")
    

    this is already a megalot faster...



  • @frederik
    Works...
    Great, thank you very much.
    The only thing is that the computer graphics is shown on the screen, but the saved picture on the desktop is empty ?



  • @frederik
    the solution of Fredrik is indeed megabit faster...
    In the meantime (yesterday) I found another fix by using the python pillow environment. It works even faster than the solution of Frederic. Anyway it is strange that Drawbot does not offer a simple plot(x,y) statement

    xscreen = 640
    yscreen = 480
    picname ="Feigenbaum.png"
    newPage(xscreen,yscreen)
    
    # Definitions for the pillow environment
    import math
    from PIL import Image, ImageDraw
    colour = (255, 255, 255) #white
    im = Image.new("RGB", (xscreen, yscreen), colour)
    draw = ImageDraw.Draw(im)
    # --------------------------------------
    
    def f(p, k) :
        fwert = p + k * p * (1 - p)
        return fwert
     
    def input():
        global left, right, bottom, top
        global invisible, visible
        left = 1.8
        right = 3.0
        bottom = 0.0
        top = 1.5
        invisible = 200
        visible = 200
        
    def setup():
        input()
        feigenbaumIteration()
        # Show picture and save picture pillow environment
        im.show()
        im.save(picname)
                
    def setglobalpoint(xw, yw):
        size = randint(1,1)
        middle = randint(-1,1)
        x = (xw - left) * xscreen / (right - left)
        y = (yw - bottom) * yscreen / (top - bottom)
        # point statement of pillow environment
        draw.point([(x, yscreen - y)], fill="black")
       
        
    def feigenbaumIteration():
        deltaxPerPixel = (right - left) / xscreen
        for section in range(0, xscreen+1, 1):
            coupling = left + section * deltaxPerPixel
            population = 0.3
            for i in range(0, invisible+1, 1):
                population = f(population, coupling)
            for i in range(0, visible+1, 1):
                setglobalpoint(coupling, population)
                population = f(population, coupling)
                
        
    setup()
    

Log in to reply