I am making an animation using Processing 3, I would like to know how can I switch screen smoothly?
each screen contains different images.
Also, if for example, I would like an image to appear at the end, how can I do that, is it to do with time?
Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. You need to break your problem down into smaller steps, and you need to be much more specific about exactly what you want to do: what do you mean by switching screens smoothly? What screens? What does smoothly mean in this context?
But I'll try to help in a general sense.
First, you need to store the state of your sketch in variables at the top of your code. This might be a series of boolean values representing which screen should be shown. Then you need to change those variables when you want the display to change: this can be in response to user input, or like you said a timer of some kind, or a combination of the two. Finally, you just need to draw each frame based on those variables.
Here's an example that stores a very simple state in a single variable, sets the variable in some event functions, and uses that variable to figure out what to draw each frame:
boolean showRed = false;
void mousePressed(){
showRed = true;
}
void keyPressed(){
showRed = false;
}
void draw(){
if(showRed){
background(255, 0, 0);
}
else{
background(0);
}
}
This is just a general answer to show you the kind of thing you need to be doing. Again, you need to break your problem down into smaller and more specific steps, and then take those smaller steps on one at a time. If you get stuck, post a MCVE in a new question and we'll go from there. Good luck.
Related
The probelm I have is that I am trying to position a QGraphicsTextItem on a specific location of my QGraphicsScene , to be precise in the center of the speedometer below. But nothing I tried seems to work properly. Despite I clearly provided the coordinates I want the QGraphicsTextItem, it still anchored on top-left as shown below:
Below the snippet of code:
speedwidget.cpp
SpeedWidget::SpeedWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::SpeedWidget)
{
ui->setupUi(this);
mScene = new Scene(this);
ui->graphicsView->setScene(mScene);
io = new QGraphicsTextItem;
io->setPos(210,240);
QFont *f = new QFont;
f->setPointSize(18);
io->setFont(*f);
mScene->addText("Odometer :")->setDefaultTextColor(Qt::red);
mScene->addItem(io);
}
speedwidget.h
class SpeedWidget : public QWidget
{
Q_OBJECT
public:
SpeedWidget(QWidget *parent = nullptr);
~SpeedWidget();
private:
Ui::SpeedWidget *ui;
Scene *mScene;
QGraphicsTextItem *io;
};
#endif // SPEEDWIDGET_H
What I tried so far to solve the problem was:
I consulted this post which explained the idea but I don't need to change the background color in this example.
This one had a good snippet, but I am not trying to highlight the color. I am only trying to position the text on a specific location.
If I change io->setPos(210,240); and give different numbers, I still see it anchored on top-left.
Thanks for pointing to the right direction for solving this issue.
The Qt Graphics View framework implements a parent-child mechanism. Simply make your QGraphicsTextItem become a child of your odometer's dial item. From then on, your text label's position will be relative to the one of the dial:
io = new QGraphicsTextItem(this);
// Position text item so that it's centered on the dial
...
Furthermore, note that this line:
mScene->addText("Odometer :")->setDefaultTextColor(Qt::red);
Means that you create yet another text item. A pointer to the newly created item is being returned. Either use & retain that one or use the one that you explicitly created with the new expression.
Furthermore you might want to reconsider your choice of using a QGraphicsScene for one simple "widget". While the Qt graphics framework is not necessarily heavy, it certainly brings quite a lot of overhead for just rendering an odometer.
You can simply overwrite the QWidget::paint() function in your SpeedWidget subclass and render everything using QPainter. That will be a lot lighter and also a lot less hassle.
This answer provides a nice way to make smooth animations in SciLab. I now have to write a simulation of a body attached to two strings (and therefore its movement regarding some additional forces).
The code in the link works well to render movement of a single point and, unfortunately, I didn't manage to make an animation of a point + two lines using this method. If someone is curious, I tried this code to do it:
frametime=(tk-t0)/Nt//defining the waitnig time
plot(Y(1,1),Y(2,1),"o")//plotting the point
plot([0;Y(1,1)],[0;Y(2,1)],style=1)
plot([D;Y(1,1)],[0;Y(2,1)],style=1)//plotting the two initial lines
h1_compound = gce();
h_point=h1_compound.children
h_point.mark_size = 20;
h_point.mark_background = 2;
h_line1=h_compound.children
h_line2=h_compound.children
//h_axes = gca();
//h_axes.data_bounds = [0,-1;10,1];
realtimeinit(frametime);
for i=1:Nt//my vectors have Nt points
realtime(i);//wait "frametime" seconds before drawing the new position
h_point.data=[Y(1,i),Y(2,i)];
h_line1.data=[[0;Y(1,i)],[0;Y(2,i)]]
h_line2.data=[[D;Y(1,i)],[0;Y(2,i)]]
end
The question is: is there any way to make an animation of three shapes without making axes blink (as it is with the window refreshment) or other wierd stuff?
Since you didn't create a MCVE I can't reproduce your exact problem. But you may try to add drawlater(); before, and drawnow(); after your data modification to see if it does help with blinking or not.
Or you may get much better looking result by saving your plots in every round with xs2gif and assemble the animation with another gifmaker progam (there are free online sites to do this, however with some limitations). If you need to present your result, you should do this step anyway.
My App uses KenBurnsView (wonderful piece of code, thanks!), and it works well with ScaleType.FIT_CENTE mode, but some users just prefer to see the whole, non cropped image instead (non moving in that case), which works pretty well with standard ImageView, but fails miserably with KenBurns:
if (XenoAmp.getWpsCover()) {
final KenBurnsView caly = (KenBurnsView) widok.findViewById(R.id.tlo);
if (XenoAmp.getCoverFill()) {
caly.setScaleType(ScaleType.FIT_CENTER);
} else {
caly.setScaleType(ScaleType.CENTER_INSIDE);
caly.pause();
}
}
What happens with Ken is: he stays small and sticks to upper left corner of parent view. How can I fix that without replacing it with standard ImageView?
You can take two different approaches:
Use a standard ImageViewtogether with KenBurnsView and switch visibilities according to what your users want to see.
Write your own TransitionGenerator that doesn't do any transition at all. You can find some information about how to do it here: Define zoom/pan start position with KenBurnsView
IMO, the former approach is much simpler and makes more sense.
I am a student learning to become a comic artist.
Now we have this course called "Media" in wich we have to make an interactive program using a program called processing.
I have to show this to a jury in 2 days but I am litteraly stuck with these codes for the past 3 weeks, I just can't get it to work the way I want it to, so here I ask you if anyone would be able to help me with this.
What I want to make :
Basically I wanted it to be interactive without being interactive, So I tried to accomplish this by making a Buddha-themed program.
So what does it have to do? I think it shouldn't be all that hard, all I want it to do is take the amount of sound it gets, and when the sound is below a certain amount, the screen, wich is completely white, will start fading to black, whenever there is sound it will rapidly become white again.
So after 30 seconds of no sound it should be completely black and it should go into a new mechanism where it will start fading the black screen ( there is a picture with the word "emptyness" behind it ) so that word should start becoming visible very slowly ( approx 30 seconds again ) then when that picture is completely visible it should start fading again and start showing a picture of a buddha ( wich is behind that picture with the word ) and that's all I want it to do.
So now I will show you what I have, I've got the screen fading whenever it's really quite, but that's where I get stuck, I don't know how to set the timer, how to set the images behind it etc :
import ddf.minim.*;
Minim minim;
AudioInput in;
PImage img;
int a = 125;//sound value
int fade = 0;//starting fade, big fade is darker
int stmin = 2; //fadestep darker
int stplus = 20; //fadestep lighter
float gw = 0.001;//sensitivity smaller = more sensitive
void setup() {
img = loadImage("emptyness.jpg");
background(0);
size(1000, 1000);
frameRate(10); // Maximum 30 frames/images per second
minim = new Minim(this);
// get a line in from Minim, default bit depth is 16
in = minim.getLineIn(Minim.STEREO, 640);
}
void draw() {
image(img, 10,10);
fill(255);
rect(0,0,1000,1000);
if (abs(in.left.get(a))> (gw)) {
fade = fade-stplus;
}
else {
fade = fade+stmin;
}
fade = constrain(fade,0,300);
fill(0,fade);
rect(0,0,1000,1000);
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}
I really hope someone can help me with this for posting this here really is my last resort, I have only 2 days left untill my jury, i've been trying, getting crashes, and the worst thing of all, I really don't understand anything about java or processing cause we never got any lessons about it, they just expected us to 'find out ourselves'
thanks for reading this, and hopefully someone can help me
greetz and lots of thanks in advance
The advice I gave you on the Processing forum still stands: You have to break your problem down into smaller individual steps and take on those steps one at a time instead of trying to tackle the whole thing at once.
Can you create a simple sketch that just fades to black after 30 seconds?
Can you create a simple sketch that fades to black after 30 seconds, but then fades back to white when you click the mouse?
Can you create a simple sketch that shows you whether it can hear sound?
Now can you combine those ideas to create a sketch that fades to black after 30 seconds, but fades back to white when it hears a sound?
This might seem like a lot for 2 days (and that's a lesson in time management), but you'll have better luck if you take a step back and focus on one small thing at a time instead of your whole project. That will also allow you to ask more specific questions, as this one is too broad to really answer without doing your homework for you. And you don't want to cheat, do you?
I'm trying to load an SWF into another in AS3/Haxe. The loaded SWF contains some images - but only on some Shape.graphics elements. (Like graphics.beginBitmapFill(); ...)
This images are not smoothed, and jaggy.
Can this images be smoothed anyhow during runtime?
Any hack interested! :)
Thanks in advance!
Tom
Update: Sorry, but I forget to mention, that I'm loading more AS2-SWFs (AVM1) into one AS3-SWF (AVM2) with AVM2Loader, which hack the loaded bytes, and convert the AVM1 SWFs into AVM2 - it works very well. :)
So, in these SWFs I need to find the images/bitmaps, but only found the Shapes, which graphics elements has the 'images'. If I clear this graphics, then all images are gone, so I think, the images are in some graphics.beginBitmapFill(...);, without smoothing. I want to reach them, and switch smoothing on at runtime, if possible.
(Sorry, if the first time I was not enough clear.)
Edit (Jan 23 '14): I found solution for it. It is not fast, and required Flash Player 11.6. Every MovieClip graphics properties has a new readGraphicsData function, which give all the graphics commands (Vector IGraphicsData) to draw the whole MC. And iterate in these commands, if I change every bitmapFill command smooth parameter to true, and redraw the MC, it will be smoothed, and nice.
That's it. Not fast, but working.
I found solution for it. It is not fast, and required Flash Player 11.6. Every MovieClip graphics properties has a new readGraphicsData function, which give all the graphics commands (Vector IGraphicsData) to draw the whole MC. And iterate in these commands, if I change every bitmapFill command smooth parameter to true, and redraw the MC, it will be smoothed, and nice.
That's it. Not fast, but working.
function onLoad(event):Void
{
pic.forceSmoothing = true;
}
Smoothing is a property of bitmaps that's off by default.
var image = new Bitmap(bitmapData);
image.smoothing = true;
Typically, your bitmapData will be in the loader.content.bitmapData when loading externally, but it's up to you were you've stored it.
Update:
If you want to smooth all images in a loaded SWF without any knowledge of the structure of the SWF, then you'll have to recursively dig through the hiarchy of that SWF, and depending on whether or not the object is a Bitmap, turn on smoothing.
function recursivelySmooth(obj):void {
for (var i:int = 0; obj.getChildAt(i); i++) {
var item:* = obj.getChildAt(i);
if (item is Bitmap) {
item.smoothing = true;
} else if (item.hasOwnProperty("numChildren") == true) {
recursivelySmooth(item);
}
}
}
This was written freehand, so you may have to doublecheck everything is correct, but that's the basic idea. Just call recursivelySmooth() on your swf, and it'll dig through all objects that can have child elements and smooth them.