niter = 101 # # Open a workstation. # wks_type = "png" wks = Ngl.open_wks(wks_type, "color5") # # Define our own color table going around # all the hues in the HLS color space, starting # with blue. # for k in range(0, niter): h = 360 * float(k) / float(niter) r, g, b = Ngl.hlsrgb(h, 50., 100.) Ngl.set_color(wks, k, r, g, b) # # Create the set and draw the color cells. # poly_res = Ngl.Resources() for j in range(ny): for i in range(nx): x, y = get_cell(i, j, xl, xr, yb, yt, nx, ny) iter = convg(complex(x[0], y[0]), niter, 0.001, 10000) poly_res.gsFillColor = iter - 1 # iter will be at least one. for i in range(len(x)): x[i], y[i] = user2ndc(x[i], y[i]) Ngl.polygon_ndc(wks, x, y, poly_res) Ngl.frame(wks)
niter = 101 # # Open a workstation. # wks_type = "ps" wks = Ngl.open_wks(wks_type,"color5") # # Define our own color table going around # all the hues in the HLS color space, starting # with blue. # for k in xrange(0,niter): h = 360*float(k)/float(niter) r,g,b = Ngl.hlsrgb(h, 50., 100.) Ngl.set_color(wks, k, r, g, b) # # Create the set and draw the color cells. # poly_res = Ngl.Resources() for j in xrange(ny): for i in xrange(nx): x, y = get_cell(i, j, xl, xr, yb, yt, nx, ny) iter = convg(complex(x[0],y[0]), niter, 0.001, 10000) poly_res.gsFillColor = iter-1 # iter will be at least one. for i in xrange(len(x)): x[i], y[i] = user2ndc(x[i], y[i]) Ngl.polygon_ndc(wks, x, y,poly_res) Ngl.frame(wks)
# Ngl.frame(wks) # # Illustrations and tests for the color conversion functions. # # # Set a tolerance limit for HLS and HSV tests. # eps = 0.00001 # # HLS to RGB: (120., 50., 100.) -> (1., 0., 0.) # r, g, b = Ngl.hlsrgb(120., 50., 100.) if numpy.sometrue(numpy.greater(numpy.fabs([r - 1., g, b]), eps)): print("color3: hlsrgb test failed") # # RGB to HLS: (1., 0., 0.) -> (120., 50., 100.) # h, l, s = Ngl.rgbhls(1., 0., 0.) if numpy.sometrue(numpy.greater(numpy.fabs([h - 120., l - 50., s - 100.]), eps)): print("color3: rgbhls test failed") # # HSV to RGB: (120., 1., 1.) -> (0., 1., 0.) # r, g, b = Ngl.hsvrgb(120., 1., 1.)
# Ngl.frame(wks) # # Illustrations and tests for the color conversion functions. # # # Set a tolerance limit for HLS and HSV tests. # eps = 0.00001 # # HLS to RGB: (120., 50., 100.) -> (1., 0., 0.) # r,g,b = Ngl.hlsrgb(120., 50., 100.) if numpy.sometrue(numpy.greater(numpy.fabs([r-1., g, b]), eps)): print "color3: hlsrgb test failed" # # RGB to HLS: (1., 0., 0.) -> (120., 50., 100.) # h,l,s = Ngl.rgbhls(1., 0., 0.) if numpy.sometrue(numpy.greater(numpy.fabs([h-120.,l-50.,s-100.]), eps)): print "color3: rgbhls test failed" # # HSV to RGB: (120., 1., 1.) -> (0., 1., 0.) # r,g,b = Ngl.hsvrgb(120., 1., 1.) if numpy.sometrue(numpy.greater(numpy.fabs([r, g-1., b]), eps)):