I was wondering if there's a hack to draw an ellipse instead of a circle. SVG itself does provide an ellipse element, e.g.:
<ellipse cx="200" cy="80" rx="100" ry="50">
Related
Can konva draw an ellipse arc?
I want to draw an ellipse arc(spanAngle = 180)with two different radii such as 40 and 70.
Is there an API that I can use?
https://konvajs.org/docs/shapes/Arc.html in this demo i can only draw circle arc ,now i want to draw an ellipse arc(different radius are 40 and 70)
I have a list view with "Hero" icons on the left. When I click a list item, it loads the next screen with the article text and the Hero image (which animates nicely/automatically to the correct spot on the 2nd screen).
I would have thought that was the "tough" part, but I'm now trying to get a curved shape as the top background of the 2nd screen. I would love to make it a drawn vector shape, as opposed to a bitmap and even have it drip/bounce onto the page, but at the moment...
I'm just trying to figure out how to:
draw a vector shape
have it as the background of a screen with other widgets on top (see purple curve on 2nd screen below)
I made a full sample for your curved shape in a gist here
I used CustomPainter to draw on a canvas then, with some geometric calculations, I achieved the curved shape.
Final result
How I draw it?
Before coding and on a Whiteboard I determined somethings:
My Canvas Area:
The canvas dimensions I need to draw that shape (which equals to Flutter widget's dimensions).
How and where my brush will move?
how means: what are the APIs I need to draw that shape on the canvas using the Path class.
e.g. lineTo() for a straight line, quadraticBezierTo() for a curve.
where means: Where are the points (coordinates) I need to draw the whole shape. (see yellow and green dots in the image above)
Points (coordinates) Calculations:
I used some geometric equations to calculate the coordinates. e.g. Point on a circle’s circumference
All of my calculations depend on the canvas size, that gives me a responsive shape.
Full sample here!
I want to map a texture image of rectangular shape into a curved area. The curved area has a axis defined by bezier curve and fixed width.
I can map the points on the axis to the texture by percentile, and get a stripe of pixels to fill the region. But this way the left side of the region is "stretched", and I get unfilled gaps.
How can I map the texture to the curved area "smoothly"? Is there an algorithm for such a task?
To answer my own question:
My own naive solution is to fill the gaps(trianglar area in the image) with pixel values by interpolating between the adjacent points on normal vectors.
Later I found a more mathematical solution to this problem in a paper:
http://www.stat.ucla.edu/~sczhu/papers/Conf_2011/portrait-painting-preprint.pdf
It map the grids of the rectanglar texture to the spline-shaped area with a method called thin-plate spline (TPS) transformation:
we compute a thin-plate spline (TPS) transformation [Barrodale
et al. 1993] between the pairs of source and target dot positions
(e.g., between the corresponding backbone control points in Figs.4a
and 4b), and apply the transformation to the vertices of a quadrilateral
mesh covering the source brush stroke to get the deformed
mesh. Finally, we compute a texture mapping using the mesh, with
a bilinear interpolation inside each quadrilateral.
I am thinking maybe the same transformation can be done with bezier curves.
Hope this is helpful.
In OpenCV, i know how to draw circles, but is there a way to get back all the points that makeup the circle? I hope I dont have to go through calculating contours.
Thanks
If you know how to draw the circle,
Create a black image with the same size of as that of original image
Then draw the circle on the black image with white color
Now in this black image, check the points which are white
If you are using Python API, you can do as follows :
import numpy as np
import cv2
img = np.zeros((500,500),np.uint8)
cv2.circle(img,(250,250),100,255)
points = np.transpose(np.where(img==255))
You can do similar thing to the answer implemented in python in C/C++
If you know how to draw the circle,
Create a black image with the same size of as that of original image
Then draw the circle on the black image with white color
Now instead of checking which pixels have certain value you can find a contour (represented as vector of points) of the circle's edge.
To do this you can use OpenCV's findContours function which will give you the points on the circles edge.
Actually the background doesn't have to be black and the circle white, but the background should be plain and the circle should have different color than background.
i have been trying to draw a rounded rectangle with spacing in the border, but i cant seem to find a way to do this using the Canvas.RoundRect function, and i am not that good in maths to draw the edges myself, i can draw a rectangle with spacing using the Canvas.MoveTo and Canvas.LineTo functions, but i dont know how to make the edges rounded. Currently what i am doing is i make yellow rectangle at the place where i want to make the spacing in the border but the problem is when i am printing i have to directly draw on printer canvas and i have to draw on a transparent sheet, so a background color will cause problems. Anyone who can help me build a custom drawing routine or tell me how can i erase that area and still print on a transparent paper without any background color. The yellow background color is just for a preview, when i am drawing to a printer canvas the background is transparent.
See the image to know what i mean by spacing in the border line.
Thanks
You can exclude the gap by manipulating the clipping region of the current device context. Assuming that L, R, T and B are the coordinates of your yellow rectangle to make the gap, use the following code:
ExcludeClipRect(Canvas.Handle, L, T, R, B); // exclude the gap
Canvas.RoundRect(<whatever you already do here>);
SelectClipRgn(Canvas.Handle, 0); // reset the clipping region
You can draw your partial rounded rectangle yourself. Use MoveTo and LineTo for the straight portions, and use Arc for the corners.
The Arc function draws a portion of an ellipse. The first two pairs of coordinates to the function indicate the bounds of the ellipse. If you want the corners of your rectangle to be circular, then the ellipse is a circle, and X2 - X1 will equal Y2 - Y1. The second two pairs of coordinates indicate the starting and ending points on the circle; they'll be the same points you pass to MoveTo and LineTo for the straight portions. The arc is drawn counter-clockwise.