Rotating A Shape - Graphics2D Rotate (theta) Method
Jun 14, 2014
I am having a problem rotating a shape I am using the transformation rotation matrix and don't seem to be getting the results I expected. Now I know a lot of programmers will just tell me to use the Graphics2D rotate(theta) Method.But I would like to create this ability through writing the code.
I have a java program which rotates a rectangular polygon. My program is having a problem. As soon as it starts rotating, it shrinks. The polygon is rotating perfectly though. I am trying but unable to figure out the cause.Main class which has an infinite loop (game loop) to rotate polygon continuously :-Java Code:
I am writing a program to solve Sudoku puzzles. I create the user interface using AWT/Swing.One panel of the main window (JFrame object) contains a Graphics2D component only (a grid for the sudoku puzzle). The problem is that this panel is too small for its contents when it is created. I have tried many things to make it bigger (like the setSize method of the panel), but to no avail. Who can tell me how I can make the panel with a single Graphics2D object larger?
Below is the code for the main window, which is a JFrame object. I set its size to 400 x 400 to have ample room for all panels. I then create two panels: a sudoku panel that contains the sudoku grid and a button panel that contains two buttons. The button panel has a flow layout.
I then create the main panel. This has a vertical BoxLayout. Finally I add the sudoku panel and the button panel to the main panel and the main panel to the frame.
public class ViewController_Graphics extends JFrame { JButton solveButton = new JButton("Solve"); JButton nakedSinglesButton = new JButton("Naked Singles");
When I run the program, the following Window shows up:the button panel is exactly in the middle (and it remains in the middle, no matter how I resize the window). And there is not enough room for the sudoku panel. How can I make enough room for the sudoku panel when the window is created?
I wanted to write a method which gets a buffered image as parameter, rotates it 90 degrees clockwise around its top left corner, and then returns it. This method will be call from another method which then draws the rotated image on a rather large background which consists of many other images.
Here is the code I have so far:
public static BufferedImage rotate(BufferedImage img) { int w = img.getWidth(); int h = img.getHeight(); BufferedImage newImage = new BufferedImage(width, height, img.getType()); Graphics2D g2 = newImage.createGraphics(); g2.rotate(Math.toRadians(90), w/2, h/2); g2.drawImage(img,null,0,0); return newImage; }
This method does rotate an image 90 degrees, but when the calling method recieves this image and displays it on the bigger frame, parts of the rotated image is cut. I think because the frame holding the returned image is not big enough. I've tried playing around with the code a lot, chaging the sizes of different images, and trying AffineTransform features, but I have had no luck.
After i draw line between 2 fixed points on two different rectangles i need to rotate them. The problem is that my line is not updated, it stays on the same x1,y1 x2,y2. How to make line to follow rectangle when they are moving or rotating? I wrote some example code to demonstrate this.
Object that i want to draw:
[public class Object { private int xPos; private int yPos; private int width; private int height; float xDistance = 0f; float yDistance = 0f; double angleToTurn = 0.0;
I am struggling to make a double border which has rounded corners. The border should be 2 parallel lines.
I made something which looks almost good, but if you look closer there are a few wrong things.To achieve this, I made 2 paths, then painted them in 2 different colours.
The main problem is painting with AA, because the colours overlap and are affected.
I think it would be smoother to paint a single path using 2 colours.
For the first problem, I think some kind of a stroke would be enough. But, if I build a stroke, it's almost same thing like drawing the path twice, like I did before. Anyway i think that would fix AA problem. But still, maybe I can achieve a smoother effect for the corners.
Question:Maybe something with a 2x1 Texture ? It's possible to achieve this ? I know I tried this before and when a curve was encountered the direction of the texture was wrong and looked messy.
PS: Ignore the blueish thing, it's a dragged component to activate the highlight border.
I have a list of Tabs which are dynamic depending on how many cars are in a database. If there are 10 cars there will be 10 tabs called car 1, car 2, car 3, etc. Each tab simply displays a photo and details of the car.
I have a JMenuItem that says start SlideShow and end SlideShow
What i would like to do is automatically slide through tabs when the start Slideshow is clicked.
i want to rotate this shape using AffineTransform without changing its position and its size. i want the arrow to be in a straight line. how can i proceed??
I have use this but the place of the arrow is changing.
AffineTransform at = new AffineTransform(); at.rotate(Math.toRadians(45)); c.transform(at);
I have been trying to rotate an image on a certain degree, and still remain on the same position. I have tried g.rotate, but it just rotate around a center, and it does not keep the same position as before.
I need my Java program (I'm working in Eclipse if it matters) to detect if an image is a portrait or a landscape, but since i am directly downloading them from my camera they only have it written somewhere in metadata, the image width and height is the same for landscape and portrait. I have the rotation code and the rest of the program working, but I need to somehow get a variable (for example integer one) to tell me if it is a portrait or a landscape image. I tried getting to the metadata but my Eclipse decided that import com.drew.metadata.Metadata; cannot be resolved.
BufferedImage image = ImageIO.read(new File(imagePath, imageName)); and after I get the variable "orientation" it looks like this
int orientation = ???; BufferedImage newImage = oldImage; if (orientation>1){ newImage = rotate(oldImage); }
I'm trying to replicate the rol(rotate left) instruction in assembly though can only get as far as shifting the bits with '<<' or doing Long.rotateLeft(var, 5). Both of these method don't wrap around the bits as the rol instruction does.
So I need to create a square and make it rotate when the letter R is pressed and then make it stop when the letter R is pressed again. I need make it rotate using a maths equation that I can't figure it out myself right this moment.
Code for square:
package lab2; public class Square { public double [][] vertices = new double[4][2]; //not good to make this public public Square(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { vertices[0][0]=x1; vertices[0][1]=y1; vertices[1][0]=x2;
[Code] ....
In the Square code there is a method to write an equation to rotate it but I can't figure that part out ....
why am I not getting a proper shape of "Leftarrow"? The result should look like the following (the system draws the arrow abnormally, so the beginning should a real ARROW:
*
* *
* *
* * * * * * * * *
* *
* *
*
here is the class:
Java Code: public class LeftArrow extends ShapeBase { private int lengthOfTail; private int widthOfArrowHead;
class shape{ public static void main(String [] args){ for(int x =0 ; x<=6;x++){ for(int y =0 ; x > y ; y++){ System.out.print(x); } System.out.print(" "); } } }
i java a project with java draw golf course and currently working on 2 combo boxes to change shape of the flag on the post and fill color as well on combo box item change. I have below code. as am new to java what to do next.
import java.awt.*; import java.awt.event.ItemEvent; import javax.swing.*; public class GulfCourse extends JPanel{ public void paintComponent( Graphics g){ super.paintComponents(g); //draw green oval
I'm making a program that prints arrows of varying tail length, head width, and displacement.The shape algorithms are working properly, but the displacement isn't working. The first arrow has zero displacement, and the second one is supposed to be bigger and start the print at 10 spaces right and 5 spaces down from the default, but it's not working. I tried changing the displacement settings of the first arrow, and no changes happened, so I know that the positions aren't registering properly in general. How to pass the xAdj and yAdj (displacement) values? I think I have the empty space formula set up, but it's still not running.
Driver: public class Driver { //default values public static final int Arrow_Default_xAdj = 0; public static final int Arrow_Default_yAdj = 0; public static final int Arrow_Default_tail = 5; public static final int Arrow_Default_width = 5;
I'm going to make tiles for my RPG game, instead of drawing each shape of the tile, I will just draw the full tile in a spritesheet. I will create a sprite sheet of shapes that I want to clip somehow or use to cut the original full image into the shape I want. How can I, take a Buffered Image, cut it's shape and perhaps add something, giving me a Buffered Image of a cut tile with possibly added features that I can then draw with Graphics?
I am supposed to Write a program that prints a shape similar to the following shape. Maximize use of loops and minimize use of print statements.
.....* ....** ...*** ..**** ...*** ....** .....*
(without the "...")(i couldn't get it to stay in shape)
This is what i got so far:
Java Code: package assignment7;
public class Exercise3 { public static void main (String[] args) { for (int count =0; count < 4; count++) { for (int j=0; j < count+1; j++) [Code] ....
I'm making my 2D Java game, in my own style, in my own way. I'm trying to make it as code efficient as possible and compact, it usually is easier to change that way. I'm going to use BufferedImage subdivision on tilesets to take out tiles that I need, rather than creating multiple images with a tile each. Now, I've made multiple water tiles, for how they would be arranged differently.
So let's say you have a single water spot, it will be circular, you have two water spots, you have a tile-thick line with circular ends like two little water spots connected, this makes the game look more advanced, better, more realistic and good in many other ways. But, I found that an avarage amount of shapes needed is 25. I thought, how could I make this more efficient?
Could it be possible to use like shape cutting tools or something that would take out a specific shape of a single water tile to leave out all the different shapes, this is a good idea because I could use these tools for all kinds of different tiles in order to make specific features. By tools I mean simple black shapes which will remove the unwanted parts of the tile to form the wanted shape.