Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # s60_subtractive_color_mixing.py
- from appuifw import *
- import e32,audio,appuifw,os,sys,key_codes,time,math,random,graphics,sensor,copy
- from graphics import *
- z_Colors = ((u'RGB_BLACK',(0,0,0)),
- (u'RGB_WHITE',(255,255,255)),
- (u'RGB_GRAYLIGHT',(211,211,211)),
- (u'RGB_GRAY',(128,128,128)),
- (u'RGB_GRAYDARK',(169,169,169)),
- (u'RGB_RED',(255,0,0)),
- (u'RGB_ORANGE',(255,165,0)),
- (u'RGB_YELLOW',(255,255,0)),
- (u'RGB_GREEN',(0,128,0)),
- (u'RGB_BLUE',(0,0,255)),
- (u'RGB_CYAN',(0,255,255)),
- (u'RGB_PURPLE',(128,0,128)),
- (u'RGB_PINK',(255,148,238)),
- (u'RGB_DARKBLUE',(0,0,139)),
- (u'RGB_DARKGREEN',(0,100,0)),
- (u'RGB_DEEPPINK',(255,20,147)),
- (u'RGB_INDIGO',(75,0,130)),
- (u'RGB_LIGHTBLUE',(173,216,230)),
- (u'RGB_LIME',(0,255,0)),
- (u'RGB_OLIVE',(107,142,35)),
- (u'RGB_BROWN',(139,69,19)),
- (u'RGB_GOLD',(255,215,0)),
- (u'RGB_SILVER',(192,192,192)))
- #
- rgb_menu='rgb_menu=['
- for rgb in z_Colors:
- i,ii=rgb[0].replace('RGB_',''),str(rgb[1])
- rgb_menu += "(u'"+i+"',c_"+i+"),"
- exec 'def c_'+i+'(): cv.color='+ii
- exec rgb[0]+'='+ii
- exec rgb_menu[:-1]+']'
- appuifw.app.menu=rgb_menu
- class cv():
- go=1
- pixel=(1,1)
- incr=0
- msg=''
- t=0
- Lcolor = (0,0,255)
- Rcolor = (255,255,0)
- btn=1
- color=(0,0,0)
- cv=cv()
- def quit():
- timer.cancel()
- cv.go = 0
- app.exit_key_handler = quit
- def draw(rect):
- if img:
- canvas.blit(img)
- def e_callback(event):
- cv.pixel = event['pos']
- try: timer.cancel()
- except: pass
- if cv.pixel[0] > 340:
- cv.incr=increment[int(cv.pixel[1]*sVy)]
- timer.after(1,zero)
- img=None
- app.screen = 'large'
- app.orientation = 'portrait'
- app.directional_pad = False
- app.body = canvas = Canvas(redraw_callback=draw, event_callback=e_callback) #
- img = Image.new(canvas.size)
- res_x, res_y = canvas.size
- timer = e32.Ao_timer()
- res_x, res_y = 360,576
- sVy = 9.0/res_y
- increment=[100,50,10,1,0,-1,-10,-50,-100]
- img.clear(RGB_GRAY)
- BW=[RGB_WHITE,RGB_BLACK]
- yy2=res_y/9
- for ssVyy in xrange(9):
- yy=yy2*ssVyy+2
- WvB=BW[0]
- BW[0],BW[1]=BW[1],BW[0]
- img.rectangle(((350,yy,358,yy+yy2)), fill=WvB)
- draw(())
- def rgb_btns(x,y,x2=360,y2=50):
- xx=x2/3+1
- rgb=RGB_RED,RGB_GREEN,RGB_BLUE
- for i in xrange(3):
- xy2=(x+xx*i,y,x+xx*(i+1),y+y2)
- if cv.pixel:
- xv,yv=cv.pixel
- if yv > y and yv < y+y2:
- if xv > xy2[0] and xv < xy2[2]:
- cv.active_palette=palref[palette+i]
- cv.RGB_mark=(x+xx*i,y,x+xx*i+10,y+10)
- img.rectangle((xy2), fill=rgb[i])
- def hx(rgb):
- return '#%02x%02x%02x' % rgb
- palref='''
- cv.Lcolor = (hh(cv.Lcolor[0]), cv.Lcolor[1], cv.Lcolor[2])
- cv.Lcolor = (cv.Lcolor[0], hh(cv.Lcolor[1]), cv.Lcolor[2])
- cv.Lcolor = (cv.Lcolor[0], cv.Lcolor[1], hh(cv.Lcolor[2]))
- cv.Rcolor = (hh(cv.Rcolor[0]), cv.Rcolor[1], cv.Rcolor[2])
- cv.Rcolor = (cv.Rcolor[0], hh(cv.Rcolor[1]), cv.Rcolor[2])
- cv.Rcolor = (cv.Rcolor[0], cv.Rcolor[1], hh(cv.Rcolor[2]))'''.split('\n')[1:]
- cv.active_palette=palref[0]
- #
- def mixColors(): ### ZZZ yellow + blue = (0,128,0)
- def rgbfix(R):
- aaa=(LC[R]*-1)+(RC[R])
- tmp=[0,1,2]; tmp.pop(R)
- bbb=LC[tmp[0]]+LC[tmp[1]]
- ccc=int((RC[tmp[0]]+RC[tmp[1]]))*-1
- tmp=abs(aaa+bbb+ccc)-637
- if tmp > 0: return tmp
- return 0
- LC,RC = cv.Lcolor,cv.Rcolor
- rgb = [(LC[0]+1)/2, (LC[1]+1)/2, (LC[2]+1)/2] # L
- rgb = [rgb[0]+((RC[0]+1)/2), rgb[1]+((RC[1]+1)/2), rgb[2]+((RC[2]+1)/2)] # R
- # color fix for mixing yellow and blue to correspondingly make green
- rgb = [rgb[0]-rgbfix(2),rgb[1],rgb[2]-rgbfix(2)]
- for i in range(3):
- if rgb[i] > 255: rgb[i] = 255
- elif rgb[i] < 0: rgb[i] = 0
- return tuple(rgb)
- #
- def zero():
- cv.incr=0
- #
- def rgb_box(box,x=10,y=210,w=60,h=60):
- i='LRM'.find(box)
- return ((x,y,350-x-w,y+h*3),(x+w,y+h,350-x,y+h*4),(x+w,y+h,350-x-w,y+h*3))[i]
- #
- def hh(limit):
- limit+=cv.incr
- if limit < 0: limit=0
- if limit > 255: limit=255
- return limit
- #
- prev_color=cv.color
- cv.RGB_mark=(10,140,20,150)
- while cv.go:
- if prev_color <> cv.color:
- prev_color=cv.color
- exec (cv.active_palette[:9]+'='+str(cv.color))
- cv.pixel=(1,0)
- if time.time() > cv.t and cv.pixel:
- exec (cv.active_palette)
- cv.subcolor = mixColors()
- img.rectangle(((0,0,350,640)), fill=RGB_GRAY)
- img.rectangle(((0,0,340,92)), fill=RGB_WHITE)
- palette=0
- rgb_btns(10,140,280)
- palette=3
- rgb_btns(10,500,280)
- img.rectangle((cv.RGB_mark), fill=RGB_WHITE)
- img.rectangle((rgb_box('L')), fill=cv.Lcolor)
- img.rectangle((rgb_box('R')), fill=cv.Rcolor)
- img.rectangle((rgb_box('L')), width=3, outline=RGB_BLACK)
- img.rectangle((rgb_box('R')), width=3, outline=RGB_BLACK)
- img.rectangle((rgb_box('M')), fill=cv.subcolor)
- img.text((10,36), u"RGB Result Of A And B:", fill = RGB_BLACK,font=(u'Nokia Hindi S60',29,STYLE_BOLD))
- img.text((10,68), u""+str(cv.subcolor), fill = RGB_BLACK,font=(u'Nokia Hindi S60',29,STYLE_BOLD))
- img.text((10,128), u"RGB Of A: "+str(cv.Lcolor), fill = RGB_BLACK,font=(u'Nokia Hindi S60',29,STYLE_BOLD))
- img.text((10,488), u"RGB Of B: "+str(cv.Rcolor), fill = RGB_BLACK,font=(u'Nokia Hindi S60',29,STYLE_BOLD))
- cv.t=time.time()+0.3
- draw(())
- cv.incr=0
- cv.pixel=None
- e32.ao_yield()
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement