We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am getting this error : 1st arg can't be coerced to processing.core.PImage
I have three jpgs named img1, img2, img3.
img1=loadImage("pic1.jpg")
img2=loadImage("pic2.jpg")
img3=loadImage("pic3.jpg")`
The variable names are in a list.
list1=["img1","img2","img3"]`
I wanted to iterate through the list using a for loop and call each image in sequence to run a simple animation, but I continue to get the error.
for i in list1:
image(i, 100, 100)
Is this not possible with processing or is there a different way to make this work?
Answers
Not an expert in Py but your statement above reads like this:
image("img1",0,0);
which is not correct. I suggest you do this in setup:
list1=[loadImage("img1"),loadImage("img2"),loadImage("img3")]
Kf
ty you for trying, but that didn't seem to work.
Given your files are named in a number sequence, you should use a loop to loadImage() them all: *-:)
For more techniques, read on my Discourse post: ;)
https://Discourse.Processing.org/t/how-to-check-if-a-file-is-exist-in-data-folder-by-code/589/7
Ok, ty. That is kind of what I thought. I changed the code so now it is a LIST of images, instead of a tuple. I am stuck on seeing all of the images though, it seems to only show the last one in the sequence. I just want it to cycle through the images one at a time.
Dunno what you have against tuples... :o3 But for a comprehension list, there's a simpler syntax:
Wrap that all up w/ a pair of square brackets
[]
: :ar!The current content of the sketch's canvas is rendered to the window only after the callback draw() is returned! L-)
That's why we can't see the drawing happening as we issue drawing commands. We only see its last state. #-o
That's also why we call each draw() iteration an animation frame. @-)
Therefore, in order to see each PImage displayed on the canvas on a sequence, we're gonna need to call image() or set() for only 1 of them for each draw() iteration. :-B
Processing got a system variable called frameCount, which stores the number of times draw() had been called back: http://Py.Processing.org/reference/frameCount.html
We can use that together w/ the module
%
operator: http://Py.Processing.org/reference/modulo.htmlIn order to determine which index to use for each draw() iteration. *-:)
Also use frameRate() to slow down the FPS for draw(), so we can see each PImage on the canvas for a few milliseconds: :>
http://Py.Processing.org/reference/frameRate.html