Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Blog
Views: 55
Author: Vincent J. Matsko
Date: 4 September 2015, Day002
Updated: 29 August 2016
Post: Josef Albers and Interaction of Color
# Note: If you want to make any changes and try on your own, you must save this file to one of your own projects. # If you are getting "no write access" errors, then you must make a copy of this file to one of you own projects. # Allows the user to experiment with RGB color values. # RGB values are incremented in units of 0.01. Change the step_size for a different increment. # To use, place your cursor anyone in the code, then hit shift+enter - hold down the shift key, and while you're holding it, hit the enter key. # Hitting shift and enter separately won't work! from sage.plot.colors import rgbcolor # Changing "True" to "False" in the next line will allow you change ALL the sliders and then press an Update button. # However, the most recent image disappears when you do this. @interact(auto_update=True) def _(r=slider(0,1.0, default=0.5, step_size=0.01, width=30), # Will default to neutral gray. g=slider(0,1.0, default=0.5, step_size=0.01, width=30), b=slider(0,1.0, default=0.5, step_size=0.01, width=30)): P = plot(disk((0,0),1,(0,2*pi),color=rgbcolor([r,g,b]))) show(P, aspect_ratio=1, axes=False)
Interact: please open in CoCalc
# This code snippet explores the color contrast of Josef Albers. # Slide the r, g, and b controls to change color of the interior rectangles. # Slide the deltar, deltag, and deltab controls to change the colors of the exterior rectangles. # Note how the colors are defined for S1 and S2! # To use, place your cursor anyone in the code, then hit shift+enter - hold down the shift key, and while you're holding it, hit the enter key. # Hitting shift and enter separately won't work! # # NOTE: To get an "Albers" effect, make sure your delta values aren't too large. See the blog post for more comments. # Negative RGB values become 0, and values greater than 1 are truncated to 1. def RGBValue (value): if value < 0: return 0 else: if value > 1: return 1 else: return value # Changing "True" to "False" in the next line will allow you change ALL the sliders and then press an Update button. # However, the most recent image disappears when you do this. @interact(auto_update=True) def _(r=slider(0, 1.0, default=0.5, step_size=0.01, width=30), # Will default to neutral gray. g=slider(0, 1.0, default=0.5, step_size=0.01, width=30), b=slider(0, 1.0, default=0.5, step_size=0.01, width=30), deltar=slider(0, 1.0, default=0, step_size=0.01, width=30), deltag=slider(0, 1.0, default=0, step_size=0.01, width=30), deltab=slider(0, 1.0, default=0, step_size=0.01, width=30)): P1 = plot(polygon2d([[0.15,0.15],[0.15,0.85],[0.35,0.85],[0.35,0.15]], rgbcolor=(r,g,b))) P2 = plot(polygon2d([[0.65,0.15],[0.65,0.85],[0.85,0.85],[0.85,0.15]], rgbcolor=(r,g,b))) S1 = plot(polygon2d([[0,0],[0,1],[0.5,1],[0.5,0]], rgbcolor=(RGBValue(r - deltar), RGBValue(g - deltag), RGBValue(b - deltab)))) S2 = plot(polygon2d([[0.5,0],[0.5,1],[1,1],[1,0]], rgbcolor=(RGBValue(r + deltar), RGBValue(g + deltag), RGBValue(b + deltab)))) show(S1 + S2 + P1 + P2, aspect_ratio=1, axes=False)
Interact: please open in CoCalc
def albers(width, height, r, g, b, rangedeltar, rangedeltag, rangedeltab, seed): squares = [] # Saves the points in the final image. set_random_seed(seed) for i in range(width): for j in range(height): deltar = rangedeltar * random() deltag = rangedeltag * random() deltab = rangedeltab * random() if random() < 0.5: pm = 1 else: pm = -1 # Drawing rectangles by specifying 4 corners and a fill color 'rgbcolor' # First the two large ones squares.append(plot(polygon2d([[i+0,j+0],[i+0,j+1],[i+0.5,j+1],[i+0.5,j+0]], rgbcolor=(RGBValue(r - pm * deltar), RGBValue(g - pm * deltag), RGBValue(b - pm * deltab))))) squares.append(plot(polygon2d([[i+0.5,j+0],[i+0.5,j+1],[i+1,j+1],[i+1,j+0]], rgbcolor=(RGBValue(r + pm * deltar), RGBValue(g + pm * deltag), RGBValue(b + pm * deltab))))) # Then the small ones inside squares.append(plot(polygon2d([[i+0.15,j+0.15],[i+0.15,j+0.85],[i+0.35,j+0.85],[i+0.35,j+0.15]], rgbcolor=(r,g,b)))) squares.append(plot(polygon2d([[i+0.65,j+0.15],[i+0.65,j+0.85],[i+0.85,j+0.85],[i+0.85,j+0.15]], rgbcolor=(r,g,b)))) P = sum(squares) # normal size is figsize=4 show(P, aspect_ratio=1, svg=True, axes=False, xmin=-1, xmax=width+1, ymin=-1, ymax=height+1,figsize=8) save(P, os.path.join(SAGE_TMP, 'test.svg'), aspect_ratio=1, axes=False, xmin=-1, xmax=width+1, ymin=-1, ymax=height+1)
# Now you can make a larger piece by putting several of these smaller squares together. # Note the syntax: def albers(width, height, r, g, b, rangedeltar, rangedeltag, rangedeltab, seed): # This is the order you enter numbers into the function. #albers(4,4,0.2,0.6,0.8,0.05,0.1,0.1,52367) albers(8,8,0.5,0.5,0.5,0.25,0.25,0.25,168)