看過藝術並想過,「是的,我可以製作類似的東西。」嗯,你並不孤單!如果你在網路上搜尋達明安·赫斯特的點畫,你的腦海中可能會出現類似的想法。今天我們將使用程式碼來測試這個理論。
我們正在嘗試使用 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中文網其他相關文章!