The image rotates with code below, but wrong, some black dots appears on original image. I believe it's something with rotation code. Any solution? Thanks. The image dimensions is 32x32 pixels loaded on center of screen (320x240).
public class RendPanel extends JPanel {
private static final long serialVersionUID = 1L;
int widthe = 320;
int heighte = 240;
double angle = Math.toRadians(220);
double sin = Math.sin(angle);
double cos = Math.cos(angle);
double x0 = 0.5 * (widthe - 1); // point to rotate about
double y0 = 0.5 * (heighte - 1); // center of image
public static BufferedImage fbuffer;
public RendPanel(int width, int height) {
fbuffer = new BufferedImage(320, 240, BufferedImage.TYPE_INT_RGB);
BufferedImage in = null;
try { in = ImageIO.read(new File("square.png")); } //32x32 square .png
catch (IOException e) { e.printStackTrace(); }
for (int i = 0; i < in.getWidth(); i++) {
for (int j = 0; j < in.getHeight(); j++) {
fbuffer.setRGB(i + (320 / 2) - 16, j + (240 / 2) - 16, in.getRGB(i, j));
}
}
BufferedImage neww = new BufferedImage(320, 240, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < widthe; x++) {
for (int y = 0; y < heighte; y++) {
if(x >= x0 - 32 && x <= x0 + 32 && y >= y0 - 32 && y <= y0 + 32){
double a = x - x0;
double b = y - y0;
int xx = (int) (+a * cos - b * sin + x0);
int yy = (int) (+a * sin + b * cos + y0);
// plot pixel (x, y) the same color as (xx, yy) if it's in bounds
if (xx >= 0 && xx < width && yy >= 0 && yy < height) {
neww.setRGB(xx, yy, fbuffer.getRGB(x, y));
}
}
}
}
fbuffer = neww;
repaint();
setPreferredSize(new Dimension(width, height));
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(fbuffer, 0, 0, null);
}
}
A beginner's mistake (sorry).
Taking every source pixel in turn, transforming the coordinates to the destination and copying the pixel value is not the right way.because the regular input grid will not map to a regular grid, and there will be voids (and overlaps).
The correct way is to scan the destination image (so that every destination pixel is reached) and counter-transform the coordinates to fetch the pixel value from the source.
As a refinement, you can use the four neighboring pixel from where you land in the source and perform bilinear interpolation, to reduce aliasing.
Man, it's strange, because in this code it works properly!
Heres a working code:
public class RendPanel extends JPanel {
private static final long serialVersionUID = 1L;
int widthe = 320;
int heighte = 240;
int ang = 0;
double x0 = 0.5 * (widthe - 1); // point to rotate about
double y0 = 0.5 * (heighte - 1); // center of image
public static BufferedImage fbuffer;
public RendPanel(int width, int height) {
fbuffer = new BufferedImage(320, 240, BufferedImage.TYPE_INT_RGB);
BufferedImage in = null;
try { in = ImageIO.read(new File("square.png")); } //32x32 square .png
catch (IOException e) { e.printStackTrace(); }
for (int i = 0; i < in.getWidth(); i++) {
for (int j = 0; j < in.getHeight(); j++) {
fbuffer.setRGB(i + (320 / 2) - 16, j + (240 / 2) - 16, in.getRGB(i, j));
}
}
setPreferredSize(new Dimension(width, height));
}
BufferedImage neww;
public void r(){
neww = new BufferedImage(320, 240, BufferedImage.TYPE_INT_RGB);
double angle = Math.toRadians(ang);
double sin = Math.sin(angle);
double cos = Math.cos(angle);
for (int x = 0; x < widthe; x++) {
for (int y = 0; y < heighte; y++) {
if(x >= x0 - 32 && x <= x0 + 32 && y >= y0 - 32 && y <= y0 + 32){
double a = x - x0;
double b = y - y0;
int xx = (int) (+a * cos - b * sin + x0);
int yy = (int) (+a * sin + b * cos + y0);
// plot pixel (x, y) the same color as (xx, yy) if it's in bounds
if (xx >= 0 && xx < widthe && yy >= 0 && yy < heighte) {
neww.setRGB(x, y, fbuffer.getRGB(xx, yy));
}
}
}
}
ang++;
repaint();
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(neww, 0, 0, null);
}
}
Thanks for:
https://introcs.cs.princeton.edu/java/31datatype/Rotation.java.html
EDIT:
You have to invert the vars on bf2.setRGB(x, y, fbuffer.getRGB(xx, yy)); to the rotated coordinate.
Related
I'm trying to implement flood fill algorithm using to fill the closed shape with specific color.
I think my code is worked out, but i don't know why are"StackOverflowError" rising up !!
i looked for the solution more and more but without finding the perfect answer.
public void paintComponent(Graphics g){
indecies.clear();
float x1 = 20;
float y1 = 20;
float x2 = 350;
float y2 = 20;
/* put the points of first line in ArraList */
for(int i = (int) x1; i < x2 ; i++){
index = (int) (i + y1 * img.getWidth());
list.add(index);
}
/***************************************************/
x1 = 350;
y1 = 20;
x2 = 100;
y2 = 100;
/* put the points of second line in ArraList */
for(int i = (int) y1; i <= y2 ; i++){
index = (int) (x1 * img.getWidth());
list.add(index);
}
/***************************************************/
x1 = 100;
y1 = 100;
x2 = 20;
y2 = 100;
/* put the points of the third line in ArraList */
for(int i = (int) x2; i < x1 ; i++){
index = (int) (i + y1 * img.getWidth());
list.add(index);
}
/*****************************************************/
x1 = 20;
y1 = 100;
x2 = 20;
y2 = 20;
/* put the points of the forth line in ArraList */
for(int i = (int) y2; i < y1 ; i++){
index = (int) (x1 * img.getWidth());
list.add(index);
}
/**************************************************/
/* Get each pixel from ArrayList of indecies then print into data raster of image */
for (Integer integer : indecies) {
pixels[integer] = Color.yellow.getRGB();
}
/* Flood fill recursive algorithm */
/* border color is yellow */
/* green is the new colow must be filled inside the shape */
fill(50, 50, Color.yellow.getRGB(), Color.green.getRGB());
g.drawImage(img, 0, 0, this);
}
Here is the fill method !!
public void fill(int x, int y, int borderColor, int newColor){
if(x >= 0 && x < width && y >= 0 && y < height){
int index = x + y * width;
if(pixels[index] != borderColor && pixels[index] != newColor){
pixels[index] = newColor;
fill(x, y - 1, borderColor, newColor);
fill(x, y + 1, borderColor, newColor);
fill(x + 1, y, borderColor, newColor);
fill(x - 1, y, borderColor, newColor);
}
}
}
Exception Details ..
java.lang.StackOverflowErrorjava.lang.StackOverflowErrorjava.lang.StackOverflowErrorjava.lang.StackOverflowErrorjava.lang.StackOverflowErrorjava.lang.StackOverflowError
at java.nio.Buffer.limit(Buffer.java:274)
at java.nio.Buffer.<init>(Buffer.java:201)
at java.nio.CharBuffer.<init>(CharBuffer.java:281)
at java.nio.HeapCharBuffer.<init>(HeapCharBuffer.java:70)
at java.nio.CharBuffer.wrap(CharBuffer.java:373)
at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:265)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
at java.io.PrintStream.write(PrintStream.java:526)
at java.io.PrintStream.print(PrintStream.java:669)
at java.io.PrintStream.println(PrintStream.java:823)
at java.lang.Throwable$WrappedPrintStream.println(Throwable.java:748)
at java.lang.Throwable.printStackTrace(Throwable.java:655)
at java.lang.Throwable.printStackTrace(Throwable.java:643)
at java.lang.Throwable.printStackTrace(Throwable.java:634)
at FillColorAlgorithm.fill(FillColorAlgorithm.java:170)
at FillColorAlgorithm.fill(FillColorAlgorithm.java:162)
......... etc
public void floodFill(int x, int y, int borderColor, int fillColor, int imgWidth, int imgHeight){
Queue<java.awt.Point> nodesList = new LinkedList<>();
if(borderColor == fillColor) return;
if(x >= 0 && x < imgWidth && y >= 0 && y < imgHeight){
int index = x + y * imgWidth;
if(pixels[index] == fillColor) return;
nodesList.add(new java.awt.Point(x, y));
}
while(!nodesList.isEmpty()) {
java.awt.Point currentNode = nodesList.element();
int index = currentNode.x + currentNode.y * imgWidth;
if(pixels[index] != fillColor){
java.awt.Point westNode = currentNode;
java.awt.Point eastNode = currentNode;
westNode = MoveWest(westNode, borderColor);
eastNode = MoveEast(eastNode, borderColor);
for (int j = westNode.x + 1; j < eastNode.x; j++) {
index = j + currentNode.y * imgWidth;
pixels[index] = fillColor;
java.awt.Point northNode = new java.awt.Point(j, currentNode.y - 1);
java.awt.Point southNode = new java.awt.Point(j, currentNode.y + 1);
index = northNode.x + northNode.y * imgWidth;
if(northNode.y >= 0 && pixels[index] != fillColor && pixels[index] != borderColor) nodesList.add(northNode);
index = southNode.x + southNode.y * imgWidth;
if(southNode.y < imgHeight && pixels[index] != fillColor && pixels[index] != borderColor) nodesList.add(southNode);
}
}
nodesList.remove();
}
}
java.awt.Point MoveWest(java.awt.Point w, int borderColor){
int index;
do{
--w.x;
index = w.x + w.y * width;
}
while(w.x >= 0 && pixels[index] != borderColor);
return new java.awt.Point(w.x, w.y);
}
java.awt.Point MoveEast(java.awt.Point e, int borderColor){
int index;
do{
++e.x;
index = e.x + e.y * width;
}
while( e.x < width && pixels[index] != borderColor);
return new java.awt.Point(e.x, e.y);
}
I can not seem to figure out why my concentric circles are not lining up. My loops seem correct to me and the measurements are correct but for some reason the last few circles are off-centered. That's the first issue I'm having. The second issue is, i can't seem to get the concentric circles to print in each square. Once again, i can't seem to find any issue in my logic, but obviously there is an issue. Any help on this at all would be great.
This should be the end product
*Now this is my source code- ExampleGUI.java *
import javax.swing.*;
public class ExampleGUI {
public static void main(String args []) {
JFrame frame = new JFrame("Example Graphics");
ExamplePanel panel = new ExamplePanel();
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(3);
frame.pack();
frame.setVisible(true);
}
}
* ExamplePanel.java *
import java.awt.*;
import javax.swing.*;
public class ExamplePanel extends JPanel{
public ExamplePanel() {
setPreferredSize(new Dimension (600, 600));
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
int x = 0;
int x2 = 5;
int y = 500;
int y2 = 505;
int w = 100;
int w2 = 90;
int h = 100;
int h2 = 90;
int i, j, k;
for(j = 1; j < 7; j++) {
x = 0;
x2 = x + 5;
for(i = 1; i < 7; i++) {
if ((i + j) % 2 == 0) {
g.setColor(Color.white);
} else {
g.setColor(Color.yellow);
}
g.fillRect(x, y, w, h);
g.setColor(Color.black);
g.drawRect(x, y, w, h);
g.setColor(Color.green);
g.fillOval(x2, y2, w2, h2);
for(k = 1; k < 7; k++) {
g.setColor(Color.black);
g.drawOval(x2, y2, w2, h2);
x2 = x2 + 5;
y2 = y2 + 5;
w2 = w2 - 10;
h2 = h2 - 10;
}
x = x + w;
x2 = x2 + w2 + 10;
}
x = x + w;
y = y - h;
y2 = (y2 - h2) - 10;
}
}
}
* This is what my program looks like when i run it. It doesn't look like the other picture for some reason *
Basically, you "spiral" loop is modifying the state of variables that are required elsewhere
What I would do, is create a new series of variables, initialized to the current state and modify those instead...
int ix = x2;
int iy = y2;
int ih = h2;
int iw = w2;
for (k = 1; k < 7; k++) {
g.setColor(Color.black);
g.drawOval(ix, iy, iw, ih);
ix = ix + 5;
iy = iy + 5;
iw = iw - 10;
ih = ih - 10;
}
I just went across some code on how to draw a pixel array on top of another pixel array that looks like this:
public class Bitmap {
private int[] pixels;
private int w, h;
public void draw(Bitmap b, int xp, int yp) {
int x0 = xp;
int x1 = xp+b.w;
int y0 = yp;
int y1 = yp+b.h;
if(x0 < 0) x0 = 0;
if(x1 > w) x1 = w;
if(y0 < 0) y0 = 0;
if(y1 > h) y1 = h;
for (int y = y0; y < y1; y++) {
int sp = (y - yp) * b.w - xp;
int dp = (y) * w;
for (int x = x0; x < x1; x++) {
int c = b.pixels[sp + x];
if (c < 0) pixels[dp + x] = b.pixels[sp + x];
}
}
}
}
As You can see, one is able to draw a Bitmap object on specific coordinates on top of another Bitmap.
The thing I don't get are the two for loops. I know, that the outer for loop is the y axis of the Bitmap drawn, and starts the inner for loop to draw the x axis of the Bitmap.
Now I came over this:
int sp = (y - yp) * b.w - xp;
int dp = (y) * w;
What exactly do sp and dp stand for? And what does 'c' mean later on in
int c = b.pixels[sp + x];
if (c < 0) pixels[dp + x] = b.pixels[sp + x];
?
Thanks in advance, best regards
Given the algorithm, we can guess what the original author was thinking:
sp is "source position": the start of the row in the source bitmap
dp is "destination position": the start of the row in the destination bitmap
c is "color": the source pixel value (where negative values are transparent).
I am trying to add some texture to my game. I am running into some problems getting the image to display properly.
This is what the texture should look like, just a boring black square:
And this is what I get. A little bit of black with blue lines.
This is the code I used to import the image. The BufferedImage is set to Type_INT_RGB:
package com.mime.minefront.graphics;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class Texture {
public static Render floor = loadBitmap("/textures/floorb.png");
public static Render loadBitmap(String fileName) {
try {
BufferedImage image = ImageIO.read(Texture.class.getResource(fileName));
int width = image.getWidth();
int height = image.getHeight();
Render result = new Render(width, height);
image.getRGB(0, 0, width, height, result.pixels, 0, width);
return result;
} catch (Exception e) {
System.out.println("CRASH!");
throw new RuntimeException(e);
}
}
}
Any help or advice would be great. I have tried to search for the answer but with no luck.
This is my Render class.
package com.mime.minefront.graphics;
public class Render {
public final int width;
public final int height;
public final int[] pixels;
public Render(int width, int height) {
this.width = width;
this.height = height;
pixels = new int[width * height];
}
public void draw(Render render, int xOffset, int yOffset) {
for (int y = 0; y < render.height; y++) {
int yPix = y + yOffset;
if (yPix < 0 || yPix >= height) {
continue;
}
for (int x = 0; x < render.width; x++) {
int xPix = x + xOffset;
if (xPix < 0 || xPix >= width) {
continue;
}
int aplha = render.pixels[x + y * render.width];
if (aplha > 0) {
pixels[xPix + yPix * width] = aplha;
}
}
}
}
}
and this is my Render3D class
package com.mime.minefront.graphics;
import com.mime.minefront.Game;
import com.mimi.minefront.input.Controller;
import com.mimi.minefront.input.InputHandler;
import java.awt.Robot;
import java.util.Random;
public class Render3D extends Render {
public double[] zBuffer;
private double renderDistance = 5000;
private double forward, right, up, cosine, sine;
public Render3D(int width, int height) {
super(width, height);
zBuffer = new double[width * height];
}
public void floor(Game game) {
double floorPosition = 8;
double cellingPosition = 8;
forward = game.controls.z;
right = game.controls.x;
up = game.controls.y;
double walking = Math.sin(game.time / 6.0) * 0.5;
if (Controller.crouchWalk) {
walking = Math.sin(game.time / 6.0) * 0.25;
}
if (Controller.runWalk) {
walking = Math.sin(game.time / 6.0) * 0.8;
}
double rotation = 0;//Math.sin(game.time / 20) * 0.5; //game.controls.rotation;
cosine = Math.cos(rotation);
sine = Math.sin(rotation);
for (int y = 0; y < height; y++) {
double celling = (y - height / 2.0) / height;
double z = (floorPosition + up) / celling;
if (Controller.walk) {
z = (floorPosition + up + walking) / celling;
}
if (celling < 0) {
z = (cellingPosition - up) / -celling;
if (Controller.walk) {
z = (cellingPosition - up - walking) / -celling;
}
}
for (int x = 0; x < width; x++) {
double depth = (x - width / 2.0) / height;
depth *= z;
double xx = depth * cosine + z * sine;
double yy = z * cosine - depth * sine;
int xPix = (int) (xx + right);
int yPix = (int) (yy + forward);
zBuffer[x + y * width] = z;
pixels[x + y * width] = //((xPix & 15) * 16 | ((yPix % 15) * 16) << 8);
Texture.floor.pixels[xPix & 7] + (yPix & 7) * 8;
if (z > 500) {
pixels[x + y * width] = 0;
}
}
}
}
public void renderWall(double xLeft, double xRight, double zDistance, double yHeight) {
double xcLeft = ((xLeft) - right) * 2;
double zcLeft = ((zDistance) - forward) * 2;
double rotLeftSideX = xcLeft * cosine - zcLeft * sine;
double yCornerTL = ((-yHeight) - up) * 2;
double yCornerBL = ((+0.5 - yHeight) - up) * 2;
double rotLeftSideZ = zcLeft * cosine + xcLeft * sine;
double xcRight = ((xRight) - right) * 2;
double zcRight = ((zDistance) - forward) * 2;
double rotRightSideX = xcRight * cosine - zcLeft * sine;
double yCornerTR = ((-yHeight) - up) * 2;
double yCornerBR = ((+0.5 - yHeight) - up) * 2;
double rotRightSideZ = zcRight * cosine + xcRight * sine;
double xPixelLeft = (rotLeftSideX / rotLeftSideZ * height + width / 2);
double xPixelRight = (rotRightSideX / rotRightSideZ * height + width / 2);
if (xPixelLeft >= xPixelRight) {
return;
}
int xPixelLeftInt = (int) (xPixelLeft);
int xPixelRightInt = (int) (xPixelRight);
if (xPixelLeftInt < 0) {
xPixelLeftInt = 0;
}
if (xPixelRightInt > width) {
xPixelRightInt = width;
}
double yPixelLeftTop = (yCornerTL / rotLeftSideZ * height + height / 2);
double yPixelLeftBottom = (yCornerBL / rotLeftSideZ * height + height / 2);
double yPixelRightTop = (yCornerTR / rotRightSideZ * height + height / 2);
double yPixelRightBottom = (yCornerBR / rotRightSideZ * height + height / 2);
double tex1 = 1 / rotLeftSideZ;
double tex2 = 1 / rotRightSideZ;
double tex3 = 0 / rotLeftSideZ;
double tex4 = 8 / rotRightSideZ - tex3;
for (int x = xPixelLeftInt; x < xPixelRightInt; x++) {
double pixelRotation = (x - xPixelLeft) / (xPixelRight - xPixelLeft);
double xTexture= (int) ((tex3+tex4*pixelRotation)/tex1+(tex2-tex1)*pixelRotation);
double yPixelTop = yPixelLeftTop + (yPixelRightTop - yPixelLeftTop) * pixelRotation;
double yPixelBottom = yPixelLeftBottom + (yPixelRightBottom - yPixelLeftBottom) * pixelRotation;
int yPixelTopInt = (int) (yPixelTop);
int yPixelBottomInt = (int) (yPixelBottom);
if (yPixelTopInt < 0) {
yPixelTopInt = 0;
}
if (yPixelBottomInt > height) {
yPixelBottomInt = height;
}
for (int y = yPixelTopInt; y < yPixelBottomInt; y++) {
pixels[x + y * width] = (int) xTexture*100;
zBuffer[x + y * width] = 0;
}
}
}
public void renderDistanceLimiter() {
for (int i = 0; i < width * height; i++) {
int colour = pixels[i];
int brightness = (int) (renderDistance / (zBuffer[i]));
if (brightness < 0) {
brightness = 0;
}
if (brightness > 255) {
brightness = 255;
}
int r = (colour >> 16) & 0xff;
int g = (colour >> 8) & 0xff;
int b = (colour) & 0xff;
r = r * brightness / 255;
g = g * brightness / 255;
b = b * brightness / 255;
pixels[i] = r << 16 | g << 8 | b;
}
}
}
From getRGB() :
Returns an array of integer pixels in the default RGB color model
(TYPE_INT_ARGB) and default sRGB color space, from a portion of the
image data. Color conversion takes place if the default model does not
match the image ColorModel
See if using TYPE_INT_ARGB instead of TYPE_INT_RGB works.
I'm trying to rotate a Bitmap where the pixels are stored in an Array int pixels[]. I got the following method:
public void rotate(double angle) {
double radians = Math.toRadians(angle);
double cos, sin;
cos = Math.cos(radians);
sin = Math.sin(radians);
int[] pixels2 = pixels;
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++) {
int centerx = this.width / 2, centery = this.height / 2;
int m = x - centerx;
int n = y - centery;
int j = (int) (m * cos + n * sin);
int k = (int) (n * cos - m * sin);
j += centerx;
k += centery;
if (!((j < 0) || (j > this.width - 1) || (k < 0) || (k > this.height - 1)))
try {
pixels2[(x * this.width + y)] = pixels[(k * this.width + j)];
} catch (Exception e) {
e.printStackTrace();
}
}
pixels = pixels2;
}
But it just gives me crazy results. Does anyone know where the error is?
The line
int[] pixels2 = pixels;
is supposed to copy the array, but you are just copying the reference to it. Use pixels.clone(). In fact, you just need a new, empty array, so new int[pixels.lenght] is enough. In the end you need System.arraycopy to copy the new content into the old array.
There are other problems in your code -- you are mixing up rows and columns. Some expressions are written as though the image is stored row by row, others as if column by column. If row-by-row (my assumption), then this doesn't make sense: x*width + y. It should read y*width + x -- you are skipping y rows down and then moving x columns to the right. All in all, I have this code that works OK:
import static java.lang.System.arraycopy;
public class Test
{
private final int width = 5, height = 5;
private int[] pixels = {0,0,1,0,0,
0,0,1,0,0,
0,0,1,0,0,
0,0,1,0,0,
0,0,1,0,0};
public Test rotate(double angle) {
final double radians = Math.toRadians(angle),
cos = Math.cos(radians), sin = Math.sin(radians);
final int[] pixels2 = new int[pixels.length];
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++) {
final int
centerx = this.width / 2, centery = this.height / 2,
m = x - centerx,
n = y - centery,
j = ((int) (m * cos + n * sin)) + centerx,
k = ((int) (n * cos - m * sin)) + centery;
if (j >= 0 && j < width && k >= 0 && k < this.height)
pixels2[(y * width + x)] = pixels[(k * width + j)];
}
arraycopy(pixels2, 0, pixels, 0, pixels.length);
return this;
}
public Test print() {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
System.out.print(pixels[width*y + x]);
System.out.println();
}
System.out.println();
return this;
}
public static void main(String[] args) {
new Test().print().rotate(-45).print();
}
}
public void render(float nx, float ny, float nz, float size, float rotate) {
int wid = (int) ((width - nz) * size);
int hgt = (int) ((height - nz) * size);
if (wid < 0 || hgt < 0) {
wid = 0;
hgt = 0;
}
for (int x = 0; x < wid; x++) {
for (int y = 0; y < hgt; y++) {
double simple = Math.PI;
int xp = (int) (nx +
Math.cos(rotate) * ((x / simple) - (wid / simple) / 2) + Math
.cos(rotate + Math.PI / 2)
* ((y / simple) - (hgt / simple) / 2));
int yp = (int) (ny + Math.sin(rotate)
* ((x / simple) - (wid / simple) / 2) + Math.sin(rotate
+ Math.PI / 2)
* ((y / simple) - (hgt / simple) / 2));
if (xp + width < 0 || yp + height < 0 || xp >= Main.width
|| yp >= Main.height) {
break;
}
if (xp < 0
|| yp < 0
|| pixels[(width / wid) * x + ((height / hgt) * y)
* width] == 0xFFFF00DC) {
continue;
}
Main.pixels[xp + yp * Main.width] = pixels[(width / wid) * x
+ ((height / hgt) * y) * width];
}
}
}
This is only a new to rotating for me, but the process of this is that of a normal rotation. It still needs much fixing -- it's inefficient and slow. But in a small program, this code works. I'm posting this so you can take it, and make it better. :)