Fill color in circle in List box using another List box have color and may its muliple in c#.net - c#-3.0

as you saw me how to draw circle using listbox now i want to fill color in List box each circle using another List box when color is defined ....it is multiple color also we can apply .. please help me in this.. in winforms in c#.net

Not sure if this is what you're asking, exactly, but you can use the same code as in the answer to your previous question, only use Graphics.FillEllipse instead of Graphics.DrawEllipse. This method uses a SolidBrush instead of a Pen.
Update: I think this is what you want. Take this line from your original answer:
e.Graphics.DrawEllipse(Pens.Blue, new Rectangle(1, 1+e.Index * 15, 100, 10));
and change it to this:
e.Graphics.FillEllipse(Brushes.Blue, new Rectangle(1, 1+e.Index * 15, 100, 10));
If you need to use different colors, you can use some variant of this:
SolidBrush brush;
Random rnd = new Random();
if (rnd.NextDouble() < 0.5)
{
brush = new SolidBrush(Color.Red);
}
else
{
brush = new SolidBrush(Color.Blue);
}
e.Graphics.FillEllipse(brush, new Rectangle(1, 1+e.Index * 15, 100, 10));
instead of using the Brushes enumeration.
Update 2: to draw a circle that is half one color and half another color, you'd want to use FillPie:
e.Graphics.FillPie(Brushes.Blue, new Rectangle(1, 1+e.Index * 15, 100, 10),
-90, 180);
e.Graphics.FillPie(Brushes.Red, new Rectangle(1, 1+e.Index * 15, 100, 10),
90, 180);

Related

Anylogic: Adding text label to Rectangular Wall

Is it possible to add a text label on top of rectangular walls in Anylogic? I am trying to dynamically create rectangular walls using code and then adding labels. So far I am able to create the walls but the text label does not appear on top of the walls as I want it.
If you are creating walls dynamically I assume you also want to create your text dynamically.
There is a little trick in AnyLogic where you can view the code that gets created for you by AnyLogic discussed in this blog post
You can use the code snipped below to draw a Text object and add it to the presentation collection (which is needed for it to be displayed)
Font _text_Font = new Font("SansSerif", 0, 10 ); // Only needed if you don't have any text in your agent else _text_Font gets created for you.
ShapeText myProgramticallyCreatedText = new ShapeText(
SHAPE_DRAW_2D, true,170.0, 90.0, 0.0, 0.0,
black,"Programatically Created text",
_text_Font, ALIGNMENT_LEFT );
presentation.add(myProgramticallyCreatedText);
Here is the syntax for creating your
ShapeText(boolean ispublic, double x, double y, double rotation, java.awt.Color color, java.lang.String text, java.awt.Font font, TextAlignment alignment)
Constructs a 2D-only text shape with specific attributes.
ShapeText(ShapeDrawMode drawMode, boolean ispublic, double x, double y, double z, double rotation, java.awt.Color color, java.lang.String text, java.awt.Font font, TextAlignment alignment)
Constructs a text shape with specific attributes.
Depending on whether or not you have 3D or not you can rotate the text by changing the correct parameters
If you want to make it visible in 3d and also rotate it correctly you need to create a group, add the text to that group, then create a new group, and the group this new group and then rotate the first group. Like below
Font _text_Font = new Font("SansSerif", 0, 10 );
ShapeText myProgramticallyCreatedText = new ShapeText(
SHAPE_DRAW_2D3D, true,170.0, 90.0, 0.0, 0.0,
black,"Programatically Created text",
_text_Font, ALIGNMENT_LEFT );
ShapeGroup innerGroup = new ShapeGroup(this, SHAPE_DRAW_2D3D, true, 170.0, 20.0, 0.0, 0.0 , myProgramticallyCreatedText );
ShapeGroup outerGroup = new ShapeGroup(this, SHAPE_DRAW_2D3D, true, 170.0, 20.0, 0.0, 0.0 , innerGroup );
innerGroup.setRotationX(-PI/2 );
presentation.add(outerGroup);
(P.S. I figured all of this out using the trick from the blog post referenced above ;-) )
If it should show horizontally on top of the wall, just ensure it has the same x,y coordinates as the center of the wall and then set the z-coordinate higher than the wall height.
If you want to show it vertically (like a clock hanging from the wall), you need to set the xY coordinates carefully so it does not display inside the wall. Z coordinate half way of the wall height. And then you need to do a trick to turn the text: put it into a group and rotate the group. The example model "Airport terminal" does that, check it out

How to add a buffer with fixed size in pixels using leaflet and turf

I'm trying to create a buffer with fixed size using leaflet and turf, the buffer should be created when the mapClick event is emitted, so basically a buffer is created when I click the map
when creating a buffer or a circle you need to pass a radius property which is pretty much the "size" of the buffer, which can be in Kilometers, Meters, Miles and so on
The problem is: I need the buffer to always be the same size in pixels regardless of the mapZoom or Scale, for instance, using circle:
const center = [LatlongFromMouseEvent];
const radius = 5;
const options = {steps: 10, units: 'kilometers', properties: {foo: 'bar'}};
const circle = turf.circle(center, radius, options);
OR using buffer
const point = turf.point([LatlongFromMouseEvent]);
const buffered = turf.buffer(point, 5, {units: 'kilometers'});
OR using native Leaflet "Circle" constructor
const lCircle = new Circle([event.latlng.lat, event.latlng.lng], {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5,
radius: 500
})
lCircle.addTo(mapInstance)
All of those "buffers" will change it's size depending on the level of zoom of the map
AND "circleMarker" from leaflet automatically changes size when you change the zoom
Found a solution by using the metersPerPixel formula
const zoom = map.getZoom()
const lat = map.getCenter().lat
const metersPerPixel = 156543.03392 * Math.cos(lat * Math.PI / 180) / Math.pow(2, zoom)
const radius = metersPerPixel * sizeInPixels
More info about the formula in:
https://gis.stackexchange.com/questions/7430/what-ratio-scales-do-google-maps-zoom-levels-correspond-to

How to locate list of widgets along the curve in Flutter?

Please tell me, is it possible to locate list of widgets along the curve? Like on picture, Let's say teeth are widgets.
If you don't want to use Stack, then you might try out the CustomPaint widget and drawing in flutter with paths.
There's a tutorial to painting: https://medium.com/flutter-community/paths-in-flutter-a-visual-guide-6c906464dcd0
However, painting is a limited thing and if you have an actual widgets that need to be fully responsive and act as a widgets, you need to use Stack with Positioned. That's the only way to go.
Also, in this question about animating along the curve in flutter you can find some code examples that use both: painting and stack and even animate that. Possibly the most useful code from there is calculating the position of an object that you want to place along some curve:
Offset calculate(path, along) {
PathMetrics pathMetrics = path.computeMetrics();
PathMetric pathMetric = pathMetrics.elementAt(0);
along = pathMetric.length * along;
Tangent pos = pathMetric.getTangentForOffset(along);
return pos.position;
}
In above example you need to have some Path which is a representation of some curve. For example you can get one like this:
Path getPath(){
Size size = Size(300,300);
Path path = Path();
path.moveTo(0, size.height / 2);
path.quadraticBezierTo(size.width / 2, size.height, size.width, size.height / 2);
return path;
}
then you give this path and some along, which is number between 0 and 1, which represents beginning and ending of this curve and you give it to the calculate, which return and Offset, which you can use in your Positioned inside your Stack:
Positioned(
top: calculate(path, along).dy,
left: calculate(path, along).dx,
child: ...
When you only want some shapes to be drawn on a screen then you can use simply painting with CustomPaint widget, but this objects won't be widgets

Creating a responsive scatter plot with flutter

I am trying to create a venn diagram of two elements from a scatter plot widget on package fl_chart.
scatterPlot(screenSize) {
return ListView(children: [
SizedBox(
width: 500,
height: 500,
child: ScatterChart(
ScatterChartData(
scatterSpots:
_createSpots(determineCircleLocation(screenSize), screenSize),
minX: 0,
minY: 0,
maxX: screenSize.width,
maxY: screenSize.height,
borderData: FlBorderData(show: false),
...
I have this problem that whenever I resize my window the scatter circles are moving - so if at a full screen it appeared that they had no intersection, when I resize the screen it appears like it has an intersection.
I was trying to wrap my plot in a SizedBox thinking that would stop the resizing side effects but it didn't.
Here's a demo of the problem
Is there a way to prevent this from happening?
While writing this I thought that by changing maxX and maxY to be some constants could help, but it resulted even worst outcome.
because we set a direct size (no matter in which size is it running) this problem happens.
You can check the window size, then update the dot's radius based on the window size.
(I calculated a number, then multiplied with radiuses).
Watch the video below. and check the code here:
LayoutBuilder(
builder: (context, constraints) {
final size = constraints.biggest.shortestSide;
final radiusMultiplier = size / 800;
return Padding(
padding: const EdgeInsets.only(right: 18.0),
child: ScatterChart(
ScatterChartData(
scatterSpots: [
ScatterSpot(5, 7, radius: 60 * radiusMultiplier,),
ScatterSpot(8, 4, radius: 20 * radiusMultiplier,),
ScatterSpot(3, 8, radius: 70 * radiusMultiplier),
],
minX: 1,
maxX: 10,
minY: 1,
maxY: 10,
)
),
);
},
)

Uneven borders of ellipse annotation when I try to rotate the PDF

I am trying to draw ellipse on a rotated PDF but the border of the ellipse appears thick and thin in center
Sample Code:
PdfAnnotation annotation = PdfAnnotation.createSquareCircle(stamper.getWriter(), rect, null, false);
annotation.setFlags(PdfAnnotation.FLAGS_PRINT);
annotation.setColor(getColor(annot.getBorderColor()));
// annotation.setBorder(new PdfBorderArray(2, 2, 2));
// annotation.setColor(getColor(annot.getBorderColor()));
annotation.setBorderStyle(new PdfBorderDictionary(3.5f, PdfBorderDictionary.STYLE_SOLID));
PdfContentByte cb = stamper.getOverContent(page);
if ((int) (orientation % 360) == 90 || (int) (orientation % 360) == 270)
{
w = rect.getHeight();
h = rect.getWidth();
}
else
{
w = rect.getWidth();
h = rect.getHeight();
}
PdfAppearance app = cb.createAppearance(w + 3.5f, h + 3.5f);
app.setColorStroke(getColor(annot.getBorderColor()));
app.setLineWidth(3.5);
app.ellipse(rect.getLeft() + 1.5, rect.getBottom() + 1.5, rect.getRight() - 1.5, rect.getTop() - 1.5);
app.stroke();
annotation.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, app);
stamper.addAnnotation(annotation, page);
As already assumed in a comment a feature of iText (for rotated pages it attempts to pretend to the user that he has an upright coordinate system, not a rotated one) gets into your way. This feature unfortunately does only affect the dimensions of the annotation itself, not of the appearances you create for it.
If a page has a 90° or 270° rotation, therefore, you have to use appearance dimensions whose width and height are switched compared to the annotation dimensions you used.
Furthermore, one also has to consider the switched dimensions when drawing the ellipse on the appearance template. The code in the question and in the example code shared via google drive forgot this.
Finally, one shall not override the switched dimensions of the appearance template using PdfAppearance.setBoundingBox. The code in the example code shared via google drive did this.
False Example
If I create an ellipse annotation with appearance on a rotated page like this:
Rectangle rect = new Rectangle(202 + 6f, 300, 200 + 100, 300 + 150);
PdfAnnotation annotation = PdfAnnotation.createSquareCircle(stamper.getWriter(), rect, null, false);
annotation.setFlags(PdfAnnotation.FLAGS_PRINT);
annotation.setColor(BaseColor.RED);
annotation.setBorderStyle(new PdfBorderDictionary(3.5f, PdfBorderDictionary.STYLE_SOLID));
PdfContentByte cb = stamper.getOverContent(1);
PdfAppearance app = cb.createAppearance(rect.getWidth(), rect.getHeight());
app.setColorStroke(BaseColor.RED);
app.setLineWidth(3.5);
app.ellipse( 1.5, 1.5, rect.getWidth() - 1.5, rect.getHeight() - 1.5);
app.stroke();
annotation.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, app);
stamper.addAnnotation(annotation, 1);
(CreateEllipse test testCreateEllipseAppearanceOnRotated)
I indeed get a funny ellipse:
Correct Example
If I create an ellipse annotation with appearance on a rotated page with switched dimensions like this, though:
Rectangle rect = new Rectangle(202 + 6f, 300, 200 + 100, 300 + 150);
PdfAnnotation annotation = PdfAnnotation.createSquareCircle(stamper.getWriter(), rect, null, false);
annotation.setFlags(PdfAnnotation.FLAGS_PRINT);
annotation.setColor(BaseColor.RED);
annotation.setBorderStyle(new PdfBorderDictionary(3.5f, PdfBorderDictionary.STYLE_SOLID));
PdfContentByte cb = stamper.getOverContent(1);
// switched appearance dimensions
PdfAppearance app = cb.createAppearance(rect.getHeight(), rect.getWidth());
app.setColorStroke(BaseColor.RED);
app.setLineWidth(3.5);
// draw ellipse using switched appearance dimensions
app.ellipse( 1.5, 1.5, rect.getHeight() - 1.5, rect.getWidth() - 1.5);
app.stroke();
annotation.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, app);
stamper.addAnnotation(annotation, 1);
(CreateEllipse test testCreateCorrectEllipseAppearanceOnRotated)
I get the expected ellipse: