首页  >  文章  >  后端开发  >  创造类似于价值百万英镑的绘画的艺术

创造类似于价值百万英镑的绘画的艺术

WBOY
WBOY原创
2024-08-23 06:01:32923浏览

Creating art similar to  million pounds worth of painting

使用 Python 和 Turtle Graphics 重新创作价值百万美元的达明安·赫斯特 (Damien Hirst) 画作

介绍

概述

看过艺术并想过,“是的,我可以制作类似的东西。”嗯,你并不孤单!如果你在网上搜索达明安·赫斯特的点画,你的脑海中可能会出现类似的想法。今天我们将使用代码来测试这个理论。

客观的

我们正在尝试使用 Python 代码和 Turtle 图形库来创作与艺术家 Damien Hirst 的流行艺术作品类似的艺术作品。

灵感

这篇博文的灵感来自 Angela Yu 的 Python 课程。

设置环境

我们需要在系统上安装Python(最新版本更好)、Turtle 图形库(安装 Python 时预装)、Colorgram 库(必须使用 pip 安装)和您最喜欢的 IDE .

理解艺术

赫斯特的艺术由相同大小的对称色点图案组成,并由一致的空间分隔。
看起来很简单,可以模仿。那么让我们开始吧。

编码绘画

创建画布:

#We import the Turtle library and give it an alias as t
import turtle as t

#We create an object of the Turtle class and name it bob
bob = t.Turtle()

#We create a screen that will be our canvas which our turtle (bob)  #will draw the painting on
screen = t.Screen()

#To make the screen persistent we add the following line of code that #makes sure that the screen stays till we click on it.
screen.exitonclick()

提取颜色:
您可以从此链接安装颜色图库。

#Import the colorgram library
import colorgram

#Make a list that will store the colors extracted from a sample #Damien Hirst painting.
rgb_colors = []

#Extract the colors from the painting. You can choose how many colors #to extract, here 30 is chosen.
colors = colorgram.extract('image.jpg', 30)

#The output is a list of colorgram object of RGB values. We select #the RGB values from them.
for color in colors:
    r = color.rgb.r
    g = color.rgb.g
    b = color.rgb.b
    new_color = (r, g, b)
    rgb_colors.append(new_color)

print(rgb_colors)

#After we get the output, we can select the color list from the #terminal, store them into a variable like below, and comment the #above code.
color_list = [(245, 243, 238), (202, 164, 110), (240, 245, 241), (149, 75, 50), (222, 201, 136), (53, 93, 123), (170, 154, 41), (138, 31, 20), (134, 163, 184), (197, 92, 73), (47, 121, 86), (73, 43, 35), (145, 178, 149), (14, 98, 70), (232, 176, 165), (160, 142, 158), (54, 45, 50), (101, 75, 77), (183, 205, 171), (36, 60, 74), (19, 86, 89), (82, 148, 129), (147, 17, 19), (27, 68, 102), (12, 70, 64), (107, 127, 153), (176, 192, 208), (168, 99, 102)]

绘制图案:

#Importing random module to randomly choose colors from color list
import random

# Since we are using RGB we set the colormode to 255 as there are 0 #to 255 values of RGB.
t.colormode(255)

#For better visualization we speed up the drawing process
bob.speed("fastest")

#by default our pen draws a line, we penup to avoid that
bob.penup()

# Going to an appropriate place in the canvas to draw all the dots in #the visible area
bob.setheading(220)
bob.forward(300)

#Setting the heading in right direction to draw the dots
bob.setheading(0)
number_of_dots = 100

#drawing dots of size 20 at a distance of 50 from each other of a #random color from the color list. After every 10 dots we go the next #line
for dots in range(1, number_of_dots + 1):
    bob.dot(20, random.choice(color_list))
    bob.forward(50)

    if dots % 10 == 0:
        bob.setheading(90)
        bob.forward(50)
        bob.setheading(180)
        bob.forward(500)
        bob.setheading(0)

#hiding our drawing pen
bob.hideturtle()

增强功能

现在有各种赫斯特的画作可供选择,我们可以从中提取任意数量的颜色,所以请随意尝试一下,看看你能想出什么样的艺术品!

结论

总的来说,这是一个有趣的项目,并展示了仅从编程语言的基础知识创建真实的东西是多么容易。

以上是创造类似于价值百万英镑的绘画的艺术的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn