ランダムハートに色を塗りました
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import numpy as np | |
import random | |
import matplotlib as plt | |
from matplotlib import cm | |
from matplotlib import pylab as plt | |
sizex = 1000 | |
sizey = 1000 | |
en = np.zeros([sizex,sizey]) | |
han = np.zeros([sizex,sizey]) | |
for m in range(sizex): | |
for n in range(sizey): | |
seeds = random.randint(1,10000) | |
hsize = random.randint(10,70) | |
if seeds == 1: | |
en += np.fromfunction(lambda x,y: (x-m)**2+((y-n)-(abs(x-m))**0.95)**2 <hsize**2, (sizex,sizey)) | |
for m in range(sizex): | |
for n in range(sizey): | |
han[m][n]=en[n][sizex-1-m] | |
plt.imshow((han),cmap=cm.Reds) | |
plt.colorbar() | |
plt.savefig("heartt") |
せっかく❤マークを多用して可愛くしようとしていますが、理系的な(?)思考が身についていてグラフとかカラーバーとか無駄な情報を入れていますね
あとは解像度よくしたり均等にハートを作ってみたいです、今後の課題です。
from matplotlib import cm
from matplotlib import pylab as plt
#色とカラーバーをつけるのに新たなモジュールmatplotlibをインポートしました
plt.imshow((han),cmap=cm.Reds)
plt.colorbar()
plt.savefig("heartt")
#カラーマップRedsを使用、カラーバーをつけてセーブ 単純ですね
<<< Pythonプログラムでハート型をランダムにいっぱい描く❤
0 件のコメント:
コメントを投稿