Create an art or image by yourself using arrays and Numpy
Creating art with NumPy involves using the NumPy library in Python to generate visual patterns, images, or designs. NumPy provides a powerful array manipulation library that allows for efficient handling and manipulation of multi-dimensional arrays.
Here’s a brief introduction to creating art with NumPy:
Overall, creating art with NumPy is a versatile and creative endeavor that leverages the power of numerical computation to generate visually appealing designs. It’s a popular approach for artists, data scientists, and hobbyists alike who want to explore the intersection of mathematics and art.
Let's dive into an art completely done with Numpy arrays,
Also, I have used OpenCV, Here is Why?
OpenCV (Open Source Computer Vision Library) primarily focuses on computer vision tasks like image processing, object detection, and more. While it’s not primarily designed for creating diagrams, it can be used in combination with other libraries to generate visual representations. Here are a few ways OpenCV can be used to create diagrams:
Custom Diagram Generation:
领英推荐
Art Image:
import cv2
import cvzone
import numpy as np
2. Art created using the arrays and Numpy
width = 400
height = 300
img = np.zeros((height, width, 3), np.uint8)
# Three vertices(tuples) of the triangle
p1 = (90, 90)
p2 = (50, 150)
p3 = (150, 150)
img[225:600] = [0, 242, 24]
img[0:150] = [235, 205, 125]
img[180:225]=[244,242,236]
cv2.circle(img, (300,80),30,(0,167,255),cv2.FILLED)
cv2.circle(img, (300,80),30,(0,167,255),cv2.FILLED)
#width,height
# Format: (startY:endY, startX:endX)
cv2.rectangle(img, (50,150), (150,230), (57,237,255),cv2.FILLED)
cv2.rectangle(img, (80,180), (115,230), (246,71,211),cv2.FILLED)
# Drawing the triangle with the help of lines
# on the black window With given points
# cv2.line is the inbuilt function in opencv library
cv2.line(img, p1, p2, (255, 0, 0), 3)
cv2.line(img, p2, p3, (255, 0, 0), 3)
cv2.line(img, p1, p3, (255, 0, 0), 3)
# finding centroid using the following formula
# (X, Y) = (x1 + x2 + x3//3, y1 + y2 + y3//3)
centroid = ((p1[0]+p2[0]+p3[0])//3, (p1[1]+p2[1]+p3[1])//3)
# Drawing the centroid on the window
cv2.circle(img, centroid, 0, (244, 233, 219),cv2.FILLED)
# image is the title of the window
cv2.imshow("image", img)
cv2.waitKey(10000)
cv2.destroyAllWindows()
Output:
Kubernetes, DevOps & Networking Expert | Solving Complex Infra Challenges | Building Scalable & Resilient Cloud Systems
1 年Nice work ??
Nice!? You might be interested in joining our platform, TheWide - a brand new social network for coders & developers. Connect, collaborate, exchange ideas, and *share code directly to your feed* ?? Also, it's totally FREE ??, so come check us out at https://thewide.com/ ?