Python Pygame Draw Pixel

  

  1. Draw An Arc In Python Pygame
  2. Python Pygame Code
  3. Pygame Draw A Triangle With Lines
  4. Python Pygame Draw Pixel Art
  5. Python Pygame Draw Pixels
Active2 months ago

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).

ashurashur

PyGame 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.

1,57811 gold badges38 silver badges65 bronze badges

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 Latty
67.4k12 gold badges139 silver badges157 bronze badges

One way of doing that is to draw a line staring and ending at the same point.

Soviut
60.8k37 gold badges150 silver badges215 bronze badges
Orestis ZekaiOrestis Zekai

Not 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.

Python Pygame Draw PixelSign up New issue

Draw 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

  • Bitbucket: https://bitbucket.org/pygame/pygame/issue/234

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 draw.lines, just polygon be the filled version of it. (In fact, when we call polygon with width>0 , we call directly lines in the code.

Also it seems difficult to be consistent with range when we think of triangle, diamond, ... all shapes where some sides are neither parallel to x-axis nor to y-axis

pushed a commit to e1000/pygame that referenced this issue Aug 30, 2018
Python
Merged
pushed a commit to e1000/pygame that referenced this issue Aug 30, 2018

Python Pygame Draw Pixels

closed this in #515Sep 3, 2018

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment