Is it possible to get this kind of gradient in cocoa ?
I can use simple CGContextDrawRadialGradient with clip made by CGContextAddEllipseInRect but the effect will slightly different.
Is it any posibility to draw exact this shade/gradient?
I would use a radial gradient, and then apply a scale trasnformation such that the y coordinate is squiched, and the x remains.
There is an advanced topic where you can define your own gradients providing an callback that calculates the color or so. Ist stated in Core Graphics docu.
Related
I've seen many versions of multicolored gradient like images, that are both non linear and heavily stylized. Usually in the form of layered blob like shapes.
My guess as to how they achieve this effect is
drawing intersecting blob like shapes
masking gradients on the shapes
interpolating the colors on the image.
However as you'll notice by the distinct lines in the image the interpolated effect only appears in certain regions of the image. This effect is what I would like to achieve in metal.
One approach is to draw your solid colors and then apply a zoom or motion blur CoreImage filter to achieve the effect of a gradient, leaving some detail by where you place the center (for zoom) or the angle you set (for motion).
Here's an example of a before and a couple afters. The original image in this case is drawn with 2D function plotting but you could easily use a static input image/video-frame, draw an image with filled bezier paths, etc.
The second image uses a CIZoomBlur, input center pt just off image center at (240, 220), with amount set to 134.9.
The CIMotionBlur filter also produces some interesting gradient effects. Here's the same input image, with CIMotionBlur inputRadius 57.6 and inputAngle -0.415.
I think this could achieve what you're after providing you set up the original solid-color image as you like and are able to figure out optimal settings for the filters (angle, center pt etc.).
I'm writing an app that could make good use of the Apple Watch's fitness tracker design, here:
So far, I've created the basic outline which is just a CAShapeLayer with a CGPath of an ellipse. I use strokeStart and strokeEnd to animate the progress. My problem comes when applying a gradient to the outline. How do I apply a gradient like above to the stroke of a CGPath?
The cleanest way to do this without having to drop down to Core Graphics or GL is to create a layer containing the angle gradient that you want the ring filled with, mask it with a CAShapeLayer containing your circular path (with the appropriate line width and cap settings), then, as you’re currently doing, use the shape layer’s strokeEnd property to set the “fill” percentage. Note that there isn’t a built-in way to create an angle gradient—you can use one of the suggestions in this answer for that.
edit: Also, you’ll need a pair of semicircular “cap” images, one at each end of the ring—as the fill percentage gets close to 100%, the region at the top will reveal the discontinuity between the start and end color. In your example image above, you’d need a red semicircle oriented like this ( at the start, and a pink one oriented like this ) with a translation/rotation transform tracking the end.
additional edit: Also also, since the end-cap semicircle will be moving along the gradient, you’ll need it to change color, interpolating from the start color to the end color as the fill amount goes from 0% to 100%. Best way to do that is with a shape layer with a semicircular path, since you can set the fillColor of that without having to redraw image contents.
We did this for an iOS app.. but quickly stopped as it gets bogged down quickly.
I think Apple is using images.. as they do in the Lister example
I am developing a Mac app, I want to draw a view like a radar, I find no method to draw gradient color along the arc. The existing method only draw gradient towards one direction.
What you want is an angle gradient. I've written a Core Image filter that generates an angle gradient; give it an opaque color (e.g., green) for the start color and the completely-transparent version of that color for the middle and end colors.
(The filter's output is actually infinite in extent and centered at the origin, so you'll need to mask it out to a circle and use an affine transform at one level or another to get it into the right position.)
Extra credit: In the kernel code for that filter (near the start of the .m), there's a line that starts the gradient at straight-up (90°) rather than straight-right. You could change the code, both of the filter and of the kernel, to make this a parameter (like inputStartColor et al) that you could vary over time, using a CABasicAnimation or something similar.
You'll need to use a combination of axial and radial gradients and probably also some clipping paths. You can find all of this documented here.
You can also use colorWithPatternImage: to stroke any lines you're drawing.
I´m doing some testing on gradients using NSBezierPath and make some progress so far with radial gradients. see first picture. I wonder, however, if it is possible to make angle gradients as in picture 2.
Anyone done this?
Tia, Ronald
Cocoa has no public API for angular gradients. You'll have to do it yourself by painting pixels in varying colors.
Good Question!
There is no Standard Feature.
Try to approx by dividing the Circle into sectors which functions as clipping Polygon
Then draw a linear Gradient in direction 90 degrees to the Center line of the sectors.
I'm creating heightmaps using Fractal Brownian Motion. I'm then coloring it based on the heights and mapping it to a sphere. My problem is that the heightmap doesn't wrap seamlessly. I've used the Diamond Square algorithm and it's pretty easy to make things seamless using it, but I can't seem to figure out how to do it with fBm and I seem to be having trouble finding an explanation for it on the web.
To clarify, by "seamless", I mean that when I map it to a sphere, it creates a seamless map on the sphere.
Instead of calculating the heightmap per pixel on the heightmap, calculate the heightmap in 3D space based on each point on the sphere and then map that to an image pixel. You're going to have trouble wrapping a 2D, rectangular heightmap like that onto a sphere without getting ugly results at the poles unless you start your calculations from the sphere.
fBM generalizes to 3 dimensions, so given a point on the sphere you can get the height at that point, and then you can do the math to map that value to where it should be stored in the heightmap image.
Or you could use one of the traditional map projections. A cylindrical projection (x, y)->(x, sin y) would give you a seam of just one meridian, which you could rotate to the back. Or you could "antialias" the edge by one or another means.
With a stereographic projection (x,y,z)->(x/(z+1),y/(z+1)), there's only one sour point (the projection point itself).