• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Turning images around the clock

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to turn several images around in different directions, like an image of an arrow turning against your cursor.
To be more exact, I want different images of arrows, lightning and others to be shot from different points and then turn against their destination points. So that no arrows etc will be flying backwards...

I will be doing this with several images, so I won't just make every image in several copies...

I've tried searching for it, but I haven't found anything close to my question.
Any ideas?
[ July 15, 2008: Message edited by: Kari Nordmann ]
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I did this with fonts but it is perfect to do with images

check
http://www.javalobby.org/java/forums/t19387.html

wit regards
sven
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you just want to flip the image with respect to its vertical center axis, then you could simply swap the respective pixel values.
 
Kari Nordmann
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tested the example with affine transform, it didn't turn any images around, only moved and resized them... I didn't really understand what the class is ment for either, I dont understand what "affine transform" means

I think it should work fine if I can flip the image to anywhere from 0 to 360 degrees, I'll try to figure that out.
[ July 16, 2008: Message edited by: Kari Nordmann ]
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<blockquote>code:
<pre name="code" class="core">
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.event.*;

public class Pointing extends JPanel {
BufferedImage image;
double theta = -Math.PI/4;

Pointing() {
int w = 75, h = 40,
type = BufferedImage.TYPE_INT_ARGB_PRE;
image = new BufferedImage(w,h,type);
Graphics2D g2 = image.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Path2D.Double path = new Path2D.Double();
path.moveTo(0,10);
path.lineTo(45,10);
path.lineTo(45,0);
path.lineTo(75,20);
path.lineTo(45,40);
path.lineTo(45,30);
path.lineTo(0,30);
path.lineTo(0,10);
g2.setPaint(Color.red);
g2.fill(path);
g2.dispose();
}

protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
int w = getWidth();
int h = getHeight();
int r = Math.min(w,h)/3;
double x = w/2 + r*Math.cos(theta);
double y = h/2 + r*Math.sin(theta);
g2.setPaint(Color.blue);
g2.draw(new Line2D.Double(w/2, h/2, x, y));
int iw = image.getWidth();
int ih = image.getHeight();
// Translate the image to the end of the line
// and rotate it from its left end, centered.
AffineTransform at =
AffineTransform.getTranslateInstance(x, y-ih/2);
// Comment-out this next line to see the translation.
at.rotate(theta, 0, ih/2);
g2.drawRenderedImage(image, at);
g2.setPaint(Color.green.darker());
g2.fill(new Ellipse2D.Double(w/2-2, h/2-2, 4, 4));
g2.fill(new Ellipse2D.Double(x-2, y-2, 4, 4));
}

private JSlider getSlider() {
JSlider slider = new JSlider(-180, 180, -45);
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int value = ((JSlider)e.getSource()).getValue();
theta = Math.toRadians(value);
repaint();
}
});
return slider;
}

public static void main(String[] args) {
Pointing test = new Pointing();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(test);
f.add(test.getSlider(), "Last");
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}
</pre>
</blockquote>
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic