The Joy of Programming
Generative Art
There is no preview available for this lesson. Please join the course to access it. Click here to enroll.
Questions
answer for 8.6
JE Joswin Emmanuel
3 years ago
Post
Dismiss
coord=[-125,-75,-25,25,75,125] for i in coord: for j in coord: for _ in range(10): n=random(40) show(rectangle(i,j,n,n))
coord=[-125,-75,-25,25,75,125] for i in coord: for j in coord: for _ in range(10): n=random(40) show(rectangle(i,j,n,n))
DP Dhanush P N
3 years ago
Post
Dismiss
##8.5 ```python def make_shape(width): if random(1) < 0.5: return circle(r=width/2) + ellipse(w=width/2, h=width) else: return circle(r=width/2) + ellipse(w=width, h=width/2) ```
##8.5 ```python def make_shape(width): if random(1) < 0.5: return circle(r=width/2) + ellipse(w=width/2, h=width) else: return circle(r=width/2) + ellipse(w=width, h=width/2) ```
DP Dhanush P N
3 years ago
Post
Dismiss
##8.6 ```python def make_shape(width): return random_concentric_squares(n=10, max_size=width) def random_concentric_squares(n, max_size): shapes = [] for i in range(n): s = random(max_size) c = rectangle(w=s, h=s) shapes.append(c) return combine(shapes) ```
##8.6 ```python def make_shape(width): return random_concentric_squares(n=10, max_size=width) def random_concentric_squares(n, max_size): shapes = [] for i in range(n): s = random(max_size) c = rectangle(w=s, h=s) shapes.append(c) return combine(shapes) ```
NF Niya Farhaan
3 years ago
Post
Dismiss
here's a nice pattern def make_grid(n): width = 300 d = width/n xstart = -width/2 + d/2 ystart = width/2 - d/2 shapes = [] for i in range(n): for j in range(n): x = xstart + d*j y = ystart - d*i shape = make_shape(d)|translate(x=x, y=y) shapes.append(shape) return combine(shapes) def make_shape(width): r=random(1) if r < 0.5: return random_concentric_squares(n=10, max_side=width*0.8) else: return random_concentric_circles(n=10, max_radius=width*0.8/2) def random_concentric_squares(n, max_side): shapes = [] for i in range(n): w = random(max_side) h=w c = rectangle(w=w,h=h) shapes.append(c) return combine(shapes) def random_concentric_circles(n, max_radius): shapes = [] for i in range(n): r = random(max_radius) c = circle(r=r) shapes.append(c) return combine(shapes) shape = make_grid(6) show(shape)
here's a nice pattern def make_grid(n): width = 300 d = width/n xstart = -width/2 + d/2 ystart = width/2 - d/2 shapes = [] for i in range(n): for j in range(n): x = xstart + d*j y = ystart - d*i shape = make_shape(d)|translate(x=x, y=y) shapes.append(shape) return combine(shapes) def make_shape(width): r=random(1) if r < 0.5: return random_concentric_squares(n=10, max_side=width*0.8) else: return random_concentric_circles(n=10, max_radius=width*0.8/2) def random_concentric_squares(n, max_side): shapes = [] for i in range(n): w = random(max_side) h=w c = rectangle(w=w,h=h) shapes.append(c) return combine(shapes) def random_concentric_circles(n, max_radius): shapes = [] for i in range(n): r = random(max_radius) c = circle(r=r) shapes.append(c) return combine(shapes) shape = make_grid(6) show(shape)
NF Niya Farhaan
3 years ago
Post
Dismiss
ok that backfired
ok that backfired
KL Khadeeja lubaba
3 years ago
Post
Dismiss
Exercise 8.5?
Exercise 8.5?
Want to discuss?
Post it here, our mentors will help you out.