Skip to content

Commit

Permalink
Refactored image.py and load_pixels (#383)
Browse files Browse the repository at this point in the history
* Refactored image.py to support image apis for different rendering backends.
load_pixels is no longer a context manager as it was different than p5.js and update_pixel is implemented

* Make PImage an abstract class

* Use renderer specific PImage in each renderer

* Update docs

* Format using black

* Use self instead of instance.
  • Loading branch information
tushar5526 authored Aug 29, 2022
1 parent a0f1a04 commit 1a5289e
Show file tree
Hide file tree
Showing 9 changed files with 632 additions and 448 deletions.
2 changes: 1 addition & 1 deletion docs/examples/image/alpha mask.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Loads a "mask" for an image to specify the transparency in different parts of th
def draw():
global img
background(0, 102, 153)
image(img, (width / 2, height / 2))
image(img, width / 2, height / 2)
image(img, mouse_x, mouse_y)
if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/image/load and display image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ Images can be loaded and displayed to the screen at their actual size or any oth
def draw():
global img
background(0)
image(img, (0, 0))
image(img, (0, height / 2), (img.width / 2, img.height / 2))
image(img, 0, 0)
image(img, 0, height / 2, img.width / 2, img.height / 2)
if __name__ == '__main__':
run()
4 changes: 2 additions & 2 deletions docs/examples/image/transparency.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ Move the pointer left and right across the image to change its position. This pr
def draw():
global img, offset, easing
image(img, (0, 0)) #Display at full opacity
image(img, 0, 0) #Display at full opacity
dx = mouse_x - img.width / 2 - offset
offset += dx * easing
tint(255, 127)
image(img, (offset, 0))
image(img, offset, 0)
if __name__ == '__main__':
run()
2 changes: 1 addition & 1 deletion docs/tutorials/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ The following code retrieves both the running time and movie poster iamge from I
global poster, runningtime
# Display all the stuff I want to display
background(255)
image(poster, (10, 10), 164, 250)
image(poster, 10, 10, 164, 250)
fill(0)
text("Shaun the Sheep", (10, 300))
text(runningtime, (10, 320))
Expand Down
14 changes: 7 additions & 7 deletions docs/tutorials/images and pixels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ In addition to user-defined objects (such as Ball), Processing has a bunch of ha
def draw():
background(0)
# Draw the image to the screen at coordinate (0,0)
image(img, (0, 0))
image(img, 0, 0)
if __name__ == '__main__':
run()
Expand Down Expand Up @@ -64,7 +64,7 @@ Once the image is loaded, it is displayed with the ``image()`` function. The ``i

.. code:: python
image(img, (10,20), (90,60))
image(img, 10,20, 90,60)
Your very first image processing filter
=======================================
Expand All @@ -88,7 +88,7 @@ If ``tint()`` receives one argument, only the brightness of the image is affecte
# The image retains its original state.
tint(255)
image(sunflower, (0, 0))
image(sunflower, 0, 0)
.. image:: ./images_and_pixels-res/tint2.jpg
:align: left
Expand All @@ -97,7 +97,7 @@ If ``tint()`` receives one argument, only the brightness of the image is affecte
# The image appears darker
tint(100)
image(sunflower, (0, 0))
image(sunflower, 0, 0)
A second argument will change the image's alpha transparency.

Expand All @@ -108,7 +108,7 @@ A second argument will change the image's alpha transparency.
# The image is at 50% opacity.
tint(100, 127)
image(sunflower, (0, 0))
image(sunflower, 0, 0)
Three arguments affect the brightness of the red, green, and blue components of each color.

Expand All @@ -119,7 +119,7 @@ Three arguments affect the brightness of the red, green, and blue components of
# None of its red, most of its green, and all of its blue.
tint(0, 200, 255)
image(sunflower, (0, 0))
image(sunflower, 0, 0)
Finally, adding a fourth argument to the method manipulates the alpha (same as with 2). Incidentally, the range of values for tint() can be specified with colorMode().

Expand All @@ -130,7 +130,7 @@ Finally, adding a fourth argument to the method manipulates the alpha (same as w
# The image is tinted red and transparent.
tint(255, 0, 0, 100)
image(sunflower, (0, 0))
image(sunflower, 0, 0)
Pixels, pixels, and more pixels
===============================
Expand Down
Loading

0 comments on commit 1a5289e

Please sign in to comment.