I'm using Core Plot to draw a scatter graph. The points (which are in an ordered sequence) are connected by line segments. I need to visualize the line direction (and it might overlap or cross itself). I've been able to set each of the points to a different color form dark to light, like this:
and
I'd like to have the line change color, too, in a linear fashion from the first point to the last. How can I use CPTGradient to do this?
You can't. The gradient options for lines in Core Plot are the lineGradient to give the line a 3D effect or the lineFill (with a gradient fill) to fill the entire line path with a gradient. The lineFill works by using the line path as a mask to show part of a rectangle filled with the gradient.
Related
I found a graph on the internet that I am trying to mimic. The line has a linear gradient inside the line to make it appear cylindric. Is there an option to add this in high charts? I found I can apply a linear gradient with fixed xy coordinates but they are not relative to the line but the background of the graph it self.
Me and my team are working on an app for a client. We are trying to understand how to achieve this kind of animations (refer only to the circle stroke) :
We tried using a CADisplayLink to set up and change the circle, but it generated non-fluid results.
We couldn't find a way to create a circle from "components" of UIBezierPath and change each of the anchors.
Any suggestions on how to achieve this kind of effect, or how to construct a circle from seperated points, would be highly appricated
Best Regards,
Roi and the team
I suggest using Catmull-Rom splines. Those allow you to create smooth curves using only points that are on the curve, whereas Bezier curves require that you define control points that are not on the curve.
Once you have beginning and ending CGPaths its pretty easy to create a CAAnimation of the path from it's starting to it's ending state (although animating change to a CGPath only works correctly if the starting and ending paths in the animation have the same number and type of points.)
You could probably also use Bezier curves, but you would need to generate the control points for the circle and it's distorted shape.
Check out this sample app that uses Catmull-Rom splines to create a distorted circle shape:
http://wareto.com/animating-shapes-using-cashapelayer-and-cabasicanimation
(Written in Objective-C, but the technique is the same in Swift.)
A Catmull-Rom spline with 8 control points evenly spaced around a circle where the distance from the center of each control points is varied by ± r/12 seems about right:
There a is an ellipse on the picture,just as following.
I have got the points of the contour by using opencv. But you can see the pictrue,because the resolution is low, there is a straight line on the contour.How can i fit it into curve like the blue line?
One Of the method to solve your problem is to vectorize your shape (moving from simple intensity space to vectors space).
I am not aware of the state-of-art in this field. However, from school information, I can suggest this solution.
Bezier curves, you can try to model your shape using simple bezier curve.This is not a hard operation you can google for dozen of them. Then, you can resizing it as much as you want after that you may render it to simple image.
Be aware that you may also Splines instead of Bezier.
Another method would be more simple but less efficient. Since you mentioned OpenCV, you can apply the cv::fitEllipse on the points. Be aware that this will return a RotatedRect which contains the ellipse. You can infer your ellipse simply like this:
Center = Center of RotatedRect.
Longest Radius = The Line which pass from the center and intersect with the two small sides of the RotatedRect.
Smallest Radius = The Line which pass from the center and intersect with the two long sides of the RotatedRect.
After you got your Ellipse Parameters, You can resize it as you want then just repaint it in the size you want using cv::ellipse.
I know that this is a pseudo answer. However, I think every thing is easy to apply. If you faced any problem implementing it, just give me a comment.
Hi I am trying to implement a polygon with a color gradient based on the color of each corner (the polygon is an overlay for a map). Up until now I have been using MKPolygon. Any Guidance will be appreciated.
Thanks,
To Achieve my result I wrote a for loop that iterated through all the points, which had a for loop inside that subtracted a value from the other points to make the polygon smaller and created a polygon this was done until the polygon was small enough for the view. This gave it a nice gradient and doing it for the other cornea with different colors gave the desired gradient of colors.
I'm using a Core Plot Scatter Plot to chart data. While I want the background to be white, I'd like to mask the plot symbols and data lines to an image sitting beneath the graph. This way, the only parts of the image visible would be the "fill" of the scatter plot lines and plot symbols.
How can I mask lines and symbols to an image while still keeping the background white?
Here's a Photoshop Mockup of what I'd like to do:
Thanks!
I'm not sure it's possible. The final result will depend on the image you're trying to use. The plot is drawn on top of the plot area and graph fills. You might be able to use image fills for the line and plot symbols. Experiment with the tiled and tileAnchoredToContext properties of CPTImage to see if you can position the fill images in a way that mimics the effect you're looking for.