I am working with Processing's rotate function.
I have a base image and then using image() I overlay two more smaller images on top.
I want to rotate image1 by x degrees and image2 by y degrees, but rotate only seems to be able to rotate both at the same time.
Is there a way around this? I thought of adding+rotating image1, saving the file, then adding+rotating image2 on top of the new file, but would prefer a more efficient way.
You can definitely rotate images by different amounts, without going through the extra step of saving any files.
Step 1: First, you need to translate() to the center of the images. If they're all the same size then that's easy, otherwise you'll have to translate() to each center before drawing each image.
Step 2: Then just rotate() however much you want for each image.
Step 3: Finally, draw the image.
Repeat that process for each image, and it should work fine. But keep in mind that translate() and rotate() calls stack, so if you call rotate(10) and then call rotate(15), that's like calling rotate(25). To avoid this, you might use the pushMatrix() and popMatrix() functions. As always, the Processing reference is your best friend.
If you're still stuck, please post an MCVE and we'll go from there. Good luck.
Related
I have an image.
I have several small functions of attributes of that image, that I'd like to overlay like a spark line into the image. Is there a straight forward way to do this?
Obviously, I could write my own graphing routines, to generate rasterized graphics objects, and overlay them on the image. I was hoping for something a bit more straight forward.
Here's what I'm looking for (roughly)
I = imread('cameraman.tif');
imshow(I);
figure(2);
plot(I(128,:));
* insert some magic here *
and generate output like the below. In this case, I'm plotting the grayscale values across the middle of the image. In general, I'll want to be able to put the sparkline plot anywhere in the image, with any orientation. But, this is getting generally to what I'm interested in achieving.
I drew multiple white pixels on a black canvas to get a night sky. I gave the stars random positions and now want that all pixels move down in-order to imitate the movement of the earth.
I tried Translate but that doesn't seem to work with pixels.
Is there a way to move all the Pixels in the canvas down?
arrayCopy(pixels, 0, pixels, width, (height - 1) * width);
Should solve the problem you have. For more help about arrayCopy look here: https://processing.org/reference/arrayCopy_.html
Basically, the process of creating an animation is this:
Store your state in variables, or in a buffer.
Use those variables to draw your scene every frame.
Change those variables over time to change your scene.
One approach is to draw your stars to a buffer. The createGraphics() function is your friend. Then draw that buffer to the screen using the image() function. Then move the y position of the buffer down by some amount each frame.
Another approach is to store your star positions in a set of variables, such as an ArrayList of PVector instances. Draw those positions to the screen, and move each one down a bit each frame.
The translate() function should work fine for points, and it's just another approach to the steps I outlined above. As is Tobias's answer. There are a bunch of different ways to do this. If you're still having trouble, please post a MCVE in a new question post. Good luck.
Shameless self-promotion: I wrote a tutorial on creating animations in Processing available here.
I'm developing a little videogame in which I have an infinite background image which moves horizontally. The image obviously is not infinite, it just finishes the same way it starts, so if I concatenate the image with itself, it seems is infinite.
The problem I'm having is that in the place where the two images join, a vertical black line appear. Looks like is not joining them in the exact position and I can see the black background.
I thought it was because the width of the images were not integers, but even if I superimpose one image over the other, the black vertical line still appear.
Any tips please?
What you are trying to do is called tiling. The image should be inherently 'tile-able'. To do this, put two copies of the image side by side, edges flush with each other and see if they are seamless.
Now then, to make things work in OpenGL, the simplest way might to make the quad (i.e. the mesh) holding your background pretty large and map this texture to a small part of this mesh (so that the image itself doesn't look stretched). Use the GL_REPEAT flag when texture mapping so the image is tiled across the entire large quad.
I want to do what they do in Minecraft and that is take a 2d item and make a it 3d.
This:
to this:
Anyone have idea how I would do this without making a model in a seperate program
Well, if you have proper images with a nice contrast to the background, you could try to read the image's pixel value and contrast and try to find the outline of those images. As a next step, you would use Three.Shape or Three.Path and trace the outline with LineTo. Afterwards, you use an ExtrudeGeometry and extrude the shape into a 3d-object.
The main problem is finding the outline, i guess. This would only work with proper images and depending on the quality you want to achieve, you will have to implement the proper algorithms, see edge detection filters maybe.
Or being very simplistic, read the pixel values, if they are white or close to white, ignore them and if they are not, Draw another line.... something like that...
I have several images of a rotating object. Each image shows a different angle. Now I want to let the user rotate the object with his or her fingers. This works but there aren't enough frames to show a smooth rotation. It's too jumpy.
I want to make it smoother and by that I probably need to generate more "steps", generate images of different missing angles. Is there an existing algorithm or technique I could use?
I think that if you try to interpolate pixel values temporaly between two consecutive images it would result in poor results but it might worth the try.
A more interesting approach would be to make a 3d estimation of your object using stereoscopic technics and then to project a synthetic view of the estimated scene at an intermediary position. For this to work, you will need to now the precise angle of the object at each frame. Occlusion is also an issue with stereoscopy.