spinning image question
in
Programming Questions
•
3 years ago
Hi, new to processing here. I want to do a spinning image effect. There are three images, each time there will be one image display in the window. Use mouse to move the image. If mouse move to left, the display sequence will be 1,3,2,1,3,2. Mouse to the right the sequence will be 1,2,3,1,2,3. Like an endless roll. My current problem is, as I'm using the mouseX and pmouseX to control the image postion. When the mouse come to the edge of the window and then come back to the middle od the window directly, the image will jump back. Which means there is an image will not display forever. Any ideas? Thanks.
PImage imgA, imgB, imgC;
String IMAGE_FILEA = "PastedGraphic-1.png"; //name of picture in data folder
String IMAGE_FILEB = "PastedGraphic-2.png"; //name of picture in data folder
String IMAGE_FILEC = "PastedGraphic-3.png"; //name of picture in data folder
int width=1400;
int height=300;
int imageWidth=1633;//image's width and height
int imageHeight=300;
int disR
int APosXP, APosXC;
int BPosXP, BPosXC;
int CPosXP, CPosXC;
int track;
void setup() {
size(1400,300);
imgA = loadImage(IMAGE_FILEA);
imgB = loadImage(IMAGE_FILEB);
imgC = loadImage(IMAGE_FILEC);
smooth();
APosXP=0;
BPosXP=APosXP+imageWidth;
CPosXP=BPosXP+imageWidth;
}
void draw() {
// background(255);
disR = mouseX-pmouseX;
APosXC = APosXP+disR;
BPosXP=APosXP+imageWidth+disR;
CPosXP=BPosXP+imageWidth+disR;
image(imgA,APosXC,0);
if(APosXP<(width-imageWidth))
{
image(imgB,BPosXC,0);
}
if(BPosXP<(width-imageWidth))
{
image(imgC,CPosXC,0);
}
if(APosXP>0)
{
image(imgC,APosXC-imageWidth,0);
}
if(BPosXP<(width-imageWidth))
{
image(imgC,CPosXC,0);
}
APosXP = APosXC;
}
1