fossunited / joy

Joy is a tiny creative coding library in Python.
MIT License
193 stars 19 forks source link

color transformations #16

Open anandology opened 3 years ago

anandology commented 3 years ago

Right now we can apply transformations on shapes, but there no way to generate patterns in color.

It would be nice to be able to specify a color range to repeat.

How about this?

c1 = color(r=255, g=0, b=0, a=0.5)
c2 = color(r=0, g=255, b=0, a=0.5)

ellipse() | repeat(36, rotate(10), fill=color_range(c1, c2), stroke="none")

This would apply colors from red to green to all the shapes.

The fill and stoke can also take a list of colors and it would cycle over the colors.

circle(x=100, y=0, r=25) | repeat(12, rotate(30), fill=['red', 'black'])

The same API could be applied to the combine function, which takes a list of shapes and converts into a single shape.

n = 6
d = 300/n
r = d/2
shapes = [circle(x=-150+r+i*d, y=0, r=r) for i in range(n)]
shape = combine(shapes, fill=['red', 'black'])
show(shape)

@amitkaps what do you think?

@vsrigayatri do you have any comments?

vsrigayatri commented 3 years ago

It look's good

On Fri, 16 Jul, 2021, 10:13 AM Anand Chitipothu, @.***> wrote:

Right now we can apply transformations on shapes, but there no way to generate patterns in color.

It would be nice to be able to specify a color range to repeat.

How about this?

c1 = color(r=255, g=0, b=0, a=0.5) c2 = color(r=0, g=255, b=0, a=0.5)

ellipse() | repeat(36, rotate(10), fill=color_range(c1, c2), stroke="none")

This would apply colors from red to green to all the shapes.

The fill and stoke can also take a list of colors and it would cycle over the colors.

circle(x=100, y=0, r=25) | repeat(12, rotate(30), fill=['red', 'black'])

The same API could be applied to the combine function, which takes a list of shapes and converts into a single shape.

n = 6 d = 300/n r = d/2 shapes = [circle(x=-150+r+i*d, y=0, r=r) for i in range(n)] shape = combine(shapes, fill=['red', 'black']) show(shape)

@amitkaps https://github.com/amitkaps what do you think?

@vsrigayatri https://github.com/vsrigayatri do you have any comments?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fossunited/joy/issues/16, or unsubscribe https://github.com/notifications/unsubscribe-auth/AU27MM7DR6ALB2P3ZG5AZ6TTX62GXANCNFSM5AO2MC5A .