[my blog] [my software] [contacts]

back to today
 

23 december 2007

J2ME rotozoomer

Today I tried to code an oldschool demo effect for my mobile phone (a Nokia 3110 classic)...
I created a simple rotozomeer :)

here is the code (J2ME MIDP 2.0)

package org.postronic.h3.testmidlet;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class RotozoomerMIDlet extends MIDlet {

  public RotozoomerMIDlet() { }

  protected void startApp() throws MIDletStateChangeException {
    RotozoomerCanvas canvas = new RotozoomerCanvas();
    Display display = Display.getDisplay(this);
    display.setCurrent(canvas);
    canvas.run();
  }

  protected void pauseApp() { }

  protected void destroyApp(boolean arg0) throws MIDletStateChangeException { }

}



package org.postronic.h3.testmidlet;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;

public class RotozoomerCanvas extends GameCanvas {

  protected RotozoomerCanvas() {
    super(true);
    setFullScreenMode(true);
  }

  public void run() {
    int imgWidth = getWidth();
    int imgHeight = getHeight();
    Graphics g = getGraphics();
    int[] img = new int[imgWidth * imgHeight];

    Image texture = Image.createImage(32, 16);
    Graphics tg = texture.getGraphics();
    tg.setColor(200, 200, 255);
    tg.drawString("h3-r3", 2, 0, Graphics.TOP | Graphics.LEFT);
    tg.setColor(200, 200, 255);
    tg.drawString("h3-r3", 4, 0, Graphics.TOP | Graphics.LEFT);
    tg.setColor(0, 0, 255);
    tg.drawString("h3-r3", 3, 0, Graphics.TOP | Graphics.LEFT);
    int[] txImg = new int[32 * 16];
    texture.getRGB(txImg, 0, 32, 0, 0, 32, 16);
    texture = null; // dispose the texture Image

    float tx, ty;
    float dtx, dty;
    float otx, oty;

    double cont = 0;
    double cos, sin;
    double size;
    int offs;
    for(;;) {
      cos = Math.cos(cont);
      sin = Math.sin(cont);
      tx = (float) cos * 20;
      ty = (float) sin * 20;
      size = cos;
      dtx = (float) (cos * size);
      dty = (float) (sin * size);
      cont += 0.02;
      for (int y = 0; y < imgHeight; y++) {
        otx = tx;
        oty = ty;
        offs = y * imgWidth;
        for (int x = 0; x < imgWidth; x++) {
          img[x + offs] = txImg[((int)(tx) & 31) + (((int)(ty) & 15) * 32)];
          tx += dtx;
          ty += dty;
        }
        tx = otx - dty;
        ty = oty + dtx;
      }
      g.drawRGB(img, 0, imgWidth, 0, 0, imgWidth, imgHeight, false);
      flushGraphics();
    }
  }

}

 
2007-12-23 23:57:09
H3-r3 wrote:
This little program is also quite useful..
I just start it when I want to empty the cellphone batteries :D

2017-12-09 02:01:14
RobertCes wrote:
Doctor Who is now considered a British Institute and has come a long way since it first aired on November 23rd 1963. The very first show saw the Doctor travel 100,00 years into the past to help some dim cavemen discover light. After 26 seasons and seven Doctors later the series came off our screens in 1989 much to the disappointment of the huge devoted fanbase. In 1996 an attempt was made to revive Doctor Who but it wasnt until June 2005 when it came back with a vengeance with Christopher Eccleston as the ninth Doctor that put the series back on the map as it were. It then went on for 5 years with David Tenant portraying the Doctor until 2010 when Matt Smith took over the role. Today it is still a great family show and has attracted many new fans.
https://www.cialissansordonnancefr24.com/acheter-cialis-en-ligne-belgique/

Comments disabled