how to fill through color in CGContextStrokeLineSegments? - iphone

i am using the code to draw a triangle , but how to fill color in it.
CGContextSetRGBStrokeColor(c, 255, 0, 255, 1);
//CGContextSetRGBStrokeColor(c, 1.0, 1.0, 1.0, 1.0);
// Drawing with a blue fill color
CGContextSetRGBFillColor(c, 0.0, 0.8, 1.0, 1.0);
CGPoint points[6] = { CGPointMake(142, 200), CGPointMake(150, 250),
CGPointMake(150, 250), CGPointMake(135, 250),
CGPointMake(135, 250), CGPointMake(142, 200) };
CGContextStrokeLineSegments(c, points, 6);

First create a path, then fill it:
CGContextSetRGBFillColor(c, 0.0, 0.8, 1.0, 1.0);
CGPoint points[6] = { CGPointMake(142, 200), CGPointMake(150, 250),
CGPointMake(150, 250), CGPointMake(135, 250),
CGPointMake(135, 250), CGPointMake(142, 200) };
CGContextAddLines(c, points, 6);
CGContextClosePath(c);
CGContextFillPath(c);

Related

[Dart][Flutter] How to exclude multi-lines from "Format On Save" in Visual Studio Code?

I am working on a Flutter project where the Formatting is set to the default Dart recommends VSCode formatter setting. Is there any way to exclude multi-lines from formatting when VS is set to format modified code/file on save?
I refer to this answer to exclude each line. The code below worked:
msg.pose.covariance = [
0.25, 0.0, 0.0, 0.0, 0.0, 0.0, // noqa
0.0, 0.25, 0.0, 0.0, 0.0, 0.0, // noqa
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, // noqa
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, // noqa
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, // noqa
0.0, 0.0, 0.0, 0.0, 0.0, 2.25 // noqa
];
Now I want to exclude multi-lines with similar this answer. The expected code like Python (black formatter):
// dart: fmt_off
msg.pose.covariance = [
0.25, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.25, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 2.25
];
// dart: fmt_on
As explained in the Dart formatter's FAQ, you just need to have a single comment within the collection literal to prevent the formatter from reformatting it:
So, if you have a collection that you have carefully split into lines, add at least one line comment somewhere inside it to get it to preserve all of the newlines in it.

Optimal number of clusters - Error in FUNcluster(x, i, ...) : more cluster centers than distinct data points

I have these data and I need to find the optimal number of clusters of this table.
The values can be either 0, 0.5 or 1
library(NbClust)
library(factoextra)
library(pheatmap)
tab=structure(list(`57-B1` = c(1, 0.5, 0.5, 1, 1, 0.5), `57-B3` = c(0.5,
0.5, 0.5, 0, 0.5, 0.5), `57-C1` = c(1, 0.5, 0.5, 0.5, 1, 0.5),
`57-C5` = c(1, 0.5, 0.5, 1, 1, 1), `57-H2` = c(1, 0.5, 0.5,
0, 1, 1), `57-H4` = c(0.5, 0.5, 0.5, 0, 0.5, 0.5), `61-1-B1` = c(0.5,
0.5, 0.5, 0, 0.5, 0.5), `61-1-C2` = c(0.5, 0.5, 0.5, 0, 0.5,
0.5), `61-1-C5` = c(0.5, 0.5, 0.5, 0, 0.5, 0.5), `61-1-H1` = c(0.5,
0.5, 0, 0, 0.5, 0.5), `61-1-H3` = c(0.5, 0.5, 0.5, 0, 0.5,
0.5), `61-1-H5` = c(0.5, 0.5, 0, 0.5, 0.5, 0.5), `62-2_H2` = c(0.5,
0.5, 0.5, 0, 0.5, 0.5), `62_1_C2` = c(0.5, 0.5, 0, 0.5, 0.5,
0.5), `62_1_C5` = c(0.5, 0.5, 0.5, 0, 0.5, 0.5), `FL-39-C3` = c(0.5,
0.5, 0.5, 0, 0.5, 0.5), `FL-41-1-C3` = c(0.5, 0.5, 0.5, 0,
0.5, 0.5), `FL-57-B1` = c(0.5, 0.5, 0.5, 0, 0.5, 0.5), `FL-57-B2` = c(0.5,
0.5, 0.5, 0, 0.5, 0.5), `FL-57-C2` = c(0.5, 0.5, 0, 0.5,
0.5, 0.5), `FL-57-C3` = c(1, 1, 1, 0, 1, 1), `FL-57-C5` = c(1,
0.5, 0.5, 1, 1, 1), `FL-57-H1` = c(1, 0.5, 0.5, 1, 1, 1),
`FL-57-H4` = c(0.5, 0.5, 0, 0, 0.5, 0.5), `FL-57-H5` = c(0.5,
0.5, 0.5, 0, 0.5, 0.5), `FL-61-1-B1` = c(0.5, 0.5, 0.5, 0,
0.5, 0.5), `FL-61-1-B4` = c(0.5, 0.5, 0.5, 0, 0.5, 0.5),
`FL-61-1-C2` = c(0.5, 0.5, 0, 0, 0.5, 0.5), `FL-61-1-C4` = c(0.5,
0.5, 0.5, 0, 0.5, 0.5), `FL-61-1-H3` = c(0.5, 0.5, 0.5, 0,
0.5, 0.5), `FL-61-1-H4` = c(0.5, 0.5, 0.5, 0, 0.5, 0.5),
`FL-61-1-H5` = c(0.5, 0.5, 0, 0.5, 0.5, 0.5), `FL-62-1-C3` = c(0.5,
0.5, 0, 0.5, 0.5, 0.5), `FL-62-2-H2` = c(0.5, 0.5, 0.5, 0,
0.5, 0.5), `FL-73-H1` = c(0.5, 0.5, 0.5, 0, 0.5, 0.5), P_57_F = c(0.5,
0.5, 0.5, 0, 0.5, 0.5), P_57_M = c(0.5, 0.5, 0.5, 0, 0.5,
0.5)), row.names = c("g1", "g2", "g3", "g4", "g5", "g6"), class = "data.frame")
I tried both on scaled and non-scale values:
fviz_nbclust(scale(tab), kmeans, method = "wss")
fviz_nbclust(tab, kmeans, method = "wss")
and I get this error:
Error in FUNcluster(x, i, ...) :
more cluster centers than distinct data points.
how can I fix it?
Many thanks for your help !
I maybe found the solutions: it was sufficient to specify k.max = any number lower than nrow(tab)

Have multiple intervals in a staggered animation

Hi I was wondering if it was possible to have a tween that can have multiple intervals in a staggered in serval e.g.
opacity goes from 1.0 to 0.0 (% time: 0.45 to 0.5)
then
opacity goes from 0.0 to 1.0 (% time: 0.5 to 0.55)
using a similar tween
opacity1 = Tween<double>(
begin: 1.0,
end: 0.0,
).animate(
CurvedAnimation(
parent: controller,
curve: Interval(
0.45, 0.5,
curve: Curves.ease,
),
),
).NextTween<double>( ///Pseudo code
begin: 0.0,
end: 1.0,
).animate(
CurvedAnimation(
parent: controller,
curve: Interval(
0.5, 0.55,
curve: Curves.ease,
),
),
)
Ok in the end I use a TweenSquence the flutter docs uses the example below which is very helpful link to the docs is Flutter docs.
This example defines an animation that uses an easing curve to interpolate between 5.0 and 10.0 during the first 40% of the animation, remains at 10.0 for the next 20%, and then returns to 5.0 for the final 40%.
final Animation<double> animation = TweenSequence(
<TweenSequenceItem<double>>[
TweenSequenceItem<double>(
tween: Tween<double>(begin: 5.0, end: 10.0)
.chain(CurveTween(curve: Curves.ease)),
weight: 40.0,
),
TweenSequenceItem<double>(
tween: ConstantTween<double>(10.0),
weight: 20.0,
),
TweenSequenceItem<double>(
tween: Tween<double>(begin: 10.0, end: 5.0)
.chain(CurveTween(curve: Curves.ease)),
weight: 40.0,
),
],
).animate(myAnimationController);

Flutter Rotation X Y Imagen

I have a problem, in the animation, the image rotates first on the X axis and then on the Y axis, but the image is upside down before it rotates. How do I make the image not to be visualized this way?
_controller = (widget.controller ??
AnimationController(vsync: this, duration: widget.duration))
..addListener(() => setState(() {}))
..repeat();
_animation1 = Tween(begin: 0.0, end: 180.0).animate(CurvedAnimation(
parent: _controller,
curve: const Interval(0.0, 0.5, curve: Curves.easeIn)));
_animation2 = Tween(begin: 0.0, end: 180.0).animate(CurvedAnimation(
parent: _controller,
curve: const Interval(0.5, 1.0, curve: Curves.easeInOut)));
transform: Matrix4.identity()
..rotateX((0 - _animation1.value) * valorAngulo)
..rotateY((0 - _animation2.value) * valorAngulo),
This is my code

Draw Dots like Matrix Structure on iphone sdk

I want to Draw dots like a Matrix Structure in iphone sdk.
if i want generate dots columns and rows (like 2x2,3x3,4x4).
but i have no idea for this generation.
i want output like below image.
any help for example code or tutorial..!
A simple Solution would be:
- (void)drawRect:(CGRect)rect {
int n = 12; // row and column count
int padding = 5; // distance beetween dots
float radius = MIN((rect.size.width-(n+1)*padding)/(n*2), (rect.size.height-(n+1)*padding)/(n*2)); // radius depending on rect size
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]); // background color
CGContextFillRect(context, rect); // setting background color
CGContextSetFillColorWithColor(context, [[UIColor blackColor] CGColor]); // dot color
for (int y = 0; y<n; y++) {
for (int x = 0; x<n; x++) {
CGContextAddArc(context, padding+radius+(padding+radius*2)*x, padding+radius+(padding+radius*2)*y, radius, 0, M_PI*2, 0); // adding dot path
CGContextFillPath(context); // drawing dot path
}
}
}
You use this code ...
- (void)drawRect:(CGRect)rect
{
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(contextRef, 0, 0, 255, 0.1);
//CGContextSetRGBFillColor(contextRef, 0, 10, 200, 0.2);
CGContextSetRGBStrokeColor(contextRef, 0, 0, 255, 0.5);
// Draw a circle (filled)
//CGContextFillEllipseInRect(contextRef, CGRectMake(100, 100, 25, 25));
// Draw a circle (border only)
CGContextStrokeEllipseInRect(contextRef, CGRectMake(100, 100, 25, 25));
// Get the graphics context and clear it
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);
// Draw a green solid circle
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(20, 50, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(50, 50, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(80, 50, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(110, 50, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(140, 50, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(170, 50, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(20, 100, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(50, 100, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(80, 100, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(110, 100, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(140, 100, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(170, 100, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(20, 150, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(50, 150, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(80, 150, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(110, 150, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(140, 150, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(170, 150, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(20, 200, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(50, 200, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(80, 200, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(110, 200, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(140, 200, 8, 8));
CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
CGContextFillEllipseInRect(ctx, CGRectMake(170, 200, 8, 8));
}
Your Output shows like