def getColor(self): if self.colorPalette: idx = random.randrange(0, len(self.colorPalette)) self.color_idx = idx return self.colorPalette[idx] else: return randomColor()
def __init__(self, name, sceneName, start=0.0, end=1.0, curves=None, textures=None, speed=1.0, preroll=0.0): self.items = [ QStandardItem(name), QStandardItem(sceneName), QStandardItem(str(start)), QStandardItem(str(end)), QStandardItem(str(end - start)), QStandardItem(str(speed)), QStandardItem(str(preroll)) ] self.curves = curves or OrderedDict() self.textures = textures or OrderedDict() self.color = QColor.fromRgb(*randomColor()) self.items[0].setData(self, Qt.UserRole + 1) self._enabled = True self._pinned = False self.items[0].setIcon(icons.get('Checked Checkbox'))
def __init__(self, model): self.model = model self.wipeDuration = 1 self.hueDelta = .27 # add this to the hue on each transition self.buttonDown = False self.wipeStartTime = None # should be None if no wipe is in progress self.color = randomColor() self.oldColor = None # ""
def extractPiece(tile, margin=0.05): imgs = [tile] w, h, _ = tile.shape im_gray = cv2.cvtColor(tile, cv2.COLOR_BGR2GRAY) imgs.append(cv2.cvtColor(im_gray, cv2.COLOR_GRAY2BGR)) # im_gray = im_gray[(h*margin):(h*(1-margin)), # (w*margin):(w*(1-margin))] # imgs.append(cv2.cvtColor(im_gray, cv2.COLOR_GRAY2BGR)) # im_gray = cv2.equalizeHist(im_gray) im_gray = cv2.medianBlur(im_gray, 3) imgs.append(cv2.cvtColor(im_gray, cv2.COLOR_GRAY2BGR)) bright = np.mean(im_gray) im_bw = im_gray im_bw[np.where(im_gray < bright)] = 0 im_bw[np.where(im_gray >= bright)] = 255 imgs.append(cv2.cvtColor(im_bw, cv2.COLOR_GRAY2BGR)) if np.mean(im_bw) < 128: im_bw = 255 - im_bw imgs.append(cv2.cvtColor(im_bw, cv2.COLOR_GRAY2BGR)) #_, im_bw = cv2.threshold(im_gray, 50, 250, cv2.THRESH_BINARY | cv2.THRESH_OTSU) #im_bw = cv2.Canny(im_bw, 0,255, apertureSize=5) contours, hierarchy = cv2.findContours(im_bw.copy(), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_TC89_KCOS) hulls = [cv2.convexHull(c) for c in contours] ids = ignoreContours(im_bw, hulls, max_area_percentage=0.75, min_area_percentage=0.2) im_bw = cv2.cvtColor(im_bw, cv2.COLOR_GRAY2BGR) tmp = im_bw.copy() for i in ids: c = np.squeeze(hulls[i], 1) drawContour(tmp, c, randomColor(), thickness=1) imgs.append(tmp) return imgs
def parseSTL(stlFilename): v = [] f = [] with open(stlFilename) as fp: for line in fp: words = line.strip().split() if words[0].lower() == 'vertex': vert = util.Vertex( float(words[1]), float(words[2]), float(words[3]), util.randomColor()) v.append(vert) #print("v(%d %d %d) i=%d" % (vert.x, vert.y, vert.z, len(v)-1)) elif words[0].lower() == 'endfacet': n = len(v) f.append((n-1, n-2, n-3)) #print("f %d %d %d" % f[-1]) print("Read %d vertices and %d faces" % (len(v), len(f))) return v,f
def paintEvent(self, event): if self.scene is None: return painter = QPainter(self) # let's assume we're drawing a timeline for 100ms scale = float(self.width()) * 10.0 cursor = 0.0 self.tooltipinfo.clear() for i, entry in enumerate(self.scene.profileLog): label, seconds = entry text = '%s %ims' % (label, round(seconds * 1000.0)) rect = QRectF(cursor * scale, 0, seconds * scale, self.height()) self.tooltipinfo[text] = rect painter.setPen(Qt.NoPen) painter.setBrush(QColor.fromRgb(*randomColor(i * 0.1357111317))) painter.drawRect(rect) painter.setPen(Qt.black) painter.setBrush(Qt.NoBrush) painter.drawText(rect, 0, text) cursor += seconds