Rotating on a different axis

Problems with Canvas, OpenGL, etc...

Rotating on a different axis

Postby Skeniver » Wed Jul 28, 2010 3:17 pm

Hi everyone

I am trying get the hang of animations... Which I am finding quite tricky. I found a tut that sort of does what I am trying... This code writes text along a circular path and then rotates the circle. What I would like to try do is rotate the text along the x-axis from top to bottom; like it is flipping down. The goal is to create a flip style clock...

Any help would be greatly appreciated!
Code: Select all
package com.skeniver.rani;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;

public class Spinning extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new GraphicsView(this));
    }
   
    private static class GraphicsView extends View {
       private static final String QUOTE = "Hi this is typing in animation";
       
       private Animation anim;
       
      public GraphicsView(Context context) {
         super(context);
      }
      
      private void createAnim(Canvas canvas) {
            anim = new RotateAnimation(0, 180, canvas.getWidth() / 2, canvas.getHeight() / 2);
            anim.setRepeatMode(Animation.REVERSE);
            anim.setRepeatCount(Animation.INFINITE);
            anim.setDuration(10000L);
            anim.setInterpolator(new AccelerateDecelerateInterpolator());

            startAnimation(anim);
        }
      
      @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);

            // creates the animation the first time
            if (anim == null) {
                createAnim(canvas);
            }

            Path circle = new Path();

            int centerX = canvas.getWidth() / 2;
            int centerY = canvas.getHeight() / 2;
            int r = Math.min(centerX, centerY);

            circle.addCircle(centerX, centerY, r, Direction.CW);
            Paint paint = new Paint();
            paint.setColor(Color.BLUE);
            paint.setTextSize(30);
            paint.setAntiAlias(true);

            canvas.drawTextOnPath(QUOTE, circle, 0, 30, paint);
        }
    }
}
Follow me on twitter -> http://twitter.com/Skeniver
Apps & blog -> http://www.formidableapps.co.uk
User avatar
Skeniver
Senior Developer
Senior Developer
 
Posts: 106
Joined: Tue Feb 03, 2009 3:51 pm
Location: Canterbury, UK

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 3 guests