How to drawing bezier curve with animation in Android using cubicTo? - android

I've been searching for simple example and solution in stackoverflow, but I couldn't find one. So, I'll ask a new one and my apologies if this question have been asked before.
First, I want to make an apps that draw a Japanese Kanji Stroke using bezier curve, I already have 1 starting point, with 3 curves, for example :
M(11,54.25)
c(3.19,0.62) (6.25,0.75) (9.73,0.5)
c(20.64,-1.5) (50.39,-5.12) (68.58,-5.24)
c(3.6,-0.02) (5.77,0.24) (7.57,0.49)
What I have been found during searching in internet is, it looks like I could use Path.cubicTo() and use canvas as to draw it (using canvas.drawPath()).
And also, I want the canvas to draw it using animation at given frame rate or speed.
Anyone could give me a simple example or maybe some clue or anything that I can work with ?
Thanks !

You can find great example here:
http://www.jayway.com/2012/08/29/creating-custom-android-views-part-3-animating-your-custom-views-smoothly/
The sources are also there so it's very easy.
Your approach is good- you basically use Path.cubicTo in your View's onDraw and invalidate views while changing input coordinates. You can do it in another thread or create ValueAnimator and invalidate view in AnimatorUpdateListener.

Related

Motion to draw numbers on android

im new to this android things. And i have to develop an application that can help an autism to learn numbers. I have a few ideas and I've been trying to learn and implement the code. But it's failed. The question is how can i apply the motion code or sprite to draw a numbers or letter? For example like this, i wanna make the penguin move through the line and draw a number nine.
There is example from mybringback.com which is the image move to draw a rectangle. How can i implement it to draw a number? Im sorry if i asking too much, i just trying to get some ideas.
I think that you should first build an utility program, in order to create the "path vector".
What I mean by path vector is simply a vector of Points (where a point has x value, and y value). And your utility should let you draw whatever you want, with a simple pen. You should draw on surface and store points when mouse is down, and ignore points when mouse is up.
Then, in the main program, you will just have to read at the path of your number/letter.
I've tried to implement something like this for the Sugar OLPC platform, without serializing path into files : I was able to draw, and to view the animation. And I used the process I've just described you.
Hope it can help you.
P.S : I used the word mouse, but you guessed that I talk about finger ...
There are various ways to achieve animation effects. One approach that is quite versatile involves creating a custom View or SurfaceView in which you Override the onDraw method. Various tutorials can be found on this; the official Android discussion of it is here:
http://developer.android.com/guide/topics/graphics/2d-graphics.html#on-view
Your implementation will look something like this:
// Find elapsed time since previous draw
// Compute new position of drawable/bitmap along figure
// Draw bitmap in appropriate location
// Add line to buffer containing segments of curve drawn so far
// Render all segments in curve buffer
// Take some action to call for the rendering of the next frame (this may be done in another thread)
Obviously a simplification. For a very simplistic tutorial, see here:
http://www.techrepublic.com/blog/software-engineer/bouncing-a-ball-on-androids-canvas/1733/
Note that different implementations of this technique will require different levels of involvement by you; for example, if you use a SurfaceView, you are in charge of calling the onDraw method, whereas subclassing the normal View lets you leave Android in charge of redrawing (at the expense of limiting your ability to draw on a different thread). In this respect, Google remains your friend =]

Android: draw figures on canvas

I m working on canvas. Here I just want to draw some geometric figures on canvas which may be resized according to the touch_move positions. By figures , I just meant triangle,rectangle,circle and some polygons. Is there a way to achieve this? . I haven't seen such apps which can draw these figures over canvas. So this seems to be complicated.. Thanks in advance
See this link.
If your application does not require a significant amount of processing or frame-rate speed (perhaps for a chess game, a snake game, or another slowly-animated application), then you should consider creating a custom View component and drawing with a Canvas in View.onDraw(). The most convenient aspect of doing so is that the Android framework will provide you with a pre-defined Canvas to which you will place your drawing calls.
I'm sure you can find some open-sourced out-of-the-box solutions for this if you tried a little.
If you actually want to learn something you should read the tutorials of per example;
-Custom Views
-OpenGL
After doing the tutorials, you'll have 2 ways to draw basic shapes, a triangle and a circle I believe, already done.

Animate drawn image

I've got some problem. I have an image drawn using canvas, and I would like to animate it. I would like to do something like TranslateAnimation, but TranslateAnimation works only with views, and my image is not a view. What can I do?
Personally I haven't worked with Android canvas, but I am fairly certain that what you need to do is this:
Draw your shape on the canvas
Wait for a couple of miliseconds
Clear the canvas
Redraw shape to next immediate position
and repeat this until the final position is reached.
From my little knowledge the canvas is more similar to a piece of paper than to a flash animation. You need to draw, clear, recalculate, redraw. I highly recommend reading some more on the topic. Firstly, I would start with the android canvas reference: http://developer.android.com/reference/android/graphics/Canvas.html
and then try some tutorials like canvas frame by frame tutorial for android : http://developingthedream.blogspot.ro/2011/01/android-canvas-frame-by-frame-animation.html
And also I highly recommend looking up things on google first before posting a question on stack. There is a good chance, especially if you are a beginner, to find existing tutorials with everything you need and more. Good luck learning.

android canvas draw circles and get touch events

i have been trying to make such a demo where i need to draw many(hundreds of) circle shapes on canvas(or any other way if possible) ,
after drawing the canvas i need to zoom and move it..
and also want to capture the click(touch) event of each shape separately ..
so i know i can get canvas touch event and get x and y positions and check which which circle is touched but i have to draw many circles and as well after zooming and moving the circle's x and y pos is changes so plz help me..
Give me any suggestion how to do this..the way to go..
or if any ANDROID MASTER have done some thing like this..plz plz give me code sample..
thank you all,
good day..
according your requirement you have 2 use one of the android game framework you can find so many game engine check this thread or you can use andengine one of the best 2D game engine in that you can find many example code.
for your requirement just follow the PinchZoomExample from here
any further help comment the question i love to help this prob.

Help with making objects touchable on Android using canvas

I'm trying to create a simple Pegs game. I have drawn the 15-hole board using canvas. I have been programming a while, but games are new to me and I'm stuck on what to do when it comes to handling the pegs. I want to only use the touch screen, but it seems like it is really difficult to touch the pegs and actually select them individually. I plan on just drawing everything programmatically. What is best way on handling this? Using buttons as place holders and changing the button image? Any help would be greatly appreciated.
To be very brief, you have to keep track of the things you draw on the canvas.
I wrote some tutorials for making and moving selectable shapes on the canvas. They should help a lot.
On android it might be a little different than using mousedown, but it should give you a very good starting place.
I don't know if this will help, but you might want to write your own onTouch()function. Check it out

Categories

Resources