- Draw An Arc In Python Pygame
- Python Pygame Code
- Pygame Draw A Triangle With Lines
- Python Pygame Draw Pixel Art
- Python Pygame Draw Pixels
I'm looking for method that allow me to draw single pixel on display screen. For example when I click mouse, I want the position of clicked pixel to change color. I know how to read mouse pos, but I could not find simple pixel draw ( there is screen.fill method but it's not working as I want).
ashurashurPyGame Drawing Basics Getting Started. You must do the following to get started with Pygame: import pygame import sys pygame.init() Strictly speaking, import sys is not needed for PyGame, but as we'll see later, to be able to use the 'close window' button on Windows or Mac, we'll need to use sys.exit(), so it is helpful. I am doing some pixel operations in Python, which obviously uses a lot of processing power and makes the program extremely slow. Drawing pixel to pixel. Checking surrounding pixels inefficiently in pygame. Loops through each row in a binary image and gets the width of each group of black or white pixels. Hot Network Questions Why.
2 Answers
You can do this with surface.set_at()
:
You can also use pygame.gfxdraw.pixel()
:
Do note, however, the warning:
EXPERIMENTAL!: meaning this api may change, or dissapear in later pygame releases. If you use this, your code will break with the next pygame release.
You could use surface.fill()
to do the job too:
You can also simply draw a line with the start and end points as the same:
Gareth LattyGareth LattyOne way of doing that is to draw a line staring and ending at the same point.
SoviutNot the answer you're looking for? Browse other questions tagged pythonpygame or ask your own question.
Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upDraw An Arc In Python Pygame
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
commented Feb 15, 2015
Originally reported by: donLorenzo (Bitbucket: donLorenzo, GitHub: donLorenzo) Reported by Florian Krause on the pygame mailing list: note that the simple example: yields a 4x4 rect
|
commented Feb 15, 2015
Python Pygame Code
Original comment bydonLorenzo (Bitbucket: donLorenzo, GitHub: donLorenzo): I guess the first step in resolving this issue is to clarify what the desired behaviour is. For example: Should the polygon ([0, 0], [3, 0], [3, 3], [0, 3]) really be a 4x4 square or should it be 3x3 ? IMHO it should be 3x3 which would be analogue to how C for-loops or python ranges handle their bounds and the same arguments apply. Mainly, that two polygons sharing an edge should not overlap. Any opinions? |
commented Mar 16, 2015
Pygame Draw A Triangle With Lines
Original comment byFlorian Krause (Bitbucket: fladd, GitHub: fladd): I agree. |
commented Jul 9, 2015
Original comment byJason Marshall (Bitbucket: jmm0, GitHub: jmm0): If I were designing pygame.draw.polygon, I would make it fill in every point that I pass to it when the width argument is 0. This is what pygame.draw.polygon does when the width argument is 1. So, I would expect the polygon ([0, 0], [3, 0], [3, 3], [0, 3]) to always be 4x4. (The analogy with C for-loops and Python ranges stops making sense to me when I consider polygons that aren't rectangular.) However, it is much more important that it draw consistently in both the x direction and the y direction. Whether that polygon is 3x3 or 4x4 is just a personal preference. pygame.gfxdraw.filled_polygon draws in the same way as pygame.draw.polygon (with a width argument of 0). I made the following little script to play with the polygon functions. It may be useful to somebody. |
added this to the 1.9.x milestone Mar 26, 2017
Python Pygame Draw Pixel Art
commented Aug 29, 2018
For me, it should be consistent with Also it seems difficult to be consistent with |