We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there, I'm trying to create someting like a Newsticker with Images, which I loaded into an array. I want to move the Pictures in an endless chain from the Top to the Bottom of the Window. But I don't know how to load or show them after another and tell them to show up at bottom when they disappear at the top... hope you understand my problem ;)
Here is what I have so far:
PImage[] thumbs = new PImage[6]; float x; float y;
void setup() { for (int i = 0; i < thumbs.length; i++) { thumbs[i] = loadImage("thumb"+i+".jpg"); } }
void draw() { background(0); y = y-3; for (int i = 0; i < thumbs.length; i++) { image(thumbs[i], x, y); }
Answers
Use modulo:
https://processing.org/reference/modulo.html
Decide how far you want to wrap -- maybe just beyond the height of the screen in both directions? That way no matter how far your ticker scrolls (
float y
), each image will appear at it wrapped (modulo) pixel location.Hm sorry, but I don't get what you mean...
Right now it works with one Image. I'm resetting the variable for y-coordinate to 0 if my Image reaches the Top of the Window. But now I want to do that with an array of Images, so that one after another is drawn in a line.
@jnspcl --
Given a strip of moving values, you want any values above the maximum length (images that scroll off the screen) to wrap back around to the minimum length. That is what Processing modulo is for -- it wraps things above the maximum back around to the minimum.
Here is an example based on your sketch that uses text to demonstrate. Notice that once you have a bunch of offsets, scrolling your list of objects up or down (or left or right) is just a matter of adding to 0 or subtracting from height (or width).
@jeremydouglass
Thank you, looks good. But when I try to adapt it to my case it doesn't work, maybe it's because I use a PImage Array?
What do you mean "it doesn't work"?
It doesn't move? The images don't load? You don't see the right thing on the screen? You get an error message? If so, what is that message? etc. etc.
You didn't copy the line correctly from the example.
You wrote:
y = the y offset, plus some spacing per image, plus the full height of the screen. That will always be off the edge of the screen!
You wanted:
y = the full height of the screen MINUS (the y offset plus some spacing per image). That will be on the screen (or close, depending on the thumbStripLength).
@jeremydouglass
oh yeah, I think it was a little bit too late for me yesterday... the minus is a good point ;) THANK YOU very much for your help! ^:)^