Image Animation, Rotation & Square Algorithm in Java

preview_player
Показать описание
This formula can be edited and used for other requirements like polygons and other stuffs..
"Screen width and screen height can also be taken dynamically according to which we have to code other values, thus smoothly deploying on all systems".
"Printing values & variables in flow is also debugging".
Source Code is in Comments section.

#programming #jframe #code #logic #method #processing #data #math #pixel #photos #pic #jpanel #revolution #sreesha #technology #ethics #ui #ux #beauty #skills #software #hardware #camera #information #move #movement #tail #moving #revolution #flip #move #straightline #line #straight
Рекомендации по теме
Комментарии
Автор

Screen width n height can be dynamically taken or mannuly adjusted according to systems.
With Rotation:
package com.sreesha.time;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class AroundFrameRotation extends JFrame {
int x=10, y=10; //2D coordinates, for image
Image img, palace;

AroundFrameRotation() //constructor
{
this.setSize(900, 900); //size of frame


this.setResizable(true);
this.setVisible(true);
}

public void paint (Graphics g)
{
Graphics2D g2d = (Graphics2D) g;

img = new //path. in windows like:
palace = new
g.drawImage(palace, 300, 300, null); //reference point is top left in swing
g.drawImage(img, x, y, null); //draws image at first


try
{
for(int i=1;i<=30;i++)
{
//x+ to move right
x, y, null); // draw image at new position till for loop
//delay in milliseconds

}

for(int i=1;i<=30;i++)
{
//y+ to move bottom
at = AffineTransform.getTranslateInstance(900, y);
//anticlockwise rotation by 90-degree
at, null);

}
x=900;
for(int i=1;i<=30;i++)
{
//x- to move left
at = AffineTransform.getTranslateInstance(x, 900);

at, null);
x, y, null); if no rotation required without changing x & y after for loops.

}
y=900;
for(int i=1;i<=30;i++)
{
//y- to move top
at = AffineTransform.getTranslateInstance(10, y);

at, null);

}
x=10;
y=10;
repaint(); // calls paint() function again & again

}
catch(InterruptedException e) {
in sleeping!");
}
}

public static void main(String[] args) {
new AroundFrameRotation();

}

}


Without Rotation:
package com.sreesha.time;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class AroundFrame extends JFrame {
int x=10, y=10; //2D coordinates, for image
Image img, sun;

AroundFrame() //constructor
{
this.setSize(900, 900); //size of frame


this.setResizable(true);
JLabel label = new JLabel("PRINCESS");
this.add(label);
this.setVisible(true);
}

public void paint (Graphics g)
{

img = new //path. in windows like:
sun = new
g.drawImage(sun, 300, 300, null); //reference is top left in swing
g.drawImage(img, x, y, null); //draws image at first


try
{
for(int i=1;i<=30;i++)
{
//x+ to move right
x, y, null); // draw image at new position till for loop
//delay in milliseconds

}

for(int i=1;i<=30;i++)
{
//y+ to move bottom
x, y, null);

}

for(int i=1;i<=30;i++)
{
//x- to move left
x, y, null);

}

for(int i=1;i<=30;i++)
{
//y- to move top
x, y, null);

}

repaint(); // calls paint() function again & again

}
catch(InterruptedException e) {
in sleeping!");
}
}

public static void main(String[] args) {
new AroundFrame();

}

}

sreeshakv
Автор

Sreesha sir how are you ? Long time ? Need more videos of your singing and flute

mkbhd
Автор

package Interview;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import

public class TextAnimationWithImage extends JPanel implements ActionListener {
private String textToDisplay = "Hey Debasree!";
private int textX = 10;
private int textY = 100;
private int imageX = 100;
private int imageY = 100;
private int imageWidth = 200;
private int imageHeight = 200;
private Image image;

public TextAnimationWithImage() {
Timer timer = new Timer(30, this); // Timer for animation, fires every 30 milliseconds
timer.start();

// Load an image
ImageIcon imageIcon = new
image = imageIcon.getImage();
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);

// Clear the panel
g.clearRect(0, 0, getWidth(), getHeight());

g.setFont(new Font("Arial", Font.BOLD, 20));
g.drawString(textToDisplay, textX, textY);

g.drawImage(image, imageX, imageY, imageWidth, imageHeight, this);
}

@Override
public void actionPerformed(ActionEvent e) {
// Move the text to the right
textX += 2;
if (textX > getWidth()) {
textX = -100; // Reset the text position when it goes off the screen
}

repaint();
}

public static void main(String[] args) {
JFrame frame = new JFrame("Text Animation with Image");

frame.setSize(400, 400);
frame.add(new TextAnimationWithImage());
frame.setVisible(true);
}
}

sreeshakv
welcome to shbcf.ru