Suffick
Suffick

Reputation: 651

Java wiggling line

I have an unusual question that hopefully someone can help me with. I want to draw a wiggling or waving line with Canvas (android), but I can't get my head around how to do it. It's going to be a tadpole's tail, so ideally I want it more triangle shaped, larger at one end but that's not essential. I expect it's achievable somehow using a Path, but I'm not sure how. I've Googled around but can't find a solution, suggestions are much appreciated.

Thanks.

Upvotes: 2

Views: 207

Answers (1)

Simon
Simon

Reputation: 14472

Create a sine wave generator that takes the phase (angle) to start from as a parameter and have it return an array of plot points ([x][y]). Then plot these points on your canvas. You can make the line wave by varying the starting phase from 0 to 360 over time. How quickly you vary x determining how fast your line waves.

Try starting here for sine wave generators:

http://www.drdobbs.com/jvm/music-components-in-java-creating-oscill/230500178

If you need a lot of tadpoles, then this might be too processor intensive in which case, you could draw a set of sine waves, say 30 with the beginning angle in steps of 12, then draw these to your canvas in sequence.

Upvotes: 1

Related Questions