# Rotating a square rendered on a Bitmap

I'm writing a Software Renderer for fun/learning. Basically, it's just a giant array of integers which contain hexadecimal values (representing colour) that are rendered to the screen....

int screenWidth = 16;
int screenHeight = 16;
int[] pixels = new int[screenWidth * screenHeight];
Arrays.fill(pixels, 0xffff00ff);


Something like that, the above should render a pink screen (255, 0, 255). So my problem is I've written a method that will fill a rectangle...

public void fillRect(int x0, int y0, int x1, int y1) {
x0 += xOffs; // apply offset to each vertex
y0 += yOffs;
x1 += xOffs;
y1 += yOffs;

if (x0 < 0) x0 = 0;
if (y0 < 0) y0 = 0;
if (x1 >= width) x1 = width - 1;
if (y1 >= height) y1 = height - 1;
for (int y = y0; y <= y1; y++) {
for (int x = x0; x <= x1; x++) {
components[x + y * width] = 0xDEADBEEF;
}
}
}


And it works fine, although I want to try and rotate the quad by 90 degrees, then render it to the bitmap. So I tried this....

public void fill(int x0, int y0, int x1, int y1) {
final int theta = 90;
x0 = (int) (x0 * Math.cos(theta) - x0 * Math.sin(theta));
x1 = (int) (x1 * Math.cos(theta) - x1 * Math.sin(theta));
y0 = (int) (y0 * Math.sin(theta) + y0 * Math.cos(theta));
y1 = (int) (y1 * Math.sin(theta) + y1 * Math.cos(theta));

x0 += xOffs; // apply offset to each vertex
y0 += yOffs;
x1 += xOffs;
y1 += yOffs;

if (x0 < 0) x0 = 0;
if (y0 < 0) y0 = 0;
if (x1 >= width) x1 = width - 1;
if (y1 >= height) y1 = height - 1;
for (int y = y0; y <= y1; y++) {
for (int x = x0; x <= x1; x++) {
components[x + y * width] = hex;
}
}
}


Although it doesn't work, nothing is shown on the Window. Any ideas? I have a feeling after the rotation, the entire method is wrong. Any help would be great :)