ホームページ  >  記事  >  バックエンド開発  >  100万ポンド相当の絵画と同様のアートを作成する

100万ポンド相当の絵画と同様のアートを作成する

WBOY
WBOYオリジナル
2024-08-23 06:01:32812ブラウズ

Creating art similar to  million pounds worth of painting

Python と Turtle グラフィックを使用して 100 万ドルのダミアン ハーストの絵画を再作成

導入

概要

アートを見て、「ああ、これに似たものを作れそう」と思ったことはありませんか。そう、あなたは一人ではありません!ダミアン・ハーストのドット絵をオンラインで検索すると、同様の考えが頭をよぎるかもしれません。今日はコードを使用してこの理論をテストします。

客観的

私たちは、Python コードと Turtle グラフィック ライブラリを使用して、アーティストのダミアン ハーストによる人気のアートワークに似たアートを作成しようとしています。

インスピレーション

このブログ投稿は、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()

機能強化

さまざまなハーストの絵画から選択でき、そこから任意の数の色を抽出できるので、お気軽に自分で試して、どのような種類のアートワークが思いつくか確認してください。

結論

全体として、これは楽しいプロジェクトであり、プログラミング言語の基礎だけから実際のものを作成することがいかに簡単であるかを示しています。

以上が100万ポンド相当の絵画と同様のアートを作成するの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。