""" pygl/COLOURsjm.py: CCP4MG Molecular Graphics Program Copyright (C) 2001-2005 University of York, CCLRC This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3, modified in accordance with the provisions of the license to address the requirements of UK law. You should have received a copy of the modified GNU Lesser General Public License along with this library. If not, copies may be downloaded from http://www.ccp4.ac.uk/ccp4license.php This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. """ from opengl import newfv4 next_code = 10 names = ['default','white','red','blue','green','grey','yellow','pink','black','magenta','cyan'] codes = [0,1,2,3,4,5,6,7,8,9,10] reps = [ [0.7, 0.7, 0.7, 1.0] , \ [1.0, 1.0, 1.0, 1.0] , \ [1.0, 0.1, 0.1, 1.0] , \ [0.0, 0.2, 1.0, 1.0] , \ [0.2, 1.0, 0.2, 1.0] , \ [0.6, 0.6, 0.6, 1.0] , \ [1.0, 1.0, 0.2, 1.0] , \ [1.0, 0.4, 0.6, 1.0] , \ [0.0, 0.0, 0.0, 0.0] , \ [1.0, 0.2, 1.0, 1.0] , \ [0.2, 1.0, 1.0, 1.0] , \ ] def new(name,rep=None): global next_code if names.count(name) > 0: print "Colour already defined:",name return names.append(name) next_code = next_code + 1 codes.append(next_code) if rep == None: # default is default reps.append(rep('default')) else: reps.append(rep) def code(name): if names.count(name) <= 0: return 0 else: i = names.index(name) return codes[i] def rep(name): #first try assuming input is a code number if codes.count(name) > 0: i = codes.index(name) return reps[i] elif names.count(name) > 0: i = names.index(name) return reps[i] else: return [0.7, 0.7, 0.7, 1.0] def rep2glrep(rep): return newfv4(rep[0], rep[1], rep[2], rep[3]) def glrep(name,alpha=1.0): #first try assuming input is a code number if codes.count(name) > 0: i = codes.index(name) if alpha != 1.0: return newfv4(reps[i][0], reps[i][1], reps[i][2], alpha) else: return newfv4(reps[i][0], reps[i][1], reps[i][2], reps[i][3]) elif names.count(name) > 0: i = names.index(name) if alpha != 1.0: return newfv4(reps[i][0], reps[i][1], reps[i][2], alpha) else: return newfv4(reps[i][0], reps[i][1], reps[i][2], reps[i][3]) else: return newfv4(0.7, 0.7, 0.7, 1.0) def delete(name): if names.count(name) > 0: i = names.index(name) names.pop(i) codes.pop(i) reps.pop(i) return 1 else: return 0 def rename(name,newname): if names.count(name) > 0: i = names.index(name) names.pop(i) names.insert(i,newname) return 1 else: return 0 def reset(name,rep): if names.count(name) > 0: i = names.index(name) reps.pop(i) reps.insert(i,rep) return 1 else: return 0