No Result
View All Result
DevRescue
  • Home
  • Python
  • Lists
  • Movies
  • Finance
  • Opinion
  • About
  • Contact Us
  • Home
  • Python
  • Lists
  • Movies
  • Finance
  • Opinion
  • About
  • Contact Us
DevRescue
Home Blog Python

Coca-Cola Logo Pixel Art in Python

by Khaleel O.
May 24, 2022
in Python
Reading Time: 4 mins read
A A
python pixel art logo coca-cola
python pixel art logo coca-cola

Hi! Let’s recreate the iconic Coca-Cola brand logo as Pixel Art in Python 3. Let’s go! ✨🔥⚡

Coca-Cola is a fizzy drink created in the late 19th Century in the USA. It is very popular and continues to sell very well around the world. In this tutorial we will use the turtle library to achieve our aim. Let’s write some code!

from turtle import Screen, Turtle

PIXEL_SIZE = 10
CURSOR_SIZE = 20

COLORS = {
    'R': 'red',
    'W': 'white',
}

PIXELS = [
    "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
    "RRRRRRRRRRRRRRRWWWWRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRWWRRRRWWWWWWWRRRRRRRRRRWWWRRRRRR",
    "RRRRRRRRRRRRRWWWWWWWRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRWWWWWWWWWWWWWWWWWRRRRRRWWWWWRRRRWR",
    "RRRRRRRRRRRWWWWWRRWWRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRWWWWWRRWWRRRWWWWWWWWRRRRWWWRRWRRWWRR",
    "RRRRRRRRRRWWWWWRRWWWRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRWWWWWRRWRRRRRRRWWWWWWWRRWWWRRRRRWWWRR",
    "RRRRRRRRRWWWWWRRRWWWRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRWWWWWRRRRRWRRRRRRRWWWWWRWWWRRRWWWWWRRR",
    "RRRRRRRRWWWWWRRRRWWRRRRRRRRRRRRRRRRRR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R",
    "RRRRWWWWWWWWWWWWRRRRRRRRRRRRRWWWWWWWWWWWRRRRRWWWWWWWRRRRRRWWWWRRRRRWWWWWRWWWWRWWWWRRRRWWWRR",
    "RRRRRRWWWWWWRRRRRRRRRRRRRRRRRRWRRRRRRRWWWRRRRRWWWWRRRRRRRRRWRRRRRRRRWWRRRRWWRRRWRRRRRWWWWRR",
    "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
]


WIDTH, HEIGHT = len(PIXELS[0]), len(PIXELS)

screen = Screen()
screen.setup((WIDTH + 3) * PIXEL_SIZE, (HEIGHT + 3) * PIXEL_SIZE)
screen.tracer(False)

turtle = Turtle()
turtle.hideturtle()
turtle.shape('square')
turtle.shapesize(PIXEL_SIZE / CURSOR_SIZE)
turtle.penup()

x0 = -WIDTH/2 * PIXEL_SIZE
y0 = HEIGHT/2 * PIXEL_SIZE

for i, row in enumerate(PIXELS):
    turtle.setposition(x0, y0 - i * PIXEL_SIZE)

    for pixel in row:
        turtle.color(COLORS[pixel])
        turtle.stamp()
        turtle.forward(PIXEL_SIZE)

screen.tracer(True)
screen.exitonclick()

Let’s explain what is happening here:

  1. First we import the Screen and Turtle subclass of the turtle library. This the library that will be responsible for drawing and rendering our Coca-Cola logo.
  2. We define two variables:
    • PIXEL_SIZE: This is the size each individual pixel of the image to be drawn. We try to keep this relatively small so our image doesn’t end up too large.
    • CURSOR_SIZE: In turtle, the cursor is usually a small turtle shape. This variable will be used to define the size of that cursor. The image will be drawn quickly so we won’t actually be able to see the drawing turtle cursor.
  3. We define the COLORS dictionary for the colors to be used in the drawing. For this pixel art, we are only using two colors: RED = R and WHITE = W. We define our colors like this because we can then easily color our drawing depending if an R or a W is presented at render time.
  4. The PIXELS list object is the centerpiece of our art. It actually contains the raw pixel data in list form. It has 31 elements with each element being 91 characters long. Each character of each element is either an R or a W depending on what color we want represented. The difference in color is how we will be able actually see the letters of the logo.
  5. There is a nifty online tool which you can find HERE that will help you to convert images into pixel values. It has two modes: black and white (1 and 0) or color mode (0-255). Once you select a suitable image and process it with the tool to obtain the pixel values, you can do a simple find and replace to insert the color values. Be creative and use as many colors as possible in your work!
  6. The Screen() object screen defines the graphics window. We use the previously defined PIXEL_SIZE, WIDTH and HEIGHT of our PIXELS list as parameters in the setup() method to determine the actual size and position of main window to be presented.
  7. The screen.tracer() method allows us to turn the turtle animation on or off. If turned off or set to False our pixel art will be presented without delay. If True we will have to wait for the turtle to draw the pixel art from top to bottom.
  8. We define the Turtle() object that will actually do the drawing of the pixel art in the main window. We set the shape, size and hide the cursor from view.
  9. The turtle will start drawing at the upper left hand corner of the window and move to the right until it reaches the end, then it moves to the line below and repeats the process until it reaches the bottom of the window and the drawing is complete.

If all goes well, when we execute our code we will have a new window pop up with the complete Coca-Cola logo in red with white letters (see below):

python pixel art logo coca-cola
Finished Logo Pixel Art

We hope you enjoyed this tutorial. Keep on coding! 👌👌👌

Tags: logopixel artturtle
Previous Post

Screenshot including Mouse Pointer with Python

Next Post

Convert RGB Values to CSS3 Color Names in Python

Khaleel O.

Khaleel O.

I love to share, educate and help developers. I have 14+ years experience in IT. Currently transitioning from Systems Administration to DevOps. Avid reader, intellectual and dreamer. Enter Freely, Go safely, And leave something of the happiness you bring.

Related Posts

Python

Python Fibonacci Recursive Solution

by Khaleel O.
January 16, 2024
0
0

Let's do a Python Fibonacci Recursive Solution. Let's go! 🔥🔥🔥 The Fibonacci sequence is a series of numbers in which...

Read moreDetails
Python

Python Slice String List Tuple

by Khaleel O.
January 16, 2024
0
0

Let's do a Python Slice string list tuple how-to tutorial. Let's go! 🔥🔥🔥 In Python, a slice is a feature...

Read moreDetails
Python

Python Blowfish Encryption Example

by Khaleel O.
January 14, 2024
0
0

Let's do a Python Blowfish Encryption example. Let's go! 🔥 🔥 Blowfish is a symmetric-key block cipher algorithm designed for...

Read moreDetails
Python

Python Deque Methods

by Khaleel O.
January 14, 2024
0
0

In this post we'll list Python Deque Methods. Ready? Let's go! 🔥🔥🔥 A deque (double-ended queue) in Python is a...

Read moreDetails

DevRescue © 2021 All Rights Reserved. Privacy Policy. Cookie Policy

Manage your privacy

To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.

Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Manage options
  • {title}
  • {title}
  • {title}
Manage your privacy
To provide the best experiences, DevRescue.com will use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Manage options
  • {title}
  • {title}
  • {title}
No Result
View All Result
  • Home
  • Python
  • Lists
  • Movies
  • Finance
  • Opinion
  • About
  • Contact Us

DevRescue © 2022 All Rights Reserved Privacy Policy