예제 #1
0
def test_cosine_vert():
    '''
    this test is testing the miniTopSim.py script
    the test is checking of the generate srf file has equal values to the srf_save file
    for verfing the test the methode distance() of surface.py is used
    '''
    distance_measure = 2.3
    simulation(os.path.join(filedir, 'cosine_vert_1.cfg'))
    surface1 = Surface(filename=os.path.join(filedir, 'cosine_vert_1.srf'))
    surface2 = Surface(
        filename=os.path.join(filedir, 'cosine_vert_05.srf_save'))
    distance = surface1.distance(surface2)
    assert distance < (distance_measure / 2)
예제 #2
0
def read_model(file_name, edges, vertices, surfaces):
    f = open(file_name)
    surface_id = 0
    for line in f.readlines():
        l = line.rstrip('\n').split(' ')
        flag = l[0]
        if flag == 'v':
            vertices.append((float(l[1]), float(l[2]), float(l[3])))
        elif flag == 'f':
            edges_list = l[1:]  # Edge list in string
            surface_edges = []
            for i in range(len(edges_list)):
                if i == len(edges_list) - 1:
                    edges.append((int(edges_list[i]), int(edges_list[0])))
                    surface_edges.append(
                        (int(edges_list[i]), int(edges_list[0])))
                else:
                    edges.append((int(edges_list[i]), int(edges_list[i + 1])))
                    surface_edges.append(
                        (int(edges_list[i]), int(edges_list[i + 1])))
            surface = Surface(surface_id, surface_edges)
            surfaces.append(surface)
            surface_id = surface_id + 1

    f.close()
예제 #3
0
    def __init__(self, width, height, channels, brightness=1):
        self.running = False
        self.width = width
        self.height = height
        self.channels = channels
        self.tbuf = TranslatedFrameBuffer()

        self.surface = Surface(width, height, channels, brightness)

        self.jobs = JobRunner()

        weatherFetcher = WeatherFetcher()
        newsApi = NewsApi()

        self.jobs.add(weatherFetcher.do)
        self.jobs.add(newsApi.do)

        self.apps = [
            App(News(newsApi), 0, 0),
            App(Weather(weatherFetcher), 0, 10),
            App(Clock(), 0, 20),
        ]

        self.rotator = Rotator(self.apps, 2 * second, 120 * second)
        self.timer = Timer(self.loop, 60)
 def arc(self, surface, color, rect, start_angle, stop_angle, width=1):
     """
     Draw arc shape, and returns bounding Rect.
     Argument include surface to draw, color, rect, start_angle, stop_angle.
     Optional width argument of outline.
     """
     if hasattr(rect, 'width'):
         _rect = rect
     else:
         _rect = Rect(rect)
     if _rect.width == _rect.height:
         surface.beginPath()
         surface.arc(_rect.x + int(_rect.width / 2),
                     _rect.y + int(_rect.height / 2), int(_rect.width / 2),
                     -start_angle, -stop_angle, True)
         if width:
             surface.setLineWidth(width)
             if hasattr(color, 'a'):
                 surface.setStrokeStyle(color)
             else:
                 surface.setStrokeStyle(Color(color))
             surface.stroke()
         else:
             surface.closePath()
             if hasattr(color, 'a'):
                 surface.setFillStyle(color)
             else:
                 surface.setFillStyle(Color(color))
             surface.fill()
     else:
         if _rect.width < _rect.height:
             dim = _rect.height
         else:
             dim = _rect.width
         surf = Surface((dim, dim))
         surf.beginPath()
         xdim = int(dim / 2)
         surf.arc(xdim, xdim, xdim, -start_angle, -stop_angle, True)
         if width:
             surf.setLineWidth(width)
             if hasattr(color, 'a'):
                 surface.setStrokeStyle(color)
             else:
                 surface.setStrokeStyle(Color(color))
             surf.stroke()
         else:
             surface.closePath()
             if hasattr(color, 'a'):
                 surface.setFillStyle(color)
             else:
                 surface.setFillStyle(Color(color))
             surf.fill()
         surface.drawImage(surf.canvas, 0, 0, dim, dim, _rect.x, _rect.y,
                           _rect.width, _rect.height)  #pyjs0.8 *.canvas
     if surface._display:
         return surface._display._surface_rect.clip(_rect)
     else:
         return surface.get_rect().clip(_rect)
예제 #5
0
 def make_surface(self, array):
     """
     Generates image pixels from array data.
     Argument array containing image data.
     Return Surface generated from array.
     """
     surface = Surface((array.__imagedata.width, array.__imagedata.height))
     self.blit_array(surface, array)
     return surface
예제 #6
0
def simulation(in_file):
    """
    Main simulation function. Calculates the progress one timestep at a time
    until the end time has been reached.
    """
    par.set_Parameters(os.path.abspath(in_file))
    init_sputtering()

    #splitting filename at position of the last point
    out_file, cfg_type = os.path.splitext(in_file)
    # if srf file exists, it has to be remove,
    # because you have to generate a new file with other possible values
    if os.path.exists(os.path.abspath('{}.srf'.format(out_file))):
        os.remove(os.path.abspath('{}.srf'.format(out_file)))

    t = 0.0
    total_time = par.TOTAL_TIME

    if par.INITIAL_SURFACE_FILE != None and par.INITIAL_SURFACE_FILE != '':
        surface = Surface(filename= os.path.join(os.path.dirname(in_file), \
                                                 par.INITIAL_SURFACE_FILE))
        total_time = total_time + 1

    else:
        #set x steps to step size of cfg file
        surface = Surface(par.DELTA_X)

    while t < total_time:

        surface.write(out_file, t)
        # Retrieve next possible timestep
        delta = advance.timestep(par.TIME_STEP, t, total_time)
        # Update surface values
        advance.advance(surface, par.TIME_STEP)
        t += delta

    if par.PLOT_SURFACE:
        if os.path.exists(os.path.abspath('{}.srf_save'.format(out_file))):
            pt.plot(os.path.abspath('{}.srf'.format(out_file)),
                    os.path.abspath('{}.srf_save'.format(out_file)))
            print('Start plot with srf_save file')
        else:
            pt.plot(os.path.abspath('{}.srf'.format(out_file)))
            print('Start plot without srf_save file')
예제 #7
0
    def __init__(self, level, **kwargs):
        super().__init__(**kwargs)

        self._level = level
        self._part = None
        self._s = Surface((20, 10))
        self._s.fill((255, 0, 0))

        self._input = Input(inputStream=self.getInputStream())
        self._input.set(pygame.KEYDOWN, self.createNew, pygame.K_f)
예제 #8
0
def test_redep_rect():
    surface = Surface()
    surface.x = [0, 0, 1, 2, 2]
    surface.y = [2, 1, 1, 1, 2]

    surface.calc_viewfactor()
    sputter_flux_redep = surface.viewfactor.sum(axis=0)
    temp = np.array([0.616, 0.314, 0.353, 0.314, 0.616])
    temp = temp.flatten()
    sputter_flux_redep = sputter_flux_redep.flatten()
    assert np.allclose(sputter_flux_redep, temp, rtol=0.01)
예제 #9
0
def test_redep_90deg():
    surface = Surface()
    surface.x = [1, 2, 3, 4, 5]
    surface.y = [2, 1, 0, 1, 2]

    surface.calc_viewfactor()
    sputter_flux_redep = surface.viewfactor.sum(axis=0)
    temp = np.array([0.177, 0.266, 0., 0.266, 0.177])
    temp = temp.flatten()
    sputter_flux_redep = sputter_flux_redep.flatten()
    assert np.allclose(sputter_flux_redep, temp, rtol=0.01)
 def convert_image(self, image):
     """
     Return the image as a Surface.
     """
     if env.canvas._isCanvas:
         img = image.getElement()
         surface = Surface((img.width, img.height))
         surface.drawImage(image, 0, 0)
     else:
         surface = Surf(image)
     return surface