Skip to content

Commit

Permalink
simplify code and add C,M,Y
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@16302 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 12, 2017
1 parent a344dcc commit 927e90c
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/tests/xpra/test_apps/colors_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ def area_draw(self, widget, cr):
#Clear everything:
cr.save()
cr.set_operator(cairo.OPERATOR_CLEAR)
ww, wh = widget.get_size()
cr.rectangle(0, 0, ww, wh)
w, h = widget.get_size()
cr.rectangle(0, 0, w, h)
cr.fill()
cr.restore()

c = 8

def paint_block(x, y, w, h, R=255, G=255, B=255, label=""):
count = 10
self.index = 0
bh = h//count
def paint_block(R=255, G=255, B=255, label=""):
y = h*self.index//count
self.index += 1
cr.set_operator(cairo.OPERATOR_SOURCE)
for i in range(w):
v = float(i)/float(w)
Expand All @@ -38,27 +41,27 @@ def paint_block(x, y, w, h, R=255, G=255, B=255, label=""):
g = max(0, float(G)*v/255.0)
b = max(0, float(B)*v/255.0)
cr.set_source_rgb(r, g, b)
cr.rectangle(x+i, y, 1, h)
cr.rectangle(i, y, 1, bh)
cr.fill()
cr.restore()
if label:
cr.set_font_size(32)
cr.set_source_rgb(1, 1, 1)
cr.move_to(x+w//2-12, y+wh//(c*2)+8)
cr.move_to(w//2-12, y+bh//2+8)
cr.show_text(label)

#Red block
paint_block(0, 0, ww, wh/c, 255, 0, 0, "R")
#Green block:
paint_block(0, wh//c, ww, 2*wh/c, 0, 254, 0, "G")
#Blue block:
paint_block(0, 2*wh//c, ww, 3*wh/c, 0, 0, 253, "B")
paint_block(255, 0, 0, "R")
paint_block(0, 254, 0, "G")
paint_block(0, 0, 253, "B")
paint_block(0, 252, 252, "C")
paint_block(251, 0, 251, "M")
paint_block(251, 251, 0, "Y")
#Black Shade Blocks:
paint_block(0, 3*wh//c, ww, 4*wh/c, 255, 255, 255)
paint_block(0, 4*wh//c, ww, 5*wh/c, 127, 127, 127)
paint_block(0, 5*wh//c, ww, 6*wh/c, 63, 63, 63)
paint_block(0, 6*wh//c, ww, 7*wh/c, 31, 31, 31)
paint_block(0, 7*wh//c, ww, 8*wh/c, 15, 15, 15)
paint_block(255, 255, 255)
paint_block(127, 127, 127)
paint_block(63, 63, 63)
paint_block(31, 31, 31)
paint_block(15, 15, 15)

import signal
signal.signal(signal.SIGINT, lambda x,y : Gtk.main_quit)
Expand Down

0 comments on commit 927e90c

Please sign in to comment.