def generate(self): """Generate random cases for the board.""" x, y = self.position sx, sy = self.size self.cases = [ Case([x, y - sy // 2], color=mycolors.random()) for y in range(sy) ]
def random(cls, size=(10, 10), ncases=10): """Create a random simple map.""" cases = [mycolors.random() for i in range(ncases)] w, h = size grid = [[random.randint(0, 9) for x in range(w)] for y in range(h)] grid = np.array(grid) return cls(grid, cases)
def setColors(self): """Set the colors of the functions.""" self.colors = [ mycolors.RED, mycolors.BLUE, mycolors.GREEN, mycolors.YELLOW, mycolors.PURPLE, mycolors.ORANGE, mycolors.BROWN ] self.colors += [ mycolors.random() for i in range(len(self.functions) - len(self.colors)) ][:len(self.functions)]
def random(cls, nf=3, np=5, nfp=3, **kwargs): """Create a random complex form.""" points = Form.random(n=np).points l = len(points) forms = [] for j in range(nf): f = Form([], area_color=mycolors.random(), fill=True) d = [] for i in range(nfp): d.append(random.randint(0, l - 1)) forms.append((d, f)) return cls(points, forms, **kwargs)
def random(cls, xmin=0, xmax=1, ymin=0, ymax=1, radiusmin=0, radiusmax=1, **kwargs): """Create a randomly initialized circle.""" center = [random.uniform(xmin, xmax), random.uniform(ymin, ymax)] radius = random.uniform(radiusmin, radiusmax) color = mycolors.random() return cls(center, radius, color=color, **kwargs)
def random(cls, na=5, sparse=1e10): """Create a random astre.""" c = "bcdfghjklmnpqrstvwxyz" v = "aeiou" def rd(n): return c[random.randint(0, len(c) - 1) ] if n % 2 == 0 else v[random.randint(0, len(v) - 1)] name = "".join([rd(i) for i in range(na)]) radius = random.uniform(0, 1) mass = random.uniform(1e20, 1e26) position = 1e12 * Vector.random() velocity = 1e6 * Vector.random() velocity.angle = (position.angle + math.pi / 2) % (2 * math.pi) acceleration = Vector.null() motion = Motion(position, velocity, acceleration) color = mycolors.random() return cls(name, radius, mass, motion, color)
def setRandomColor(self): """Set the color of the brush to a random color.""" self.color = mycolors.random()
def crossCircle(self,other): """Determine if two circles are crossing.""" vector=Vector.createFromTwoPoints(self.center,other.center) return vector.norm<self.radius+other.radius if __name__=="__main__": from mysurface import Surface from myzone import Zone from mywindow import Window surface=Surface(plane=Zone(),window=Window()) c1=Circle(4,2,2,color=mycolors.BLUE) c2=Circle(1,2,1,color=mycolors.BLUE) corners=[-1,-1,1,1] cs=[Circle.random(corners,color=mycolors.random()) for i in range(10)] fill=False c1_border_color=mycolors.random() c2_border_color=mycolors.random() c1_area_color=mycolors.random() c2_area_color=mycolors.random() while surface.open: surface.check() surface.control() surface.clear() surface.show() x,y=surface.point() c1.setPosition(x,y)
def random(cls, nm=1, nv=2, d=2): """Create a random asteroid.""" anatomy = Asteroid(color=mycolors.random(), conversion=False, radius=5) motions = [Motion.random(n=nv, d=d) for im in range(nm)] return cls(anatomy, motions)
x, y = position xmin, ymin, xmax, ymax = self.getCorners() return (xmin <= x <= xmax) and (ymin <= y <= ymax) center = property( getCenter, setCenter, "Allow the user to manipulate the center of the case easily.") if __name__ == "__main__": from mysurface import Surface from myzone import Zone #surface=Surface(plane=Zone(size=[20,20])) surface = Surface() cases = [ Case([x, y], color=mycolors.random(), fill=True) for x in range(-20, 20) for y in range(0, 20) ] cases = [ Case([x, y], color=mycolors.GREEN, fill=True) for x in range(8) for y in range(8) ] #cases=[] matrix = [[None for i in range(8)] for y in range(8)] for x in range(8): for y in range(8): matrix[x][y] = Case([x, y], color=mycolors.GREEN, fill=True) #case=Case([x,y],color=mycolors.GREEN,fill=True) #if x%8==0 or y%8==0: # case.color=mycolors.BLUE #cases.append(case)