def __init__(self): self.baseColor = Color((1, 1, 1)) #white self.otherColor = Color((0, 0, 0)) #black self.ambientComp = 1.0 self.diffusComp = 0.6 self.specularComp = 0.4 self.checkSize = 2.5
class Colors(object): #This is a class that holds a list of colors. #To make a new color, name the color and type... #yellow=Color(255,255,0,255); """ YOU: Define any colors you want here and get their values by calling Ex)Colors.red.getColor(); """ red=Color(255,0,0,255); green=Color(0,255,0,255); blue=Color(0,0,255,255); white=Color(255,255,255,255); black=Color(0,0,0,255); def __init__(self): pass; def getRandomColor(self): """ Get a randomly generated color. """ return ColorUtilities.randomColor();
def __init__(self, fileName): f = open(fileName, 'r') x = f.readline().strip() if ('P3' != x): print('Exception') x = f.readline().strip() dimensions = x.split(' ') self.collumns = int(dimensions[0]) self.rows = int(dimensions[1]) self.colorSize = int(f.readline().strip()) print self.collumns print self.rows print self.colorSize print "" self.data = [[Color()] * self.collumns] * self.rows self.data = np.array(self.data) print np.shape(self.data) for i in range(self.rows): x = f.readline().strip().split(' ') for j in range(self.collumns): self.data[i][j] = Color(int(x[j * 3]), int(x[j * 3 + 1]), int(x[j * 3 + 2]))
def create_timed(self, blueprint): """ Create a Target that disappears after some time. """ attr = blueprint.attributes # WHEN SHOT AT # =================================================================== actions = [ self.actions[AC.REWARD], self.actions[AC.SPAWN], self.actions[AC.DESPAWN_GOOD] ] blueprint.events[TR.SHOT_AT] = actions[:] # WHEN TIMED OUT # =================================================================== actions = [ self.actions[AC.SPAWN], self.actions[AC.PENALTY], self.actions[AC.DESPAWN_BAD] ] blueprint.events[TR.TIME_EXPIRED] = actions[:] # COLOR # =================================================================== attr[AT.COLORS] = { 'frame': Color(rgb=Color.WHITE), 'bg': Color(rgb=Color.BLACK), 'text': random_text_color() } # INTERACTIONS # =================================================================== attr[AT.VALUE_STRATEGY] = ValueStrategy.RANDOM_BY_STRENGTH vc = ValueChanger() vc.strategy = RewardStrategy.TIME_LEFT strength = int(attr[AT.STRENGTH]) vc.stiff_value = max(1, 20 * (strength - 3) * (1 + strength / 10)) vc.base_value = 20 + strength * 10 vc.base_multiplier = 1 attr[AT.REWARD] = vc vc = ValueChanger() vc.strategy = PenaltyStrategy.HARD_SET vc.stiff_value = strength * strength * -1 vc.base_value = strength * -5 vc.base_multiplier = 1 attr[AT.PENALTY] = vc attr[AT.TIME_TO_EXPIRE] = (strength + 1) * 1500 # SPAWN # =================================================================== spawn_blueprint = TargetBlueprint() spawn_attr = spawn_blueprint.attributes spawn_attr[AT.TARGET_TYPE] = TargetType.TIMED spawn_attr[AT.STRENGTH] = min(attr[AT.STRENGTH] + STRENGTH_INCREASE, 9) spawn_attr[AT.POSITION] = attr[AT.POSITION] attr[AT.SPAWN_BLUEPRINT] = spawn_blueprint return blueprint
def wheel(self, pos): if pos < 85: return Color(pos * 3, 255 - pos * 3, 0) elif pos < 170: pos -= 85 return Color(255 - pos * 3, 0, pos * 3) else: pos -= 170 return Color(0, pos * 3, 255 - pos * 3)
def test_should_apply_opacity_case1(self): bg_color = Color(rgb=Color.BLACK) color1 = Color(rgb=(100, 50, 200)) opacity = 0.5 self.assertEqual( color1.apply_opacity(bg_color, opacity).to_tuple(), (50, 25, 100)) opacity = 0.25 self.assertEqual( color1.apply_opacity(bg_color, opacity).to_tuple(), (25, 12, 50))
def test_should_raise_error_on_wrong_rgb_tuple_arguments(self): with self.assertRaises(ValueError): test_var = Color(rgb=(-1, 13, 14)) with self.assertRaises(ValueError): test_var = Color(rgb=(256, 13, 14)) with self.assertRaises(ValueError): test_var = Color(rgb=(13, 14)) with self.assertRaises(ValueError): test_var = Color(rgb=(12, 13, 14, 15))
def test_paint_fill_nine_point_one_color(self): before_screen = Screen(3, 3, Color(0, 0, 0)) after_screen = Screen(3, 3, Color(255, 255, 255)) recursive_paint_fill_strategy = RecursivePaintFillStrategy( before_screen, Point(0, 0), Color(255, 255, 255)) recursive_paint_fill_strategy.paint_fill() self.assertEqual(str(after_screen), str(before_screen))
def initialize(app, params): # Set GPIO pins for R, G, B wires params["PIN_R"] = 17 params["PIN_G"] = 22 params["PIN_B"] = 24 # Create Actions # Basic Colors actionWhite = app.addAction(ActionColor(params)) actionBlue = app.addAction(ActionColor(params, Color(0, 0, 255))) actionGreen = app.addAction(ActionColor(params, Color(0, 255, 0))) actionRed = app.addAction(ActionColor(params, Color(255, 0, 0))) #Ryan Added actionColorTrigger = app.addAction( ActionColorTrigger(params, Color(0, 0, 255), 100, 100, 100)) #Existing Actions actionStrobe = app.addAction(ActionStrobe(params)) actionStrobeMute = app.addAction(ActionStrobeMute(params)) actionMute = app.addAction(ActionMute(params)) actionChaos = app.addAction(ActionChaos(params)) # Bind Inputs to Actions # Knob app.addInput(actionStrobe, "knob", 1, "Speed") app.addInput(actionStrobe, "knob", 2, "Intensity") app.addInput(actionStrobeMute, "knob", 3, "Mute") app.addInput(actionStrobeMute, "knob", 4, "Speed") app.addInput(actionBlue, "knob", 5, "Intensity") app.addInput(actionGreen, "knob", 6, "Intensity") # app.addInput(actionRed, "knob", 7, "Intensity") # app.addInput(actionWhite, "knob", 8, "Intensity") app.addInput(actionColorTrigger, "knob", 7, "Sustain") app.addInput(actionColorTrigger, "knob", 8, "Release") # Trigger Hold app.addInput(actionColorTrigger, "trigger_hold", 38, "Sustain") # COMMENT 2 # app.addInput(actionMute, "hold", 45, "On") # app.addInput(actionChaos, "hold", 44, "Intensity") # app.addInput(actionWhite, "hold", 46, "Intensity") # app.addInput(actionStrobeMute, "hold", 47, "On") # app.addInput(actionStrobeMute, "knob", 10, "Speed") # Use ActionBuilder (optional) ActionBuilder.buildKeys(app, 48, 72, Color.red(), Color.blue(), attack=50, sustain=100, release=50)
def setup(self): """ Initialize the GUI and place it properly. """ # Create the main menu font. WELCOME_FONT_TITLE = pygame.font.SysFont('Consolas', 28) WELCOME_FONT_INSTRUCTIONS = pygame.font.SysFont('Consolas', 20) # Create the title display. self.title_display = Gui.DisplayableText(value='num.type', font=WELCOME_FONT_TITLE, color=Color(rgb=Color.WHITE), align='cc') self.title_display.set_position(640 / 2, 40) self.add_gui(self.title_display) self.title_colors = [ Color(rgb=(200, 20, 20)), Color(rgb=(200, 200, 20)), Color(rgb=(20, 200, 20)), Color(rgb=(20, 200, 200)), Color(rgb=(20, 20, 200)), Color(rgb=(200, 20, 200)) ] self.title_color_current = 0 self.title_color_next = 1 self.title_color_current_began_at = get_ticks() # Create the subtitle display. self.subtitle_display = Gui.DisplayableText( value='a numerical typing game', font=WELCOME_FONT_TITLE, color=Color(rgb=Color.WHITE), align='cc') self.subtitle_display.set_position(640 / 2, 70) self.add_gui(self.subtitle_display) self.subtitle_color_current = 1 self.subtitle_color_next = 2 # Create the instructions display. self.instr_displays = [] instructions = [ 'Attempt to type in numbers as fast as you can.', 'You can only use the numeric keyboard.', 'Every time you "shoot" a target in time, it will grant', 'you points.', 'Every time you miss, you will lose one heart,', 'so type carefully.', 'You can use backspace if you mistype.', 'If a target times out, you will lose points.', 'The game will become progressively harder as you play.', 'Win by accumulating {} points.'.format(VICTORY_POINTS), 'Lose by going below 0 points or losing all hearts.', '', 'Press ENTER to begin.', 'Pressing ESCAPE at any time will end the game in defeat.', 'Good luck!' ] for instruction in instructions: new_display = Gui.DisplayableText(value=instruction, font=WELCOME_FONT_INSTRUCTIONS, color=Color(rgb=Color.WHITE), align='lc') new_display.set_position(20, 120 + 23 * len(self.instr_displays)) self.instr_displays.append(new_display) self.add_gui(new_display)
def test_should_apply_opacity_case2(self): bg_color = Color(rgb=(100, 100, 100)) color1 = Color(rgb=(100, 60, 30)) opacity = 0.5 self.assertEqual( color1.apply_opacity(bg_color, opacity).to_tuple(), (100, 80, 65)) print(bg_color.to_tuple()) print(color1.to_tuple()) opacity = 0.75 self.assertEqual( color1.apply_opacity(bg_color, opacity).to_tuple(), (100, 70, 48))
def __init__(self, x=0, y=0, width=1, height=1): """ Set initial values for the instance. """ self.width = width self.height = height self.x = x self.y = y self.colors = { 'frame': Color(rgb=Color.WHITE), 'bg': Color(rgb=Color.BLACK), 'text': Color(rgb=Color.WHITE) } self.frame_width = 3
def numTramas(self): if self.numColores == 2: indice = 16 elif self.numColores == 4: indice = 8 else: indice = 6 matriz = self.frame[2 * self.tamCelda:(2 + self.tamanoMatriz) * self.tamCelda, 2 * self.tamCelda:(2 + self.tamanoMatriz) * self.tamCelda] #cv2.imshow('',matriz) coloresR1 = self.coloresReferencia[0:self.numColores, 0:] coloresR2 = self.coloresReferencia[self.numColores:2 * self.numColores, 0:] coloresR3 = self.coloresReferencia[2 * self.numColores:, 0:] arregloColores = np.zeros((indice), np.uint8) aux = 0 img = np.zeros((512, 512, 3), np.uint8) x = 0 for f in range(self.tamanoMatriz): for c in range(self.tamanoMatriz): if x == indice: return arregloColores celda = matriz[f * self.tamCelda:(f + 1) * self.tamCelda, c * self.tamCelda:(c + 1) * self.tamCelda] if (f == 0 and c == 0) or (f == 0 and c == self.tamanoMatriz - 1) or (f == self.tamanoMatriz - 1 and c == self.tamanoMatriz - 1): d = 1 else: x += 1 if f < (self.tamanoMatriz / 2) + 2 and c < (self.tamanoMatriz / 2) + 1: colorC = Color(celda) colorCelda = colorC.colorDominante() arregloColores[aux] = self.color(colorCelda, coloresR1) elif f < (self.tamanoMatriz / 2) + 2 and c >= (self.tamanoMatriz / 2) + 1: colorC = Color(celda) colorCelda = colorC.colorDominante() arregloColores[aux] = self.color(colorCelda, coloresR1) else: colorC = Color(celda) colorCelda = colorC.colorDominante() arregloColores[aux] = self.color(colorCelda, coloresR1) aux = aux + 1 return arregloColores
def get_bot_front(): max_area = 0 min_area = 10000 colorName = "front" upperColor = Color(colorName, 1) lowerColor = Color(colorName, 0) list_of_points = [] Frame.capture_frame() resized = Frame.cut ratio = 1 hsv = cv2.cvtColor(resized, cv2.COLOR_BGR2HSV) #t = cv2.getTrackbarPos('t','img') mask = cv2.inRange(hsv, lowerColor.get_array(), upperColor.get_array()) res = cv2.bitwise_and(resized, resized, mask=mask) gray = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY) blurred = cv2.GaussianBlur(gray, (5, 5), 0) T = mahotas.thresholding.otsu(blurred) b = blurred.copy() b[b > T] = 255 b[b < 255] = 0 cnts = cv2.findContours(b, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) cnts = cnts[0] if imutils.is_cv2() else cnts[1] area = 0 cX = 0 cY = 0 for c in cnts: M = cv2.moments(c) if M["m00"] > 0: cX = int((M["m10"] / M["m00"] + 1e-7) * ratio) cY = int((M["m01"] / M["m00"] + 1e-7) * ratio) #shape = sd.detect(c) c = c.astype("float") c *= ratio c = c.astype("int") area = cv2.contourArea(c) #rad = getRadFromArea(area) if area > 300: #cv2.drawContours(resized, [c], -1, (255,0,0), 2) list_of_points.append((cX, cY)) if len(list_of_points) > 0: bot_front = list_of_points[0] return bot_front else: return Bot.get_bot_front()
def GetSMPStatus(Beam): if Beam == "Beam 1": colors = list() img = getImage( "https://vistar-capture.web.cern.ch/vistar-capture/lhc1.png") rgb_img = img.convert('RGB') coords = [ (872, 572), #Stable Beams (872, 600), #Moveable Devices Allowed In (872, 629), #Beam Presence (872, 658), #Setup Beam (872, 686), #Global Beam Permit (872, 715) #Link Status of Beam Permits ] colors += [Color(*rgb_img.getpixel((xy))) for xy in coords] if colors[5].g == 255: del colors[3] #if in stable beams remove the setup flag elif len(colors) == 6 & colors[3].g == 255: del colors[5] #if in setup remove the stable beams flag for color in colors: if color.r == 255: print("There is a fault with Beam 1's SMP status") return print("Beam 1's SMP status is good.") elif Beam == "Beam 2": colors = list() img = getImage( "https://vistar-capture.web.cern.ch/vistar-capture/lhc1.png") rgb_img = img.convert('RGB') coords = [ (945, 572), #Stable Beams (945, 600), #Moveable Devices Allowed in (945, 629), #Beam Presence (945, 658), #Setup Beam (945, 686), #Global Beam Permit (945, 715) #Link Status of Beam Permits ] colors += [Color(*rgb_img.getpixel((xy))) for xy in coords] if colors[5].g == 255: del colors[3] #if in stable beams remove the setup flag elif len(colors) == 6 & colors[3].g == 255: del colors[5] #if in setup remove the stable beams flag for color in colors: if color.r == 255: print("There is a fault with Beam 2's SMP status") return print("Beam 2's SMP status is good.")
def test_paint_fill_one_point_one_color(self): """BUILD-OPERATE-TEST pattern used.""" # Build before_screen = Screen(1, 1, Color(0, 0, 0)) after_screen = Screen(1, 1, Color(255, 255, 255)) recursive_paint_fill_strategy = RecursivePaintFillStrategy( before_screen, Point(0, 0), Color(255, 255, 255)) # Operate recursive_paint_fill_strategy.paint_fill() # Test self.assertEqual(str(after_screen), str(before_screen))
def despawn_good(self, requestor): """ Mark a shot Target as garbage and display its dying animation. """ requestor.attributes[AT.GARBAGE] = True blueprint = TargetBlueprint() attr = blueprint.attributes attr[AT.TARGET_TYPE] = TargetType.DYING_ANIMATION attr[AT.VALUE] = requestor.attributes[AT.REWARD].display attr[AT.COLORS] = { 'frame': Color(rgb=Color.BLACK), 'bg': requestor.colors['text'], 'text': Color(rgb=Color.BLACK) } attr[AT.POSITION] = requestor.attributes[AT.POSITION] self.target_factory.create(blueprint)
def rotar(self): colores = np.ones((4, 3)) inicio = int(self.tamMatriz - (self.numColores / 2)) + 1 celda1 = self.image[0:self.tamCelda, 2 * self.tamCelda:3 * self.tamCelda] color1 = Color(celda1) colores[0, :] = color1.colorDominante() celda2 = self.image[2 * self.tamCelda:3 * self.tamCelda, (self.tamMatriz + 3) * self.tamCelda:(self.tamMatriz + 4) * self.tamCelda] color2 = Color(celda2) colores[1, :] = color2.colorDominante() celda3 = self.image[(self.tamMatriz + 3) * self.tamCelda:(self.tamMatriz + 4) * self.tamCelda, -3 * self.tamCelda:-2 * self.tamCelda] color3 = Color(celda3) colores[2, :] = color3.colorDominante() celda4 = self.image[-3 * self.tamCelda:-2 * self.tamCelda, 0:self.tamCelda] color4 = Color(celda4) colores[3, :] = color4.colorDominante() #Calcular distancias negro = [0, 0, 0] distanciaMenor = 10000 for i in range(4): color = colores[i, :] distancia = math.sqrt((color[0] - negro[0])**2 + (color[1] - negro[1])**2 + (color[2] - negro[2])**2) if distancia < distanciaMenor: distanciaMenor = distancia indice = i indicadores = np.ones((4), dtype=int) indicadores[indice] = 0 if np.array_equal(indicadores, np.array([0, 1, 1, 1], dtype=int)): imageRotada = self.rotateImage(self.image, 90) elif np.array_equal(indicadores, np.array([1, 0, 1, 1], dtype=int)): imageRotada = self.rotateImage(self.image, 180) elif np.array_equal(indicadores, np.array([1, 1, 0, 1], dtype=int)): imageRotada = self.rotateImage(self.image, -90) else: imageRotada = self.image return imageRotada
def getCheckerImage(cls,ImageSize,sqSize): from math import floor nx = ImageSize/sqSize ny = ImageSize/sqSize colors = [] for i in range (ImageSize): row = [] for j in range(int(nx)): for px in range(sqSize): if((floor(i/sqSize)+j)%2): row.append(Color(1,1,1)) else: row.append(Color(0,0,0)) colors.append(row) return cls(ImageSize,ImageSize,colors)
def despawn_bad(self, requestor): """ Mark a timed-out Target as garbage and display its dying animation. """ self.owner.score_keeper.targets_timed_out += 1 requestor.attributes[AT.GARBAGE] = True blueprint = TargetBlueprint() attr = blueprint.attributes attr[AT.TARGET_TYPE] = TargetType.DYING_ANIMATION attr[AT.VALUE] = requestor.attributes[AT.PENALTY].display attr[AT.COLORS] = { 'frame': Color(rgb=Color.RED), 'bg': Color(rgb=(120, 0, 0)), 'text': Color(rgb=Color.RED) } attr[AT.POSITION] = requestor.attributes[AT.POSITION] self.target_factory.create(blueprint)
def test_paint_fill_nine_points_two_colors(self): before_screen = Screen(3, 3, Color(0, 0, 0)) after_screen = Screen(3, 3, Color(0, 0, 0)) for row in range(2): for column in range(2): before_screen.set_color_at_point(Point(row, column), Color(128, 128, 128)) after_screen.set_color_at_point(Point(row, column), Color(255, 255, 255)) recursive_paint_fill_strategy = RecursivePaintFillStrategy( before_screen, Point(0, 0), Color(255, 255, 255)) recursive_paint_fill_strategy.paint_fill() self.assertEqual(str(after_screen), str(before_screen))
def addfile(self, filename, label, color = None, **kparams): """ Adds a file to the fetching list. :param filename: File name to be added to list. :param label: Label given to data presented from this file. :param color: Color to be given to data presented from this file. :return bool: Could the file be added? """ filename = self.root + filename.lstrip('/\\') if not os.path.isfile(filename): return False if color is None: color = Graphic.colors[len(self.source) % 8] elif not isinstance(color, Color): color = Color(*color) if 'lw' not in kparams.keys(): kparams['lw'] = 2 self.source.append(type('fileinfo', (object,), { 'path': filename, 'label': label, 'color': color, 'param': kparams })) return True
def getRef1(cls,ray,p,obj,scene,factor,color): # print("Call : ",factor) if(factor<0.25): return color if isinstance(obj,Triangle): normal = obj.normal elif isinstance(obj,Sphere): normal = p - obj.center normal=normal.normalize() d = p-ray.a reflectionRay = Ray(p,d - (normal*d.dot(normal)*2)) tminRef, closestObjRef = Utility.getClosestIntersection(reflectionRay,scene,0.001) diffuseRef=0 specularRef=0 rRef=0 pRef=None if not closestObjRef==None : for light in scene.lights: pRef = reflectionRay.a + reflectionRay.b*tminRef lightDistance=Vector.distance(pRef,light.position) lrspecular,lrdiffuse = Utility.shading(pRef,closestObjRef,reflectionRay,scene,light) specularRef+=lrspecular*(light.intensity**0.001) diffuseRef+=light.intensity*lrdiffuse/(lightDistance**2) rRef=closestObjRef.getTexture(pRef)*diffuseRef + Color(1,1,1)*(specularRef)*closestObjRef.specularFactor + closestObjRef.getTexture(pRef)*scene.ambient color= rRef*factor + color return cls.getRef1(reflectionRay,pRef,closestObjRef,scene,closestObjRef.reflectionFactor*0.8,color) return color
def setPixelAlphasFromIntsRandom(image, ints): """ Encrypt the message into the image's alpha values starting in a random order. """ cleanImage(image) pixelData = list(image.getdata()) length = len(ints) rand = int(len(pixelData) / length) position = 0 randomPosition = [] for i in range(length): value = random.randint(position, (rand - 1) + position) randomPosition.append(value) position += value - position for x in range(len(ints)): r = 0 g = 0 b = 0 a = 0 try: r, g, b, a = pixelData[randomPosition[x]] except: r, g, b = pixelData[randomPosition[x]] a = 255 color = Color(r, g, b, a) color.alpha = ints[x] pixelData[randomPosition[x]] = color.getColor() image.putdata(pixelData)
def __init__(self, n): self.n = n self.size = Hexagon.size self.width = self.size self.height = self.size * 3 // 4 # 正六角形の左下の頂点から反時計回りに座標を取得する際のオフセット self.vertexes_offset = [[0, 0], [self.width // 3, 0], [self.width * 2 // 3, -self.height // 2], [self.width // 3, -self.height], [0, -self.height], [-self.width // 3, -self.height // 2]] self.hexagons = [] self.rank = [] self.coordinate_offset = [[1, 1], [1, 0], [0, -1], [-1, -1], [-1, 0], [0, 1]] self.vertex_index = {} colors = Color(n) k = self.n - 1 l = 0 ct = 0 for i in range(2 * n - 1): # x成分 if i < n: k += 1 else: l += 1 for j in range(l, k): # y成分 if i == 0 or i == 2 * n - 2 or j == 0 or j == 2 * n - 2 or j == l or j == k - 1: self.hexagons.append(Hexagon(i, j, Color.WALL_COLOR, True)) else: self.hexagons.append( Hexagon(i, j, colors.get_color(), False)) self.vertex_index[(i, j)] = ct ct += 1
def initialize(app, params): # Set GPIO pins for R, G, B wires params["PIN_R"] = 17 params["PIN_G"] = 22 params["PIN_B"] = 24 # Create Actions actionWhite = app.addAction(ActionColor(params)) actionBlue = app.addAction(ActionColor(params, Color(0, 0, 255))) actionStrobe = app.addAction(ActionStrobe(params)) actionStrobeMute = app.addAction(ActionStrobeMute(params)) actionMute = app.addAction(ActionMute(params)) actionChaos = app.addAction(ActionChaos(params)) # Bind Inputs to Actions app.addInput(actionMute, "hold", 45, "On") app.addInput(actionChaos, "hold", 44, "Intensity") app.addInput(actionWhite, "hold", 46, "Intensity") app.addInput(actionStrobeMute, "hold", 47, "On") app.addInput(actionBlue, "knob", 3, "Intensity") app.addInput(actionStrobe, "knob", 7, "Intensity") app.addInput(actionStrobe, "knob", 8, "Speed") app.addInput(actionStrobeMute, "knob", 10, "Speed") # Use ActionBuilder (optional) ActionBuilder.buildKeys(app, 48, 72, Color.red(), Color.blue())
def calculateColor(self, lightColor, environmentColor, objColor, raylight_direction, ray_direction, hitPointNormale, point=None): if isinstance(objColor, CheckerBoardMaterial): objColor = objColor.baseColorAt( point ) # wenn obj instance von CheckerBoardMaterial: color = baseColorAt ambientColor = self.calculateAmbientColor(objColor, environmentColor) diffColor = self.calculateDiffusColor(objColor, lightColor, raylight_direction, hitPointNormale) specularColor = self.calculateSpecularColor(objColor, lightColor, ray_direction, raylight_direction, hitPointNormale) result_color_vector = ambientColor + specularColor + diffColor # sum farbwerte return Color((result_color_vector.x, result_color_vector.y, result_color_vector.z))
def test_should_correct_minimum_average(self): # given color_low_average = Color(rgb=(20, 20, 20)) # when color_low_average.correct_minimum_average(60) # then self.assertGreaterEqual(color_low_average.sum(), 60)
def __init__(self, master, *ap, **an): """Инициализация с параметрами по умолчанию: круглая кисть; случайная палитра; константная функция масштаба; 8 симметричных отображений""" Canvas.__init__(self, master, *ap, **an) self.fig_size = START_FIGURE_SIZE self.fig_type = 'circle' # None в color_pick означает, что будет выбираться автоматически self.color_pick = None # стартовый цвет self.color = Color() # привязки функций-обработчиков self.binding_functions() # загрузка палитры self.color.define_palette(-1) # выбор функции масштаба self.set_scale_function("constant") # число симметричных отображений self.num_symm = 16 # история - список из HistoryRecord self.history = [] # время (каждый клик мышкой увеличивает время на 1) self.time = 0 self.recalculate_coefficients()
def __init__(self, W, H, color=Color(0, 0, 0)): self.width = W self.height = H self.MAX_COLOR_NUMBER = 255 self.screen = [[ str(color * self.MAX_COLOR_NUMBER) for w in range(self.width) ] for h in range(self.height)]