def testTransfers(self):
        # test fates
        cmap = fract4dc.cmap_create(
            [(0.0,33,33,33,255)])

        # make inner transfer func none
        fract4dc.cmap_set_transfer(cmap,1,0)
        
        # inside should be all-black by default, outside should never be
        index = 0.0
        while index < 2.0: 
            color = fract4dc.cmap_lookup_flags(cmap,index,0,1)
            self.assertEqual(color,(0,0,0,255))
            color = fract4dc.cmap_lookup_flags(cmap,index,0,0)
            self.assertEqual(color,(33,33,33,255))            
            index += 0.1

        # test setting solid colors and transfers
        fract4dc.cmap_set_solid(cmap,0,166,166,166,255)
        fract4dc.cmap_set_solid(cmap,1,177,177,177,255)
        fract4dc.cmap_set_transfer(cmap,0,0)
        
        index = 0.0
        while index < 2.0: 
            color = fract4dc.cmap_lookup_flags(cmap,index,0,1)
            self.assertEqual(color,(177,177,177,255))
            color = fract4dc.cmap_lookup_flags(cmap,index,0,0)
            self.assertEqual(color,(166,166,166,255))            
            index += 0.1

        # make inner linear
        fract4dc.cmap_set_transfer(cmap,1,1)

        index = 0.0
        while index < 2.0: 
            color = fract4dc.cmap_lookup_flags(cmap,index,0,1)
            self.assertEqual(color,(33,33,33,255))
            color = fract4dc.cmap_lookup_flags(cmap,index,0,0)
            self.assertEqual(color,(166,166,166,255))            
            index += 0.1

        # test that solid overrides
        color = fract4dc.cmap_lookup_flags(cmap,0.1,1,1)
        self.assertEqual(color,(177,177,177,255))
        color = fract4dc.cmap_lookup_flags(cmap,0.1,1,0)
        self.assertEqual(color,(166,166,166,255))
Beispiel #2
0
    def setUp(self):
        global g_comp
        self.compiler = g_comp

        self.f = fractal.T(self.compiler)
        self.f.render_type = 2
        self.f.set_formula("test.frm", "test_hypersphere")
        self.f.compile()

        handle = fract4dc.pf_load(self.f.outputfile)
        self.pfunc = fract4dc.pf_create(handle)
        self.cmap = fract4dc.cmap_create_gradient(self.f.get_gradient().segments)
        (r,g,b,a) = self.f.solids[0]
        fract4dc.cmap_set_solid(self.cmap,0,r,g,b,a)
        (r,g,b,a) = self.f.solids[1]
        fract4dc.cmap_set_solid(self.cmap,1,r,g,b,a)

        initparams = self.f.all_params()
        fract4dc.pf_init(self.pfunc,self.f.params,initparams)

        self.im = image.T(40,30)
        siteobj = FractalSite()
        
        self.fw = fract4dc.fw_create(
            1,self.pfunc,self.cmap,self.im._img,self.f.site)

        self.ff = fract4dc.ff_create(
            [0.0, 0.0, 0.0, 0.0,
             4.0,
             0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            2,
            100,
            0,
            1,
            self.pfunc,
            self.cmap,
            0,
            1,
            2, # 3D
            self.im._img,
            self.f.site,
            self.fw,
            False,
            1.0E-9)
Beispiel #3
0
    def setUp(self):
        global g_comp
        self.compiler = g_comp

        self.f = fractal.T(self.compiler)
        self.f.render_type = 2
        self.f.set_formula("test.frm", "test_hypersphere")
        self.f.compile()

        handle = fract4dc.pf_load(self.f.outputfile)
        self.pfunc = fract4dc.pf_create(handle)
        self.cmap = fract4dc.cmap_create_gradient(
            self.f.get_gradient().segments)
        (r, g, b, a) = self.f.solids[0]
        fract4dc.cmap_set_solid(self.cmap, 0, r, g, b, a)
        (r, g, b, a) = self.f.solids[1]
        fract4dc.cmap_set_solid(self.cmap, 1, r, g, b, a)

        initparams = self.f.all_params()
        fract4dc.pf_init(self.pfunc, self.f.params, initparams)

        self.im = image.T(40, 30)
        siteobj = FractalSite()

        self.fw = fract4dc.fw_create(1, self.pfunc, self.cmap, self.im._img,
                                     self.f.site)

        self.ff = fract4dc.ff_create(
            [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            2,
            100,
            0,
            1,
            self.pfunc,
            self.cmap,
            0,
            1,
            2,  # 3D
            self.im._img,
            self.f.site,
            self.fw,
            False,
            1.0E-9)
    def testFractWorker(self):
        xsize = 8
        ysize = 8
        im = image.T(xsize,ysize)
        
        cmap = fract4dc.cmap_create([(1.0, 255, 255, 255, 255)])

        fract4dc.cmap_set_solid(cmap,0,0,0,0,255)
        fract4dc.cmap_set_solid(cmap,1,0,0,0,255)
        
        (fw,ff,site,handle,pfunc) = self.makeWorkerAndFunc(im._img,cmap)

        im.clear()
        fate_buf = im.fate_buffer()
        buf = im.image_buffer() 
        
        # draw 1 pixel, check it's set properly
        fract4dc.fw_pixel(fw,0,0,1,1)
        self.assertPixelIs(im,0,0,[im.OUT]+[im.UNKNOWN]*3)

        fract4dc.fw_pixel(fw,0,4,1,1)
        self.assertPixelIs(im,0,4,[im.IN]+[im.UNKNOWN]*3)
        
        # draw it again, check no change.
        fract4dc.fw_pixel(fw,0,0,1,1)
        self.assertPixelIs(im,0,0,[im.OUT]+[im.UNKNOWN]*3)

        # draw & antialias another pixel
        fract4dc.fw_pixel(fw,2,2,1,1)
        fract4dc.fw_pixel_aa(fw,2,2)
        self.assertPixelIs(im,2,2,[im.OUT, im.OUT, im.IN, im.OUT])

        # change cmap, draw same pixel again, check color changes
        cmap = fract4dc.cmap_create(
            [(1.0, 79, 88, 41, 255)])
        fract4dc.cmap_set_solid(cmap,1,100,101,102,255)
        
        (fw,ff,site,handle,pfunc) = self.makeWorkerAndFunc(im._img,cmap)

        fract4dc.fw_pixel(fw,0,0,1,1)
        self.assertPixelIs(im,0,0,[im.OUT]+[im.UNKNOWN]*3, [79,88,41])

        # redraw antialiased pixel
        fract4dc.fw_pixel_aa(fw,2,2)
        self.assertPixelIs(
            im,2,2, [im.OUT, im.OUT, im.IN, im.OUT],
            [79,88,41], [100,101,102])

        # draw large block overlapping existing pixels
        fract4dc.fw_pixel(fw,0,0,4,4)
        self.assertPixelIs(
            im,0,0, [im.OUT, im.UNKNOWN, im.UNKNOWN, im.UNKNOWN],
            [79,88,41], [100,101,102])

        self.assertPixelIs(
            im,3,1, [im.UNKNOWN]*4,
            [79,88,41], [100,101,102], im.OUT)