StarlingGraphics / Starling-Extension-Graphics

flash.display.Graphics style extension for the Starling Flash GPU rendering framework
https://github.com/StarlingGraphics/Starling-Extension-Graphics/wiki
MIT License
285 stars 88 forks source link

Drawing natural cubic splines #48

Closed DrSchizo closed 10 years ago

DrSchizo commented 11 years ago

The curveTo() function of the graphics extension is a great feature but the use of control points make it pretty complicated to manage.

I found few AS3 scripts that allows you to draw a smooth line through a series of points on a map without having to deal with control points. You can see some pratical examples like the green line in here and here.

The first example has been made by Nicoptere on this page

The second one has been ported in AS3 by Daniel McLaren here

There are as well some alternative methods on this thread.

I've ported Nicoptere's class to Starling: Example Source code A glowing river

Would it be complicated to add this to the graphics extension?

IonSwitz commented 11 years ago

I've spent some time to convert this math into the "GraphicsEx" framework, ensuring that you can specify a dynamic thickness and alpha along the full length of the curve as well.

See this issue for further discussion about the GraphicsEx addition.

https://github.com/StarlingGraphics/Starling-Extension-Graphics/issues/52

I will upgrade the zip file content (mentioned in the other thread) later tonight. Or, I might even manage to understand how to use "fork, clone, commit, push" in Git , AND make it work ;)

IonSwitz commented 11 years ago

The code has now been gently modified and added to the ZIP file here, for anyone who feels like playing with it. It has been redesigned to work with alpha and thickness.

https://dl.dropboxusercontent.com/u/107200878/StarlingExtensionGraphicsEx.zip

robsilv commented 11 years ago

Hi @IonSwitz, thanks for your updates. Have you tried using the mac or windows client for GitHub? http://mac.github.com/ http://windows.github.com/ They make the whole process of updating your fork a lot easier! :-)

IonSwitz commented 11 years ago

No problem, @robsilv , I love to contribute. :) But I am running into newbie issues with Git, and there's a workflow that i haven't understood.

I pressed "Fork" here at the Project , but that (apparently) didn't do much. When I do a clone operation, to get the repository, I seem to get the master branch, and on the master branch, I am not allowed to commit code (which seems reasonable)

So.. somehow I need to be able to make sure that I can pull down and commit/push to the fork I created. But I don't see how I make that happen. So, yeah, I feel pretty damn dumb here ;)

IonSwitz commented 11 years ago

But, hey, I think I managed to get a IonSwitz fork going now, with the checked in code. Wahey! ;)

robsilv commented 11 years ago

Anyone who can update this graphics extension isn't dumb in my book! ;-) Git takes a bit of getting used to, but I'm a convert now, being able to review and discuss the code so clearly on github.com is a huge bonus. The best plan I think is to do as much via the user interface as possible to begin with.

When you fork a project, you create a personal copy of the project that appears on your personal GitHub profile. You can then select that fork from your GitHub Mac or Windows desktop client and "clone" (copy) it to your machine (defaults to documents/github/myFork I think). Point your code editor to that copy of the code and edit it in situ, GitHub will track any changes. When you want save revisions to your fork locally, make a commit and give it a name. When you want to sync those commits with your fork on GitHub.com, press the "sync" button.

When you're happy with the updates to your fork and you want to get them into the main project, create a "pull request" by clicking the button on your fork on github.com. The owner of the main project then receives a message asking them if they want to merge these changes into the master.

Hope that helps!

makc commented 11 years ago

personally I am big fan of tortoise tools. after tortoise, github own tools seem unnatural.

Have you tried using the mac or windows client for GitHub?

that assumes windows, of course.

robsilv commented 11 years ago

I've used Tortoise & SVN for most of my career and found them to be pretty useful, but never liked the fact that SVN scatters your entire project with hidden folders; I often ran into intractable issues with renaming/moving files and folders. GitHub was a world of pain for me to begin with, but when the windows client came out and I started to get more confident with the Command Prompt, it all started to fall into place and I learned to love it. Plus this website is just incredibly awesome.

@IonSwitz, one other thing (which I'm sure you're familiar with from your extensive non-GitHub version control experience): Please try to get into the flow with GitHub and regularly commit small batches of clearly labelled changes to your fork, this way it'll be much easier for us to understand your intent and merge pull requests.

Thanks Rob

makc commented 11 years ago

tortoise is not only for svn, it does have git client.

robsilv commented 11 years ago

Aha... I wasn't aware of that.

IonSwitz commented 11 years ago

@robsilv Ok, I will try to remember that. I just undid a big batch of nasty code to implement the post process step, but I haven't committed anything since I also wanted to do the private to protected stuff across the board, and not just for the classes I am so far using.

But maybe it is better to do it in small increments. Thanks! :)

jonathanrpace commented 11 years ago

FYI - Tortoise-SVN has recently done away with the .svn folder everywhere. There's now just a single one at the top of your hierachy (much like git).

robsilv commented 11 years ago

Nice.

robsilv commented 11 years ago

@IonSwitz thanks! Please obviously do whatever feels right, so long as it isn't "here's 1000s of changes in one big commit because I don't like Git!" ;-P

makc commented 11 years ago

@robsilv at the same time it's not like you would cherry-pick through 1000 small commits instead.

robsilv commented 11 years ago

@makc indeed.

robsilv commented 11 years ago

@DrSchizo, sorry for hijacking your thread! @IonSwitz, does your latest commit help @DrSchizo with his issue?

IonSwitz commented 11 years ago

@robsilv Yes, the method naturalCubicSplineTo in GraphicsEx does exactly what @DrSchizo does in the sample code he provides. In fact, this code has been ripped forcefully from the example he provided himself here:

http://www.schizogame.com/test/starling/natural_cubic.zip

All I did was to change a few method names to fit better with the Graphics naming convention. ( "naturalCubicSplineTo" sounds more like "curveTo" and "lineTo" than the original "compute". )

A few changes have been made, to work with the basic "LineTo" structure of the curve code in Graphic, and I cant rule out that I have introduced some bug, but to me it seems to work.

If @DrSchizo want more credit than what I have added to the GraphicsEx code, that's understandable, and I can add more of that, in that case.

I have tried to keep my name away from any comments in the other new code I wrote, but I don't minde putting his name, or his website, in there, if he would want it.

IonSwitz commented 10 years ago

Closing this Issue