Beispiel #1
0
    def make(self, n_dots, dot_radius, gap=0):
        """Make the cloud by randomly putting dots on it.

        Parameters
        ----------
        n_dots : int
            number of dots to put into the cloud
        dot_radius : int
            radius of the dots
        gap : int, optional
            gap between dots (default = 0)

        """

        top_left = dot_radius - self._radius
        bottom_right = self._radius - dot_radius
        remix = 0

        while(True): #remix-loop
            self._cloud = []
            remix = remix + 1
            reps = 0
            while(True): #find a solution
                dot = Dot(radius=dot_radius)
                expyriment.stimuli._stimulus.Stimulus._id_counter -= 1
                dot.position = (random.randint(top_left, bottom_right),
                                random.randint(top_left, bottom_right))
                reps = reps + 1

                if dot.is_inside(self.area):
                    if not self._is_overlapping_with_point(dot, gap):
                        self._cloud.append(dot)
                        reps = 0
                if reps > 10000:
                    break
                if len(self._cloud) >= n_dots:
                    self.clear_surface()
                    return True

            if remix > 10:
                message = "Dotcloud make: Cannot find a solution."
                print("Warning: ", message)
                if self._logging:
                    expyriment._active_exp._event_file_log(message)
                return False