Advertisement
phjoe

Color Wheel

Dec 19th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Color Wheel
  2. # Joe, 19/12/2014
  3. import appuifw as A
  4. import graphics as G
  5. from math import cos,sin,pi
  6.  
  7. rad=lambda x:x*pi/180.0
  8.  
  9. def h2r(h,s,v):
  10.  if s==0.0: return v,v,v
  11.  i=int(h*6.0)
  12.  f=(h*6.0)-i
  13.  p=v*(1.0-s)
  14.  q=v*(1.0-s*f)
  15.  t=v*(1.0-s*(1.0-f))
  16.  if i%6==0:return v,t,p
  17.  if i==1:return q,v,p
  18.  if i==2:return p,v,t
  19.  if i==3:return p,q,v
  20.  if i==4:return t,p,v
  21.  if i==5:return v,p,q
  22.  
  23. def gen(n=256):
  24.  hsv=[(x*0.9/n,0.6,0.9) for x in xrange(n)]
  25.  rgb=map(lambda x: tuple(map(lambda x:int(x*255), h2r(*x))),hsv)
  26.  return rgb
  27.  
  28. run=1
  29. w,h=G.sysinfo.display_pixels()
  30. img=G.Image.new((w,h))
  31.  
  32. def stop():
  33.  global run
  34.  run=0
  35.  
  36. def draw(x):
  37.  c.blit(img)
  38.  
  39. A.app.screen='full'
  40. c=A.Canvas(redraw_callback=draw)
  41. A.app.body=c
  42. A.app.exit_key_handler=stop
  43.  
  44. N=360
  45. col=gen(N)
  46. cx,cy=w/2,h/2
  47. rr=80
  48. for i in range(h+1):
  49.  img.line((0,h-i,w,h-i),col[i])
  50.  draw(())
  51.  A.e32.ao_sleep(1e-04)
  52. for i in range(N):
  53.  x1=cx+rr*cos(rad(i))
  54.  y1=cy+rr*-sin(rad(i))
  55.  img.line((cx,cy,x1,y1),col[i],0,2)
  56.  draw(())
  57.  A.e32.ao_sleep(1e-04)
  58.  
  59. while run:
  60.  img.text((5,h-10),u'Color Wheel \u00a9 2014, Joe',0xffffff)
  61.  draw(())
  62.  A.e32.ao_sleep(1e-04)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement