Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following code successfully rotates a bitmap, thanks to reddit.com/user/dd_123! </p> <pre><code>public void render2(int xPos, int yPos, double angle, BitMap data){ double angle2 = Math.toRadians(angle); angle = angle2; int w = data.getWidth(); int h = data.getHeight(); int size = (int) (Math.sqrt(w * w + h * h)); BitMap newBitMap = new BitMap(size, size); int xCenter = w / 2; int yCenter = h / 2; final int halfSize = size / 2; for(int y = 0; y &lt; size; y++){ for(int x = 0; x &lt; size; x++){ int samplePointX = x - halfSize; int samplePointY = y - halfSize; int xData, yData; xData = (int)(samplePointX * -Math.cos(angle) + samplePointY * Math.sin(angle)); yData = (int)(samplePointX * -Math.sin(angle) - samplePointY * Math.cos(angle)); xData += xCenter; yData += yCenter; if(!(xData &gt;= 0 &amp;&amp; xData &lt; w)){ continue; } if(!(yData &gt;= 0 &amp;&amp; yData &lt; h)){ continue; } if((x) + (y) * size &gt; size * size){ continue; } screenPixels.setValue(x, y, data.getValue(xData, yData)); } } </code></pre> <p>}</p> <p>The bitmap class</p> <pre><code>public class BitMap { public BitMap(int width, int height){ this.width = width; this.height = height; this.data = new int[width * height]; } public BitMap(int[] data, int width, int height) { this.data = data; this.width = width; this.height = height; } private int[] data; private int width, height; public int getWidth(){ return width; } public int getHeight(){ return height; } public int getValue(int x, int y){ return data[x + y * width]; } public BitMap fillWithValues(int value){ for(int i = 0; i &lt; data.length; i++){ data[i] = value; } return this; } public void setValue(int xScr, int yScr, int value) { data[xScr + yScr * width] = value; } public int[] getValues() { return data; } public BitMap subData(int xPos, int yPos, int w, int h) { BitMap bitmap = new BitMap(w, h); for(int y = 0; y &lt; h; y++){ for(int x = 0; x &lt; w; x++){ bitmap.setValue(x, y, this.getValue(x + xPos, y + yPos)); } } return bitmap; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload