def __init__(self): self.colors = Colors() self.color = colorama.Fore.GREEN self.interfaces = netifaces.interfaces() self.routers = netifaces.gateways() self.netmask = None self.network = None self.interface = None self.ip = None self.mac = None self.router = None self.country = None self.city = None self.lat = None self.lng = None self.region = None self.target = None self.ipTarget = None self.countryTarget = None self.cityTarget = None self.regionTarget = None self.latTarget = None self.lngTarget = None self.run = True self.ips = [] self.macs = [] self.os = [] self.public = None
def calculateRoomColor(self, currentCoord): colorsClass = Colors() result = colorsClass.SPECIAL logging.debug("JEFF Current: %s, %s, %s", str(currentCoord.x), str(currentCoord.y), str(currentCoord.z)) excludeColors = [] for index, coord in enumerate(self.adjacentCoords): adjacentCoord = Coord(currentCoord.x, currentCoord.y, currentCoord.z) adjacentCoord.x += coord.x adjacentCoord.y += coord.y adjacentCoord.z += coord.z logging.debug("JEFF adj: %s, %s, %s", str(adjacentCoord.x), str(adjacentCoord.y), str(adjacentCoord.z)) room = self.getRoom(adjacentCoord) if (room != None): logging.debug('JEFF Found ROOM!') if (room.color == None): room.color = colorsClass.getRandomColor() if (room.color not in excludeColors): excludeColors.append(room.color) if (len(excludeColors) > 0): result = colorsClass.getRandomColor(excludeColors) return result
def __init__(self, grass, props): GrassAnimation.__init__(self, grass, props) self.effects = [] self.on_time_percent = 0.5 self.hue = 0.33 self.pixel_hue = 0.7 self.brightness = 1.0 if self.props != None: if 'on_time_percent' in self.props: self.on_time_percent = self.props['on_time_percent'] if 'hue_start' in self.props: self.hue = self.props['hue_start'] if 'pixel_hue' in self.props: self.pixel_hue = self.props['pixel_hue'] if 'brightness' in self.props: self.brightness = self.props['brightness'] max_height = 0 for leaf in self.grass.get_leaves_array(): max_height = max(max_height, len(leaf[0])) max_height = max(max_height, len(leaf[1])) for leaf in self.grass.get_leaves_array(): rand_leaf_color = Colors.hls_to_rgb( self.hue, random.uniform(0.6, 1), random.uniform(0.2, self.brightness)) pixel_color = Colors.hls_to_rgb(self.pixel_hue, 1.0, 1.0) self.effects.append( SinglePixelEffect(leaf[0], rand_leaf_color, pixel_color, max_height * (1 + self.on_time_percent))) self.effects.append( SinglePixelEffect(leaf[1][::-1], rand_leaf_color, pixel_color, max_height * (1 + self.on_time_percent)))
def apply(self, time_percent): for i in range(0, self.grass.num_of_leaves()): leaf = self.grass.get_leaves_array()[i] loc = self.grass.leaf_loc_percent(i) c = self.timed_color.get_color(time_percent, loc) brightness = self.loc_to_brightness(time_percent, loc) * self.global_brightness(time_percent) c = Colors.change_rgb_lightness(c, Colors.fix_lightness_percent(brightness)) AlwaysOnEffect(leaf[0] + leaf[1], c).apply(time_percent, self.grass.get_array())
class Target: def __init__(self): self.hostname = None self.ip = None self.country = None self.region = None self.city = None self.lat = None self.lng = None self.colors = Colors() def getResumeTarget(self): self.colors.print_random_color('[INFO TARGET HOST]\r\n') resume = self.getDetailsTarget() if self.ip is not None : print('PUBLIC IP: '+str(self.ip)) if resume[0] is not None : print('COUNTRY: '+resume[0]) if resume[1] is not None : print('CITY: '+resume[1]) if resume[2] is not None : print('REGION: '+resume[2]) if resume[3] is not None : print('LATITUDE: '+str(resume[3])) if resume[4] is not None : print('LONGITUDE: '+str(resume[4])) print('\r\n') def getTargetIP(self): if self.ip is None : self.getDetailsTarget() return self.ip def getDetailsTarget(self): if self.ip is None : self.hostname = input('[*] Type your target (ip or hostname): ') location = DbIpCity.get(self.getIPFromHostname(), api_key='free') else : location = DbIpCity.get(self.ip, api_key='free') print('\r\n') self.country = location.country self.city = location.city self.region = location.region self.lat = location.latitude self.lng = location.longitude return self.country,self.city,self.region,self.lat,self.lng def getIPFromHostname(self): if self.ip is None : self.ip = socket.gethostbyname(str(self.hostname)) return self.ip return self.ip
def create_effects(self): self.effects = [] color1 = Colors.hls_to_rgb(self.hue1, 1, 1) color2 = Colors.hls_to_rgb(self.hue2, 1, 1) self.effects.append(AlternateColorEvery3Effect(self.sheep.body, color1, color2)) self.effects.append(AlwaysOnEffect(self.sheep.head + self.sheep.legs, color1)) self.effects.append(AlwaysOnEffect(self.sheep.eyes, color2))
def create_effects(self): self.effects = [] color1 = Colors.hls_to_rgb(self.hue1, 1, 1) color2 = Colors.hls_to_rgb(self.hue2, 1, 1) for l in self.grass.get_leaves_array(): self.effects.append(AlternateColorEvery3Effect(l[0], color1, color2)) self.effects.append(AlternateColorEvery3Effect(l[1][:], color1, color2))
def __init__(self): self.hostname = None self.ip = None self.country = None self.region = None self.city = None self.lat = None self.lng = None self.colors = Colors()
def next_hue(self): self.effects = [] new_hue = self.hue + self.hue_speed if new_hue > 1 : new_hue -= 1 prev_color = Colors.hls_to_rgb(self.hue, 1.0, 1.0) new_color = Colors.hls_to_rgb(new_hue, 1.0, 1.0) self.effects.append(GoToColorEffect(self.flower.get_leaves() + self.flower.seeds, prev_color, new_color)) self.hue = new_hue self.effects.append(AlwaysOnEffect(self.flower.line, [50, 200, 0])) self.effects.append(AlwaysOnEffect(self.flower.leaves, [0, 200, 0]))
def create_effects(self): self.effects = [] hue = random.random() for leaf in self.tree.get_leaves_and_stem(): self.effects.append( SinglePixelEffect(leaf[0][::-1], [0, 0, 0], Colors.hls_to_rgb(hue, 1.0, 1.0), len(leaf[0]))) self.effects.append( SinglePixelEffect(leaf[1][::-1], [0, 0, 0], Colors.hls_to_rgb(hue, 1.0, 1.0), len(leaf[1])))
def apply(self, time_percent): spin = int(math.floor(time_percent * self.num_of_spins)) if (spin != self.current_spin): self.current_spin = spin self.hue1 = Colors.reduce_by_1(self.hue1 + 0.4) self.hue2 = Colors.reduce_by_1(self.hue1+0.25) self.current_color1 = [int(c*255) for c in colorsys.hsv_to_rgb(self.hue1, 1.0, 0.15)] self.current_color2 = [int(c*255) for c in colorsys.hsv_to_rgb(self.hue2, 1.0, 0.15)] self.effect = AlternateColorEvery3Effect(self.signs.get_all_indexes(),self.current_color1,self.current_color2) oneSpinTime = 1.0 / self.num_of_spins relativePercent = (time_percent - oneSpinTime * self.current_spin) * self.num_of_spins self.effect.apply(relativePercent, self.signs.get_array())
def create_effects(self): self.effects = [] color1 = Colors.hls_to_rgb(self.hue1, 1, 1) color2 = Colors.hls_to_rgb(self.hue2, 1, 1) self.effects.append( AlternateColorEvery3Effect(self.flower.bottom_parts, color1, color2)) self.effects.append( AlternateColorEvery3Effect(self.flower.get_leaves(), color1, color2)) self.effects.append(AlwaysOnEffect(self.flower.seeds, color1))
def apply(self, time_precent, parent_array): if (time_precent < 0.5): power = time_precent * 2 else: power = (1.0 - time_precent) * 2 fixed_power = Colors.fix_lightness_percent(power) color = self.timed_color.get_color(time_precent, None) fixed_color = Colors.change_rgb_lightness(color, fixed_power) for i in self.indexes: parent_array[i*3 : i*3+3] = fixed_color
def show_fibonacci_animation(): print "fibonacci" hue1 = random.random() hue2 = Colors.reduce_by_1(hue1 + 0.111) hue3 = Colors.reduce_by_1(hue1 + 0.222) global animations animations = [ FibonacciAnimation(smallSheep, NUM_OF_BITS / 8, hue2), FibonacciAnimation(bigSheep12, NUM_OF_BITS / 8, hue1), FibonacciAnimation(bigSheep34, NUM_OF_BITS / 8, hue3), AlwaysOnSignsAnimation(signs, [30, 30, 30]) ]
def ls(self, param): # get actual element: elm = self.path[len(self.path)-1] print(Colors.c('./', Colors.BLUE)) if len(self.path) > 1: print(Colors.c('../', Colors.BLUE)) for k,v in elm.getChildren().items(): if isinstance(v, SugarSyncDirectory): print(Colors.c(str(k) + '/', Colors.BLUE)) else: print(k)
def show_fade_in_out_animation(): print "fade_in_out" hue1 = random.random() hue2 = Colors.reduce_by_1(hue1 + 0.111) hue3 = Colors.reduce_by_1(hue1 + 0.222) hue4 = Colors.reduce_by_1(hue1 + 0.333) global animations animations = [ FadeInOutAnimation(smallSheep, NUM_OF_BITS / 2, hue2), FadeInOutAnimation(bigSheep12, NUM_OF_BITS / 2, hue1), FadeInOutAnimation(bigSheep34, NUM_OF_BITS / 2, hue3), FadeInOutSignsAnimation(signs, NUM_OF_BITS / 2, hue4) ]
def show_alternate_animation(): print "alternate" hue1 = random.random() hue2 = Colors.reduce_by_1(hue1 + 0.25) hue3 = Colors.reduce_by_1(hue1 + 0.5) hue4 = Colors.reduce_by_1(hue1 + 0.75) global animations animations = [ AlternateAnimation(smallSheep, NUM_OF_BITS / 4, hue2), AlternateAnimation(bigSheep12, NUM_OF_BITS / 4, hue1), AlternateAnimation(bigSheep34, NUM_OF_BITS / 4, hue3), AlternateSignsAnimation(signs, NUM_OF_BITS / 4, hue4) ]
def apply(self, time_percent): spin = int(math.floor(time_percent * self.num_of_spins)) if (spin != self.current_spin): self.current_spin = spin self.hue1 = Colors.reduce_by_1(self.hue1 + 0.4) self.hue2 = Colors.reduce_by_1(self.hue1+0.25) self.current_color1 = [int(c*255) for c in colorsys.hsv_to_rgb(self.hue1, 1.0, 0.15)] self.current_color2 = [int(c*255) for c in colorsys.hsv_to_rgb(self.hue2, 1.0, 0.15)] self.create_effects() oneSpinTime = 1.0 / self.num_of_spins relativePercent = (time_percent - oneSpinTime * self.current_spin) * self.num_of_spins for effect in self.effects: effect.apply(relativePercent, self.flower.get_array())
def apply_animation(ui_element, num_of_beats, duration, relative_song_time): beat_duration = duration/num_of_beats beats_played = math.floor(relative_song_time / beat_duration) relative_beat_time = relative_song_time - beat_duration * beats_played percent_beat_time = relative_beat_time / beat_duration if beats_played % 2 == 0: color = Colors.hls_to_rgb(hue, 1 ,1) else: color = Colors.hls_to_rgb(hue + 0.1, 1 ,1) for i in range(len(ui_element.get_array())/3): ui_element.get_array()[i*3 : i*3+3] = color
def _start_spike(self): self.effects = [] self.last_hue += self.hue_speed if self.last_hue > 1: self.last_hue -= 1 rand_color = Colors.hls_to_rgb(self.last_hue, 1.0, 1.0) self.effects.append(AlwaysOnEffect(self.lake.waves_arr[self.last_wave], rand_color)) contour_color = Colors.hls_to_rgb(self.last_hue, 0.5, 0.7) self.effects.append(AlwaysOnEffect(self.lake.contour, contour_color)) self.last_wave += 1 if self.last_wave >= len(self.lake.waves_arr): self.last_wave = 0
def apply(self, time_percent): if time_percent < 0.5: c = time_percent * 0.25 else: c = (1.0 - time_percent) * 0.25 c = c +0.01 c = math.pow(c, 0.5) for i in self.flower.get_leaves(): self.flower.get_array()[i*3:i*3+3] = Colors.change_rgb_lightness([128, 0, 128], c) for i in self.flower.get_seeds(): self.flower.get_array()[i*3:i*3+3] = Colors.change_rgb_lightness([255, 255, 0], c) for i in self.flower.bottom_parts: self.flower.get_array()[i*3:i*3+3] = Colors.change_rgb_lightness([0, 255, 0], c)
def cmd(self): while self.run: want = input('%s %s ' % (self.getPath(), Colors.c('$', Colors.BLUE))) cmd = '' param = '' # its always the same: command parameters - there is no &&, ||, |, &, etc. pp. index = want.find(' ') if index > 0: cmd = want[:index] param = want[index:] else: cmd = want param = '' try: self.cmds[cmd](param) except KeyError as ke: print('Wrong input.') except Exception as e: print('Error processing action.', e) exc_type, exc_value, exc_traceback = sys.exc_info() #print("*** print_tb:") #traceback.print_tb(exc_traceback, limit=20, file=sys.stdout) print("*** print_exception:") traceback.print_exception(exc_type, exc_value, exc_traceback, limit=20, file=sys.stdout)
def create_bottom_animation(self): self.effects = [] hue = self.previous_hue + 0.1 + random.random() * 0.8 if hue > 1: hue -= 1 self.previous_hue = hue self.previous_color = self.color self.color = Colors.hls_to_rgb(hue, 1, 1) self.effects.append( AdvanceEffect.initColor(self.flower.line_back, self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(self.flower.line_front, self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(self.flower.leaf_right_front, self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(self.flower.leaf_right_back, self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(self.flower.leaf_left_front, self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(self.flower.leaf_left_back, self.previous_color, self.color)) self.effects.append( AlwaysOnEffect(self.flower.seeds, self.previous_color)) self.effects.append( AlwaysOnEffect(self.flower.get_leaves(), self.previous_color))
def drawBoard( self, stdscr: Optional[curses.window] = None, # type: ignore return_as_str: bool = False, ) -> Optional[str]: return_str: Optional[str] = None for y, row_data in enumerate(self.getBoard()): for x, entities in enumerate(row_data): if len(entities) > 1: raise Exception( "Got to draw step without clearing out multi-entity cells. Should have been cleared by collision handlers" ) entity = entities[0] if len(entities) == 1 else None if entity is not None: if return_as_str: if return_str is None: return_str = "" return_str += entity.symbol elif stdscr is not None: # Redundant but type checking purposes stdscr.addch(y, x, entity.symbol, Colors.getAttr(entity.color)) else: if return_as_str: if return_str is None: return_str = "" return_str += " " elif stdscr is not None: stdscr.addch(y, x, " ") if return_str is not None: return_str += "\n" return return_str
def __init__(self, game, name, rep, color_tone, hands, armor_rating, encumbrance, enchantment, loc, brand=None): self.rep, self.color, self.hands, self.armor_rating, self.encumbrance, self.enchantment, self.loc, self.brand = rep, color_tone, hands, armor_rating, encumbrance, enchantment, loc, brand self.wclass = "shield" self.name, self.base_string = Colors.color(name, self.color), name # Legendary if self.base_string in Weapons.legendaries: self.legendary = True try: game.legendaries_to_spawn.remove(self.base_string) except: pass else: self.legendary = False # Magic Damage self.mdamage = 0
def apply(self, time_percent): spin = int(math.floor(time_percent * self.num_of_spins)) if (spin != self.current_spin): self.current_spin = spin if (spin % 2 == 0): color = [ int(c * 255) for c in colorsys.hsv_to_rgb(self.hue, 1.0, 0.15) ] self.effects = [ FadeOutEffect(self.sheep.get_all_indexes(), color) ] else: self.hue = Colors.reduce_by_1(self.hue + 0.29) color = [ int(c * 255) for c in colorsys.hsv_to_rgb(self.hue, 1.0, 0.15) ] self.effects = [ FadeInEffect(self.sheep.get_all_indexes(), color) ] oneSpinTime = 1.0 / float(self.num_of_spins) relativePercent = (time_percent - oneSpinTime * self.current_spin) * self.num_of_spins for effect in self.effects: effect.apply(relativePercent, self.sheep.get_array())
def apply(self, time_percent, parent_array): for i in range(len(self.indexes)): index = self.indexes[i] percent = float(i) / len(self.indexes) percent = math.pow(percent, self.power) color = Colors.go_to_color(self.from_color, self.to_color, percent) parent_array[index * 3:index * 3 + 3] = color
def apply(self, time_percent): if time_percent < 0.5: c = time_percent * 0.25 else: c = (1.0 - time_percent) * 0.25 c = c + 0.01 c = math.pow(c, 0.5) for i in self.tree.get_stem(): self.tree.get_array()[i * 3:i * 3 + 3] = Colors.change_rgb_lightness( [184, 134, 11], c) for i in self.tree.get_leaves(): self.tree.get_array()[i * 3:i * 3 + 3] = Colors.change_rgb_lightness([0, 255, 0], c)
def dir(self, dir): dir = dir.strip() if dir in ('', '.'): dir = self.cwd if dir[:2] == './': dir = dir[2:] if dir[0] not in ('~', '.', '/'): dir = os.path.join(self.cwd, dir) dir = os.path.expanduser(dir) dir = os.path.abspath(dir) for item in os.listdir(dir): fullName = os.path.join(dir, item) if os.path.isdir(fullName): Colors.print('BLUE', item) elif os.access(fullName, os.X_OK): Colors.print('RED', item) else: print(item)
def dir(self, dir): dir = dir.strip() if dir in ('','.'): dir = self.cwd if dir[:2] == './': dir = dir[2:] if dir[0] not in ('~', '.', '/'): dir = os.path.join(self.cwd, dir) dir = os.path.expanduser(dir) dir = os.path.abspath(dir) for item in os.listdir(dir): fullName = os.path.join(dir,item) if os.path.isdir(fullName): Colors.print('BLUE',item) elif os.access(fullName, os.X_OK): Colors.print('RED',item) else: print(item)
def add_effect_for_index(self, index, location_percent): start_t = random.uniform(0.0, 0.4) dark_time = 1.0 - random.uniform(0.00, 0.4) on_tot_time = dark_time - start_t on_start_t = start_t + random.uniform(0.1, on_tot_time / 2.0) on_end_t = dark_time - random.uniform(0.1, on_tot_time / 2.0) rgb_color = Colors.hls_to_rgb(random.random(), random.uniform(0, 0.5), 1.0) self.effects.append( StarEffect([index], ConstTimedColor(rgb_color), start_t, on_start_t, on_end_t, dark_time, location_percent))
def apply(self, parent_array): for i in range(len(self.indexes)): # color hue = (i / float(len(self.indexes)) * self.num_of_rainbows) % 1 color = Colors.hls_to_rgb(hue, self.max_brightness, 1.0) index = self.indexes[i] parent_array[index * 3:index * 3 + 3] = color
def __init__(self, roomCoord, originCoord, level, mapCoord): ''' :type level: MCLevel ''' self.originCoord = originCoord self.roomCoord = roomCoord self.level = level self.color = Colors.getRandomColor(Colors()) self.mapCoord = mapCoord pass
def getPath(self, withHeader=True, colorize=True): # the beginning: if len(self.sugarsync.nickname) > 0: h = self.sugarsync.nickname + ' ' else: h = self.sugarsync.username[:self.sugarsync.username.find('@')] + ' ' if colorize: h = Colors.c(h, Colors.YELLOWL) p = '' for f in self.path: p = p + f.getName() + '/' if colorize: p = Colors.c(p, Colors.BLUE) if withHeader: return h + p else: return p
def appendGif(): sequence = choice(sequences) sequence_str = ''.join(i for i in sequence) for i in sequence: i = ['y', 'b', 'g', 'r', 'p'].index(i) ok = Colors(500,100) ok.drawCells() im = ok.img.convert("P") images.append(im) ok = Colors(500,100) ok.drawCells() ok.drawCell(i, 'active') im = ok.img.convert("P") images.append(im) ok = Colors(500,100) ok.drawCells() im = ok.img.convert("P") images.append(im) writeGif(sequence_str+".gif", images, duration=0.5, repeat=False) system("convert %s -colors 9 %s" % (sequence_str+".gif", sequence_str+".gif")) with open(sequence_str+".gif", "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) json_data = json.dumps({'gif' : encoded_string, 'sequence' : sequence_str}) print sequence_str
from itertools import product from random import choice from os import remove, system import base64 import json import redis for q in range(100): images=[] sequences = list(product(['b', 'y', 'r', 'p', 'g'], repeat=4)) sequence = choice(sequences) sequence_str = ''.join(i for i in sequence) for i in sequence: i = ['b', 'y', 'r', 'p', 'g'].index(i) ok = Colors(500,100) ok.drawCells() im = ok.img.convert("P") images.append(im) ok = Colors(500,100) ok.drawCells() ok.drawCell(i, 'active') im = ok.img.convert("P") images.append(im) ok = Colors(500,100) ok.drawCells() im = ok.img.convert("P") images.append(im)