Skip to content

Commit

Permalink
Edit more examples for doc and flake8 goodness
Browse files Browse the repository at this point in the history
  • Loading branch information
rlafuente committed May 7, 2018
1 parent 1464ebe commit b26a8d3
Show file tree
Hide file tree
Showing 22 changed files with 244 additions and 194 deletions.
88 changes: 40 additions & 48 deletions examples/libraries/color/colorlib_1.bot
Original file line number Diff line number Diff line change
@@ -1,110 +1,102 @@
size(450,450)
background(1,1,1)
"""
Colors library showcase 1
from the Nodebox colors library example (is it?)
"""

size(450, 450)
background(1, 1, 1)

colors=ximport("colors")
#print(dir(colors))

clr = colors.lab(78,29,37,1)
clr = colors.lab(78, 29, 37, 1)
clr1 = colors.named_color("olive")
clr2 = colors.mediumorchid()
clr3 = colors.named_color("#DD7100")
clr4 = colors.named_color("yellowy")
clr5 = clr3.blend(clr4,0.5)
clr5 = clr3.blend(clr4, 0.5)
clr6 = colors.complement(clr5)[1]
clr7 = colors.silver()

if clr7.is_gray:
print("yes, it's gray")
else:
print("no, no gray here")

if clr7.is_transparent:
print("yes, you can see through")
else:
print("no, opaque")


clr6.swatch(200,40,20,20)
clr5.swatch(222,40,20,20)
clr6.swatch(200, 40, 20, 20)
clr5.swatch(222, 40, 20, 20)

colori = colors.list(clr, clr1, clr2, clr3, clr4, clr5, clr6, clr7)
print colori




print(colori)

#draw test
# draw test
fill(clr)
circle(50,40,40)
circle(50, 40, 40)
fill(colors.complement(clr)[1])
circle(90,40,40)
circle(90, 40, 40)
fill(clr1)
circle(90,80,40)
circle(90, 80, 40)
fill(colors.complement(clr1)[1])
circle(130,80,40)
circle(130, 80, 40)
fill(clr2)
circle(130,120,40)
circle(130, 120, 40)
fill(colors.complement(clr2)[1])
circle(170,120,40)
circle(170, 120, 40)
fill(clr3)
circle(170,160,40)
circle(170, 160, 40)
fill(colors.complement(clr3)[1])
circle(210,160,40)
circle(210, 160, 40)
fill(clr4)
circle(210,200,40)
circle(210, 200, 40)
fill(colors.complement(clr4)[1])
circle(250,200,40)
circle(250, 200, 40)
fill(clr5)
circle(250,240,40)
circle(250, 240, 40)
fill(colors.complement(clr5)[1])
circle(290,240,40)
circle(290, 240, 40)
fill(clr6)
circle(290,280,40)
circle(290, 280, 40)
fill(colors.complement(clr6)[1])
circle(330,280,40)
circle(330, 280, 40)
fill(clr7)
circle(330,320,40)
circle(330, 320, 40)
fill(clr7.darken(step=0.4))
circle(370,320,40)
circle(370, 320, 40)

x=0
x = 0
for colore in colori:
fill(colore)
rect(x,0,20,20)
rect(x, 0, 20, 20)
x += 20
x += 20
for colore in colori.darken(step=0.1):
fill(colore)
rect(x,0,20,20)
rect(x, 0, 20, 20)
x += 20
x += 20
fill(colori.average)
rect(x,0,20,20)
rect(x, 0, 20, 20)
x += 20
fill(colori.darken(step=0.1).average)
rect(x,0,20,20)
rect(x, 0, 20, 20)

#color triad
# color triad
triade = colors.triad(clr3, angle=120)
x = 200
for colore in triade:
fill(colore)
rect(x,80,20,20)
rect(x, 80, 20, 20)
x += 20

triade = colors.triad(clr4, angle=120)
x = 260
for colore in triade:
fill(colore)
rect(x,120,20,20)
rect(x, 120, 20, 20)
x += 20






#colori.swarm(100,50)


# colori.swarm(100, 50)
14 changes: 9 additions & 5 deletions examples/libraries/color/colorlib_2.bot
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"""
Colors lib visual showcase
"""

size(450,450)
background(1,1,1)
colors = ximport("colors")

size(450, 450)
background(1, 1, 1)

colors=ximport("colors")

clr8 = colors.rgb(0.0, 0.4, 0.6)
x = 10
for name in colors.rules:
scheme = colors.rule(name, clr8)
scheme.swatch(x, 10)
x += 40
fill(0.0,0.4,0.6)
rect(300,200,70,70)
fill(0.0, 0.4, 0.6)
rect(300, 200, 70, 70)
23 changes: 14 additions & 9 deletions examples/libraries/color/gradient_list.bot
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# GRADIENT LIST
"""
Gradient list
from the Nodebox color library examples

Make a list of colors to replicate a gradient effect.
"""

colors = ximport("colors")

Expand All @@ -16,11 +21,11 @@ g = colors.gradient(clr1, clr2, steps=60)
# this way we get a radial gradient.
for i in range(len(g)):
fill(g[i])
r = 700-i*10
oval(-75+i*5, -170+i*5, r, r)
r = 700 - i * 10
oval(-75 + i * 5, -170 + i * 5, r, r)

# Some nice dropshadows.
#colors.shadow(blur=12, alpha=0.3)
# colors.shadow(blur=12, alpha=0.3)

# Expand the gradient list, for the next element
# we're going to need more than 60 colors.
Expand All @@ -31,18 +36,18 @@ g = g.reverse()

# Draw a spiral of ovals for each of the 200 gradient steps:
transform(CORNER)
translate(WIDTH/2, HEIGHT/2)
translate(WIDTH / 2, HEIGHT / 2)
for i in range(len(g)):
fill(g[i])
#fill(choice(g))
# fill(choice(g))
rotate(3)
oval(i*0.5, i*0.5, 200-i, 200-i)
oval(i * 0.5, i * 0.5, 200 - i, 200 - i)

reset()

# All of the colors in the gradient:
i = 0
for x, y in grid(10, len(g)/10, 10, 10):
for x, y in grid(10, len(g) / 10, 10, 10):
if i < len(g):
fill(g[i])
rect(x, y, 8, 8)
Expand Down
22 changes: 12 additions & 10 deletions examples/libraries/color/hair.bot
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# COLOR LIST FROM PIXELS
"""
Color list from pixels
from the Nodebox colors library examples
"""

colors = ximport("colors")

Expand All @@ -7,32 +10,31 @@ nofill()
stroke(0.4, 0.5, 0)
strokewidth(0.1)
autoclosepath(False)

clr = colors.rgb(0.6, 0.4, 0, 0.5)

background(colors.dark(clr).darken(0.1))
#colors.shadow(alpha=0.05, blur=0.2)
# colors.shadow(alpha=0.05, blur=0.2)

for i in range(50):

# Each strand of curves has an analogous color
# (i.e. hues that are next to each other on the color wheel).
# This yields a very natural effect.
stroke(clr.analog(angle=10, d=0.3))

x0 = WIDTH / 2
y0 = HEIGHT / 2
vx0 = random(-200, 200)
vy0 = random(-200, 200)
vx1 = random(-200, 200)
vx1 = random(-200, 200)
vy1 = random(-200, 200)
x1 = choice((-10, WIDTH))
y1 = random(HEIGHT)
for j in range(100):
beginpath(x0, y0)
curveto(
x0+vx0+random(80), y0+vy0+random(80),
x1+vx1, y1+vy1,
x0 + vx0 + random(80), y0 + vy0 + random(80),
x1 + vx1, y1 + vy1,
x1, y1
)
endpath()
30 changes: 16 additions & 14 deletions examples/libraries/color/hair_shadow.bot
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# blonde hairy example from nodebox website
"""
Alternative to hair.bot so that the shadow works
"""

colors = ximport("colors")

Expand All @@ -7,37 +9,37 @@ nofill()
stroke(0.4, 0.5, 0)
strokewidth(0.1)
autoclosepath(False)

clr = colors.rgb(0.6, 0.4, 0, 0.5)

background(colors.dark(clr).darken(0.1))
#colors.shadow(alpha=0.05, blur=0.2)
# colors.shadow(alpha=0.05, blur=0.2)

for i in range(50):

# Each strand of curves has an analogous color
# (i.e. hues that are next to each other on the color wheel).
# This yields a very natural effect.
clr1=(clr.analog(angle=10, d=0.3))
x0 = WIDTH/2
y0 = HEIGHT/2
clr1 = (clr.analog(angle=10, d=0.3))

x0 = WIDTH / 2
y0 = HEIGHT / 2
vx0 = random(-200, 200)
vy0 = random(-200, 200)
vx1 = random(-200, 200)
vx1 = random(-200, 200)
vy1 = random(-200, 200)
x1 = choice((-10, WIDTH))
y1 = random(HEIGHT)
for j in range(100):
beginpath(x0, y0)
curveto(
x0 + vx0 + random(80), y0 + vy0 + random(80),
x1 + vx1, y1 + vy1,
x0 + vx0 + random(80), y0 + vy0 + random(80),
x1 + vx1, y1 + vy1,
x1, y1
)
p = endpath(draw=False)
push()
translate(8,8)
translate(8, 8)
stroke(0, 0, 0, 0.3)
drawpath(p.copy())
pop()
Expand Down
19 changes: 11 additions & 8 deletions examples/libraries/color/rules.bot
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# COLOR RULES
size(600,600)
background(1,1,1)
"""
Color rules
"""

colors = ximport("colors")

size(600, 600)
background(1, 1, 1)

var("H", NUMBER, 0.55, 0.0, 1.0)
var("S", NUMBER, 1.0, 0.0, 1.0)
var("B", NUMBER, 0.6, 0.0, 1.0)
Expand All @@ -13,13 +16,13 @@ x = 10
y = 30

for name in colors.rules:

transform(CORNER)
translate(x, y)
rotate(-90)
push()
fill(0,0,0)
text(name, x+45, 250-x, fontsize=14)
fill(0, 0, 0)
fontsize(14)
text(name, x + 45, 250 - x)
pop()
reset()

Expand All @@ -29,5 +32,5 @@ for name in colors.rules:

# Each of the names in colors.rules
# is also a command in the library, try out:
#scheme = colors.right_complement(clr)
#scheme.swarm(50,50)
# scheme = colors.right_complement(clr)
# scheme.swarm(50, 50)
8 changes: 6 additions & 2 deletions examples/libraries/color/shades.bot
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""
Color shades
"""

colors = ximport("colors")

var("hue", NUMBER, 0.8, 0.0, 1.0)
clr = colors.hsb(hue, 1, 1)

Expand All @@ -8,7 +12,7 @@ y = 20
for shade in colors.shades:
fill(0)
fontsize(12)
text(str(shade), x, y-5)
text(str(shade), x, y - 5)
snapshot = shade.colors(clr, 10)
snapshot.swatch(x, 20, padding=5)
y = 20
Expand Down

0 comments on commit b26a8d3

Please sign in to comment.