public static int Compare(double x, double y) { if (x < y) { return(-1); } if (x > y) { return(1); } if (x == y) { return(x == 0 ? Double.Compare(1 / x, 1 / y) : 0); } if (IsNaN(x)) { if (IsNaN(y)) { return(0); } else { return(1); } } else { return(-1); } }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); // set canvas background color // canvas.DrawColor(bgColor); // set stroke width paint.StrokeWidth = ((float)(0.02083 * screenW)); //incrementing counter for rotation count = count + 0.5; //comparison to check 360 degrees rotation int retval = Double.Compare(count, 360.00); if (retval == 0) { if (!isAnimated) { // mark completion of animation isAnimated = true; //resetting counter on completion of a rotation count = 0; } else { //resetting counter on completion of a rotation count = 0; } } // draw cloud canvas.DrawPath(c.getCloud(X, Y, screenW, count), paint); if (!isStatic || !isAnimated) { // invalidate if not static or not animating Invalidate(); } }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); // set canvas background color canvas.DrawColor(bgColor); count = count + 0.5; paintCloud.StrokeWidth = ((float)(0.02083 * screenW)); paintSnow.StrokeWidth = ((float)(0.01 * screenW)); int retval = Double.Compare(count, 360.00); if (retval == 0) { if (!isAnimated) { // mark completion of animation isAnimated = true; //resetting counter on completion of a rotation count = 0; } else { //resetting counter on completion of a rotation count = 0; } } PointF P1c1 = cloud.getP1c1(X, Y, screenW, count); PointF P1c2 = cloud.getP1c2(X, Y, screenW, count); PointF P2c1 = cloud.getP2c1(X, Y, screenW, count); PointF P2c2 = cloud.getP2c2(X, Y, screenW, count); float P1Y = ((float)((int)(0.1041667 * screenW) * Math.Sin(Math.ToRadians(80 + (0.111 * count))) + Y)); float P2Y = ((float)(((int)(0.1041667 * screenW) + ((0.00023125 * screenW) * count)) * Math.Sin(Math.ToRadians(120 + (0.222 * count))) + Y)); if (x1 == 0) { x1 = (int)P1c2.X + 10; } if (y1 == 0) { float value = (int)P1c2.Y - ((P1c1.Y + P1Y) / 2); y1 = (int)(P1c2.Y - value / 2); } if (x2 == 0) { x2 = (int)P2c2.X + 10; } if (y2 == 0) { float value = (int)P2c2.Y - ((P2c1.Y + P2Y) / 2); y2 = (int)(P2c2.Y - value / 2); } if (!pointsStored) { // Store path coordinates for snow fall 1 cubicPath11 = new Path(); int height = screenH - y1; cubicPath11.MoveTo(x1, y1); cubicPath11.CubicTo(x1 - screenW * 0.06f, y1 + height * 0.3f, x1 - screenW * 0.12f, y1 + height * 0.7f, x1 - screenW * 0.18f, y1 + height * 1.1f); pathPoints11 = getPoints(cubicPath11); // Store path coordinates for snow fall 2 cubicPath12 = new Path(); int x = x1 - 5; cubicPath12.MoveTo(x, y1); cubicPath12.CubicTo(x + screenW * 0.06f, y1 + height * 0.3f, x + screenW * 0.1f, y1 + height * 0.7f, x - screenW * 0.03f, y1 + height * 1.1f); pathPoints12 = getPoints(cubicPath12); // Store path coordinates for snow fall 3 cubicPath21 = new Path(); cubicPath21.MoveTo(x2, y2); cubicPath21.CubicTo(x2 + screenW * 0.06f, y2 + height * 0.3f, x2 + screenW * 0.12f, y2 + height * 0.7f, x2 + screenW * 0.18f, y2 + height * 1.1f); pathPoints21 = getPoints(cubicPath21); // Store path coordinates for snow fall 4 cubicPath22 = new Path(); int xx = x2 + 5; cubicPath22.MoveTo(xx, y2); cubicPath22.CubicTo(xx - screenW * 0.06f, y2 + height * 0.3f, xx - screenW * 0.1f, y2 + height * 0.6f, xx + screenW * 0.03f, y2 + height * 1.1f); pathPoints22 = getPoints(cubicPath22); pointsStored = true; } if (isAnimated && isStatic) { //Initial static view int x = 55; pathCircle2 = new Path(); pathCircle2.AddCircle(pathPoints12[x].getX(), pathPoints12[x].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle12 = getPoints(pathCircle2); //2nd drop path21 = new Path(); path22 = new Path(); path23 = new Path(); int a = (25 + x / 5) >= 100 ? 25 + x / 5 - 100 : 25 + x / 5; int b = (8 + x / 5) >= 100 ? 8 + x / 5 - 100 : 8 + x / 5; int c = (40 + x / 5) >= 100 ? 40 + x / 5 - 100 : 40 + x / 5; path21.MoveTo(pointsCircle12[a].getX(), pointsCircle12[a].getY()); path22.MoveTo(pointsCircle12[b].getX(), pointsCircle12[b].getY()); path23.MoveTo(pointsCircle12[c].getX(), pointsCircle12[c].getY()); a = (75 + x / 5) >= 100 ? 75 + x / 5 - 100 : 75 + x / 5; b = (59 + x / 5) >= 100 ? 59 + x / 5 - 100 : 59 + x / 5; c = (90 + x / 5) >= 100 ? 90 + x / 5 - 100 : 90 + x / 5; path21.LineTo(pointsCircle12[a].getX(), (pointsCircle12[a].getY())); path22.LineTo(pointsCircle12[b].getX(), (pointsCircle12[b].getY())); path23.LineTo(pointsCircle12[c].getX(), (pointsCircle12[c].getY())); canvas.DrawPath(path21, paintSnow); canvas.DrawPath(path22, paintSnow); canvas.DrawPath(path23, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); int y = 35; pathCircle2 = new Path(); pathCircle2.AddCircle(pathPoints22[y].getX(), pathPoints22[y].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle22 = getPoints(pathCircle2); //2nd drop path21 = new Path(); path22 = new Path(); path23 = new Path(); a = (25 + y / 5) >= 100 ? 25 + y / 5 - 100 : 25 + y / 5; b = (8 + y / 5) >= 100 ? 8 + y / 5 - 100 : 8 + y / 5; c = (40 + y / 5) >= 100 ? 40 + y / 5 - 100 : 40 + y / 5; path21.MoveTo(pointsCircle22[a].getX(), pointsCircle22[a].getY()); path22.MoveTo(pointsCircle22[b].getX(), pointsCircle22[b].getY()); path23.MoveTo(pointsCircle22[c].getX(), pointsCircle22[c].getY()); a = (75 + y / 5) >= 100 ? 75 + y / 5 - 100 : 75 + y / 5; b = (59 + y / 5) >= 100 ? 59 + y / 5 - 100 : 59 + y / 5; c = (90 + y / 5) >= 100 ? 90 + y / 5 - 100 : 90 + y / 5; path21.LineTo(pointsCircle22[a].getX(), (pointsCircle22[a].getY())); path22.LineTo(pointsCircle22[b].getX(), (pointsCircle22[b].getY())); path23.LineTo(pointsCircle22[c].getX(), (pointsCircle22[c].getY())); canvas.DrawPath(path21, paintSnow); canvas.DrawPath(path22, paintSnow); canvas.DrawPath(path23, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); } else // Animating view { if (drop11) { pathCircle1 = new Path(); pathCircle1.AddCircle(pathPoints11[m].getX(), pathPoints11[m].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle11 = getPoints(pathCircle1); //1st drop path11 = new Path(); path12 = new Path(); path13 = new Path(); int a = (25 + m / 5) >= 100 ? 25 + m / 5 - 100 : 25 + m / 5; int b = (8 + m / 5) >= 100 ? 8 + m / 5 - 100 : 8 + m / 5; int c = (40 + m / 5) >= 100 ? 40 + m / 5 - 100 : 40 + m / 5; path11.MoveTo(pointsCircle11[a].getX(), pointsCircle11[a].getY()); path12.MoveTo(pointsCircle11[b].getX(), pointsCircle11[b].getY()); path13.MoveTo(pointsCircle11[c].getX(), pointsCircle11[c].getY()); a = (75 + m / 5) >= 100 ? 75 + m / 5 - 100 : 75 + m / 5; b = (59 + m / 5) >= 100 ? 59 + m / 5 - 100 : 59 + m / 5; c = (90 + m / 5) >= 100 ? 90 + m / 5 - 100 : 90 + m / 5; path11.LineTo(pointsCircle11[a].getX(), (pointsCircle11[a].getY())); path12.LineTo(pointsCircle11[b].getX(), (pointsCircle11[b].getY())); path13.LineTo(pointsCircle11[c].getX(), (pointsCircle11[c].getY())); canvas.DrawPath(path11, paintSnow); canvas.DrawPath(path12, paintSnow); canvas.DrawPath(path13, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); m = m + 1; if (m > 75) { pathCircle2 = new Path(); pathCircle2.AddCircle(pathPoints12[n].getX(), pathPoints12[n].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle12 = getPoints(pathCircle2); //2nd drop path21 = new Path(); path22 = new Path(); path23 = new Path(); a = (25 + n / 5) >= 100 ? 25 + n / 5 - 100 : 25 + n / 5; b = (8 + n / 5) >= 100 ? 8 + n / 5 - 100 : 8 + n / 5; c = (40 + n / 5) >= 100 ? 40 + n / 5 - 100 : 40 + n / 5; path21.MoveTo(pointsCircle12[a].getX(), pointsCircle12[a].getY()); path22.MoveTo(pointsCircle12[b].getX(), pointsCircle12[b].getY()); path23.MoveTo(pointsCircle12[c].getX(), pointsCircle12[c].getY()); a = (75 + n / 5) >= 100 ? 75 + n / 5 - 100 : 75 + n / 5; b = (59 + n / 5) >= 100 ? 59 + n / 5 - 100 : 59 + n / 5; c = (90 + n / 5) >= 100 ? 90 + n / 5 - 100 : 90 + n / 5; path21.LineTo(pointsCircle12[a].getX(), (pointsCircle12[a].getY())); path22.LineTo(pointsCircle12[b].getX(), (pointsCircle12[b].getY())); path23.LineTo(pointsCircle12[c].getX(), (pointsCircle12[c].getY())); canvas.DrawPath(path21, paintSnow); canvas.DrawPath(path22, paintSnow); canvas.DrawPath(path23, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); n = n + 1; } if (m == 100) { m = 0; path11.Reset(); path11.MoveTo(0, 0); path12.Reset(); path12.MoveTo(0, 0); path13.Reset(); path13.MoveTo(0, 0); x1 = 0; y1 = 0; x2 = 0; y2 = 0; drop12 = true; drop11 = false; } } if (drop12) { pathCircle2 = new Path(); pathCircle2.AddCircle(pathPoints12[n].getX(), pathPoints12[n].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle12 = getPoints(pathCircle2); //2nd drop path21 = new Path(); path22 = new Path(); path23 = new Path(); int a = (25 + n / 5) >= 100 ? 25 + n / 5 - 100 : 25 + n / 5; int b = (8 + n / 5) >= 100 ? 8 + n / 5 - 100 : 8 + n / 5; int c = (40 + n / 5) >= 100 ? 40 + n / 5 - 100 : 40 + n / 5; path21.MoveTo(pointsCircle12[a].getX(), pointsCircle12[a].getY()); path22.MoveTo(pointsCircle12[b].getX(), pointsCircle12[b].getY()); path23.MoveTo(pointsCircle12[c].getX(), pointsCircle12[c].getY()); a = (75 + n / 5) >= 100 ? 75 + n / 5 - 100 : 75 + n / 5; b = (59 + n / 5) >= 100 ? 59 + n / 5 - 100 : 59 + n / 5; c = (90 + n / 5) >= 100 ? 90 + n / 5 - 100 : 90 + n / 5; path21.LineTo(pointsCircle12[a].getX(), (pointsCircle12[a].getY())); path22.LineTo(pointsCircle12[b].getX(), (pointsCircle12[b].getY())); path23.LineTo(pointsCircle12[c].getX(), (pointsCircle12[c].getY())); canvas.DrawPath(path21, paintSnow); canvas.DrawPath(path22, paintSnow); canvas.DrawPath(path23, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); n = n + 1; if (n == 100) { m = 0; n = 0; path21.Reset(); path21.MoveTo(0, 0); path22.Reset(); path22.MoveTo(0, 0); path23.Reset(); path23.MoveTo(0, 0); x1 = 0; y1 = 0; drop21 = true; drop11 = false; drop12 = false; } } if (drop21) { pathCircle1 = new Path(); pathCircle1.AddCircle(pathPoints21[m].getX(), pathPoints21[m].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle21 = getPoints(pathCircle1); //1st drop path11 = new Path(); path12 = new Path(); path13 = new Path(); int a = (25 + m / 5) >= 100 ? 25 + m / 5 - 100 : 25 + m / 5; int b = (8 + m / 5) >= 100 ? 8 + m / 5 - 100 : 8 + m / 5; int c = (40 + m / 5) >= 100 ? 40 + m / 5 - 100 : 40 + m / 5; path11.MoveTo(pointsCircle21[a].getX(), pointsCircle21[a].getY()); path12.MoveTo(pointsCircle21[b].getX(), pointsCircle21[b].getY()); path13.MoveTo(pointsCircle21[c].getX(), pointsCircle21[c].getY()); a = (75 + m / 5) >= 100 ? 75 + m / 5 - 100 : 75 + m / 5; b = (59 + m / 5) >= 100 ? 59 + m / 5 - 100 : 59 + m / 5; c = (90 + m / 5) >= 100 ? 90 + m / 5 - 100 : 90 + m / 5; path11.LineTo(pointsCircle21[a].getX(), (pointsCircle21[a].getY())); path12.LineTo(pointsCircle21[b].getX(), (pointsCircle21[b].getY())); path13.LineTo(pointsCircle21[c].getX(), (pointsCircle21[c].getY())); canvas.DrawPath(path11, paintSnow); canvas.DrawPath(path12, paintSnow); canvas.DrawPath(path13, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); m = m + 1; if (m > 75) { pathCircle2 = new Path(); pathCircle2.AddCircle(pathPoints22[n].getX(), pathPoints22[n].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle22 = getPoints(pathCircle2); //2nd drop path21 = new Path(); path22 = new Path(); path23 = new Path(); a = (25 + n / 5) >= 100 ? 25 + n / 5 - 100 : 25 + n / 5; b = (8 + n / 5) >= 100 ? 8 + n / 5 - 100 : 8 + n / 5; c = (40 + n / 5) >= 100 ? 40 + n / 5 - 100 : 40 + n / 5; path21.MoveTo(pointsCircle22[a].getX(), pointsCircle22[a].getY()); path22.MoveTo(pointsCircle22[b].getX(), pointsCircle22[b].getY()); path23.MoveTo(pointsCircle22[c].getX(), pointsCircle22[c].getY()); a = (75 + n / 5) >= 100 ? 75 + n / 5 - 100 : 75 + n / 5; b = (59 + n / 5) >= 100 ? 59 + n / 5 - 100 : 59 + n / 5; c = (90 + n / 5) >= 100 ? 90 + n / 5 - 100 : 90 + n / 5; path21.LineTo(pointsCircle22[a].getX(), (pointsCircle22[a].getY())); path22.LineTo(pointsCircle22[b].getX(), (pointsCircle22[b].getY())); path23.LineTo(pointsCircle22[c].getX(), (pointsCircle22[c].getY())); canvas.DrawPath(path21, paintSnow); canvas.DrawPath(path22, paintSnow); canvas.DrawPath(path23, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); n = n + 1; } if (m == 100) { m = 0; path11.Reset(); path11.MoveTo(0, 0); path12.Reset(); path12.MoveTo(0, 0); path13.Reset(); path13.MoveTo(0, 0); x1 = 0; y1 = 0; drop22 = true; drop21 = false; } } if (drop22) { pathCircle2 = new Path(); pathCircle2.AddCircle(pathPoints22[n].getX(), pathPoints22[n].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle22 = getPoints(pathCircle2); //2nd drop path21 = new Path(); path22 = new Path(); path23 = new Path(); int a = (25 + n / 5) >= 100 ? 25 + n / 5 - 100 : 25 + n / 5; int b = (8 + n / 5) >= 100 ? 8 + n / 5 - 100 : 8 + n / 5; int c = (40 + n / 5) >= 100 ? 40 + n / 5 - 100 : 40 + n / 5; path21.MoveTo(pointsCircle22[a].getX(), pointsCircle22[a].getY()); path22.MoveTo(pointsCircle22[b].getX(), pointsCircle22[b].getY()); path23.MoveTo(pointsCircle22[c].getX(), pointsCircle22[c].getY()); a = (75 + n / 5) >= 100 ? 75 + n / 5 - 100 : 75 + n / 5; b = (59 + n / 5) >= 100 ? 59 + n / 5 - 100 : 59 + n / 5; c = (90 + n / 5) >= 100 ? 90 + n / 5 - 100 : 90 + n / 5; path21.LineTo(pointsCircle22[a].getX(), (pointsCircle22[a].getY())); path22.LineTo(pointsCircle22[b].getX(), (pointsCircle22[b].getY())); path23.LineTo(pointsCircle22[c].getX(), (pointsCircle22[c].getY())); canvas.DrawPath(path21, paintSnow); canvas.DrawPath(path22, paintSnow); canvas.DrawPath(path23, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); n = n + 1; if (n == 100) { m = 0; n = 0; path21.Reset(); path21.MoveTo(0, 0); path22.Reset(); path22.MoveTo(0, 0); path23.Reset(); path23.MoveTo(0, 0); x1 = 0; y1 = 0; drop11 = true; drop12 = false; drop21 = false; drop22 = false; } } } if (!isStatic || !isAnimated) { Invalidate(); } }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); // set canvas background color // canvas.DrawColor(bgColor); // set stroke width paint.StrokeWidth = ((float)(0.02083 * screenW)); // initializing paths path = new Path(); path1 = new Path(); // positioning Sun with respect to cloud PointF P5c1 = cloud.getP5c1(X, Y, screenW, count); if (XSun == 0) { // center point for Sun XSun = P5c1.X; YSun = P5c1.Y + (int)(0.042 * screenW); } //incrementing counter for rotation count = count + 0.5; //comparison to check 360 degrees rotation int retval = Double.Compare(count, 360.00); if (retval == 0) { if (!isAnimated) { // mark completion of animation isAnimated = true; //resetting counter on completion of a rotation count = 0; } else { //resetting counter on completion of a rotation count = 0; } } // drawing center circle path.AddCircle(XSun, YSun, (int)(0.083 * screenW), Path.Direction.Cw); // drawing arms of sun for (int i = 0; i < 360; i += 45) { path1.MoveTo(XSun, YSun); float x1 = (float)((int)(0.1146 * screenW) * Math.Cos(Math.ToRadians(i + count / 4)) + XSun); //arm pointX at radius 50 with incrementing angle from center of sun float y1 = (float)((int)(0.1146 * screenW) * Math.Sin(Math.ToRadians(i + count / 4)) + YSun); //arm pointY at radius 50 with incrementing angle from center of sun float X2 = (float)((int)(0.1563 * screenW) * Math.Cos(Math.ToRadians(i + count / 4)) + XSun); //arm pointX at radius 65 with incrementing angle from center of sun float Y2 = (float)((int)(0.1563 * screenW) * Math.Sin(Math.ToRadians(i + count / 4)) + YSun); //arm pointY at radius 65 with incrementing angle from center of sun path1.MoveTo(x1, y1); // draw arms of sun path1.LineTo(X2, Y2); } // drawing sun canvas.DrawPath(path, paint); canvas.DrawPath(path1, paint); // drawing cloud with fill paint.Color = (bgColor); paint.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paint); // drawing cloud with stroke paint.Color = (strokeColor); paint.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paint); if (!isStatic || !isAnimated) { // invalidate if not static or not animating Invalidate(); } }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); // canvas.DrawColor(bgColor); paintCloud.StrokeWidth = ((float)(0.02083 * screenW)); paintFog.StrokeWidth = ((float)(0.02083 * screenW)); path1 = new Path(); path2 = new Path(); count = count + 0.5; int retval = Double.Compare(count, 360.00); if (retval == 0) { count = 0; } canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); PointF P1c2 = cloud.getP1c2(X, Y, screenW, count); path1 = new Path(); path2 = new Path(); if (line1Y == 0) { line1Y = P1c2.Y + (float)(0.1042 * screenW); //Calculating Y coordinate for foglines. line2Y = P1c2.Y + (float)(0.15625 * screenW); lineStartX = (float)(X - X * 50.0 / 100.0); //Calculating X coordinate for foglines. lineEndX = (float)(X + X * 50.0 / 100); } float temp = (lineEndX - lineStartX) * (float)95.0 / (float)100; //Calculating fogline length path1.MoveTo(lineStartX, line1Y); path1.LineTo(lineStartX + temp, line1Y); path2.MoveTo(lineEndX, line2Y); path2.LineTo(lineEndX - temp, line2Y); //Code to move foglines from one point to another if (moving && (lineStartX + temp + ctr) <= lineEndX) { path1.Reset(); path1.MoveTo(lineStartX + ctr + i, line1Y); path1.LineTo(lineStartX + ctr + temp + i, line1Y); path2.Reset(); path2.MoveTo(lineEndX - ctr + i + i, line2Y); path2.LineTo(lineEndX - ctr - temp + i - i, line2Y); ctr = ctr + (float)0.5; if ((lineStartX + temp + ctr) > lineEndX) { expanding = true; moving = false; } } //Code to expand foglines if (expanding) { if (i <= 5f) { i = i + 0.1f; path1.Reset(); path1.MoveTo(lineStartX + ctr + temp + i, line1Y); path1.LineTo(lineStartX + ctr - i, line1Y); path2.Reset(); path2.MoveTo(lineEndX - ctr - temp + i, line2Y); path2.LineTo(lineEndX - ctr - i, line2Y); } else { //Moving the fogline to the other end after expanding path1.Reset(); path1.MoveTo(lineStartX + ctr + temp + i, line1Y); path1.LineTo(lineStartX + ctr - i, line1Y); path2.Reset(); path2.MoveTo(lineEndX - ctr - temp + i, line2Y); path2.LineTo(lineEndX - ctr - i, line2Y); ctr = ctr - 0.2f; if (lineStartX + ctr <= lineStartX) { expanding = false; compress = true; ctr = 0.0f; } } } //Compressing the fogline to normal length if (compress) { if (i > 0.0f) { i = i - 0.1f; path1.Reset(); path1.MoveTo(lineStartX + ctr - i, line1Y); path1.LineTo(lineStartX + ctr + temp + i, line1Y); path2.Reset(); path2.MoveTo(lineEndX - ctr - i, line2Y); path2.LineTo(lineEndX - ctr - temp + i, line2Y); } else { compress = false; moving = true; if (isStatic) { isAnimated = false; } } } canvas.DrawPath(path1, paintFog); canvas.DrawPath(path2, paintFog); if (isAnimated) { Invalidate(); } }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); // set canvas background color canvas.DrawColor(bgColor); paintCloud.StrokeWidth = ((float)(0.02083 * screenW)); paintMoon.StrokeWidth = ((float)(0.02083 * screenW)); count = count + 0.5; int retval = Double.Compare(count, 360.00); if (retval == 0) { if (!isAnimated) { // mark completion of animation isAnimated = true; //resetting counter on completion of a rotation count = 0; } else { //resetting counter on completion of a rotation count = 0; } } // Moon shape pathMoon = new Path(); RectF rectF1 = new RectF(); PointF P5c1 = cloud.getP5c1(X, Y, screenW, count); if (X2 == 0) { X2 = P5c1.X; Y2 = P5c1.Y + (int)(0.042 * screenW); radius = (int)(0.1042 * screenW); } if (!clockwise) { //Anticlockwise rotation // First arc of the Moon. rectF1.Set(X2 - radius, Y2 - radius, X2 + radius, Y2 + radius); pathMoon.AddArc(rectF1, 65 - (m / 2), 275); pathPoints = getPoints(pathMoon); a = pathPoints[999].getX(); b = pathPoints[999].getY(); c = pathPoints[0].getX(); d = pathPoints[0].getY(); PointF p1 = cubic2Points(a, b, c, d, true); PointF p2 = cubic2Points(a, b, c, d, false); // Second arc of the Moon in opposite face. pathMoon.MoveTo(a, b); pathMoon.CubicTo(p1.X, p1.Y, p2.X, p2.Y, c, d); canvas.DrawPath(pathMoon, paintMoon); m = m + 0.5f; if (m == 100) { m = 0; clockwise = !clockwise; } } else { //Clockwise rotation // First arc of the Moon. rectF1.Set(X2 - radius, Y2 - radius, X2 + radius, Y2 + radius); pathMoon.AddArc(rectF1, 15 + (m / 2), 275); pathPoints = getPoints(pathMoon); a = pathPoints[999].getX(); b = pathPoints[999].getY(); c = pathPoints[0].getX(); d = pathPoints[0].getY(); PointF p1 = cubic2Points(a, b, c, d, true); PointF p2 = cubic2Points(a, b, c, d, false); // Second arc of the Moon in opposite face. pathMoon.MoveTo(a, b); pathMoon.CubicTo(p1.X, p1.Y, p2.X, p2.Y, c, d); canvas.DrawPath(pathMoon, paintMoon); m = m + 0.5f; if (m == 100) { m = 0; clockwise = !clockwise; } } // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); if (!isStatic || !isAnimated) { Invalidate(); } }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); // set canvas background color canvas.DrawColor(bgColor); paintCloud.StrokeWidth = ((float)(0.02083 * screenW)); paintRain.StrokeWidth = ((float)(0.015 * screenW)); pathRain = new Path(); // pathCloud for drop count = count + 0.5; //comparison to check 360 degrees rotation int retval = Double.Compare(count, 360.00); if (retval == 0) { if (!isAnimated) { // mark completion of animation isAnimated = true; //resetting counter on completion of a rotation count = 0; } else { //resetting counter on completion of a rotation count = 0; } } PointF P1c2 = cloud.getP1c2(X, Y, screenW, count); PointF P1c1 = cloud.getP1c2(X, Y, screenW, count); float P1Y = ((float)((int)(0.1041667 * screenW) * Math.Sin(Math.ToRadians(80 + (0.111 * count))) + Y)); PointF P2c2 = cloud.getP2c2(X, Y, screenW, count); PointF P2c1 = cloud.getP2c2(X, Y, screenW, count); float P2Y = ((float)(((int)(0.1041667 * screenW) + ((0.00023125 * screenW) * count)) * Math.Sin(Math.ToRadians(120 + (0.222 * count))) + Y)); if (isAnimated && isStatic) { //Initial static view pathRain = new Path(); // 1st drop if (x1 == 0) { x1 = (int)P1c2.X; } if (y1 == 0) { float value = (int)P1c2.Y - ((P1c1.Y + P1Y) / 2); y1 = (int)(P1c2.Y - value / 2); } m = 95; // Shape for rain drop pathRain.MoveTo(x1, y1); pathRain.AddArc(new RectF(x1 - 5, (y1 - 5) + m, x1 + 5, y1 + 5 + m), 180, -180); pathRain.LineTo(x1, (y1 - 10) + m); pathRain.Close(); // 2nd drop if (x2 == 0) { x2 = (int)P2c2.X; } if (y2 == 0) { float value = (int)P2c2.Y - ((P2c1.Y + P2Y) / 2); y2 = (int)(P2c2.Y - value / 2); } pathRain.MoveTo(x2, y2); pathRain.AddArc(new RectF(x2 - 5, (y2 - 5) + m, x2 + 5, y2 + 5 + m), 180, -180); pathRain.LineTo(x2, (y2 - 10) + m); pathRain.Close(); // 3rd drop if (x3 == 0) { x3 = (x1 + x2) / 2; } if (y3 == 0) { y3 = (y1 + y2) / 2; } pathRain.MoveTo(x3, y3); pathRain.AddArc(new RectF(x3 - 5, (y3 - 5) + m / 2, x3 + 5, y3 + 5 + m / 2), 180, -180); pathRain.LineTo(x3, (y3 - 10) + m / 2); pathRain.Close(); } else // Animating view { if (drop1) // Drop 1 of the rain { pathRain = new Path(); if (x1 == 0) { x1 = (int)P1c2.X; } if (y1 == 0) { float value = (int)P1c2.Y - ((P1c1.Y + P1Y) / 2); y1 = (int)(P1c2.Y - value / 2); } // Shape for rain drop pathRain.MoveTo(x1, y1); pathRain.AddArc(new RectF(x1 - 5, (y1 - 5) + m, x1 + 5, y1 + 5 + m), 180, -180); pathRain.LineTo(x1, (y1 - 10) + m); pathRain.Close(); if (m == 100) { m = 0; pathRain.Reset(); pathRain.MoveTo(0, 0); drop2 = true; drop1 = false; } } if (drop2) // Drop 2 of the rain { pathRain = new Path(); if (x2 == 0) { x2 = (int)P2c2.X; } if (y2 == 0) { float value = (int)P2c2.Y - ((P2c1.Y + P2Y) / 2); y2 = (int)(P2c2.Y - value / 2); } pathRain.MoveTo(x2, y2); pathRain.AddArc(new RectF(x2 - 5, (y2 - 5) + m, x2 + 5, y2 + 5 + m), 180, -180); pathRain.LineTo(x2, (y2 - 10) + m); pathRain.Close(); if (m == 100) { m = 0; pathRain.Reset(); pathRain.MoveTo(0, 0); drop2 = false; drop3 = true; } } if (drop3) { // Drop 3 of the rain pathRain = new Path(); if (x3 == 0) { x3 = (x1 + x2) / 2; } if (y3 == 0) { y3 = (y1 + y2) / 2; } pathRain.MoveTo(x3, y3); pathRain.AddArc(new RectF(x3 - 5, (y3 - 5) + m, x3 + 5, y3 + 5 + m), 180, -180); pathRain.LineTo(x3, (y3 - 10) + m); pathRain.Close(); if (m == 100) { m = 0; pathRain.Reset(); pathRain.MoveTo(0, 0); // animate = false; drop3 = false; drop1 = true; } } // First fill the shape with paint paintRain.SetStyle(Paint.Style.Fill); canvas.DrawPath(pathRain, paintRain); // Then, draw the same pathCloud with paint stroke paintRain.SetStyle(Paint.Style.Stroke); canvas.DrawPath(pathRain, paintRain); m = m + 2.5f; // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); if (!isStatic || !isAnimated) { Invalidate(); } } }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); canvas.DrawColor(bgColor); paintCloud.StrokeWidth = ((float)(0.02083 * screenW)); paintThunder.StrokeWidth = ((float)(0.02083 * screenW)); //incrementing counter for rotation count = count + 0.5; //comparison to check 360 degrees rotation int retval = Double.Compare(count, 360.00); if (retval == 0) { //resetting counter on completion of a rotation count = 0; } PointF P2c1 = cloud.getP2c1(X, Y, screenW, count); //Setting up the height of thunder from the cloud if (thHeight == 0) { thHeight = P2c1.Y; } float startHeight = thHeight - (thHeight * 0.1f); //Setting up X coordinates of thunder float path2StartX = X + (X * 0.04f); //Calculating coordinates of thunder thPath.MoveTo(path2StartX, startHeight); thPath.LineTo(X - (X * 0.1f), startHeight + (startHeight * 0.2f)); //1 thPath.LineTo(X + (X * 0.03f), startHeight + (startHeight * 0.15f)); thPath.LineTo(X - (X * 0.08f), startHeight + (startHeight * 0.3f)); leftPoints = getPoints(thPath); if (ctr <= 98) { if (check == false) { thFillPath.MoveTo(leftPoints[ctr].getX(), leftPoints[ctr].getY()); thFillPath.LineTo(leftPoints[ctr + 1].getX(), leftPoints[ctr + 1].getY()); } else { //Once filled, erasing the fill from top to bottom thFillPath.Reset(); thFillPath.MoveTo(leftPoints[ctr].getX(), leftPoints[ctr].getY()); for (int i = ctr + 1; i < leftPoints.Length - 1; i++) { thFillPath.LineTo(leftPoints[i].getX(), leftPoints[i].getY()); } } ctr = ctr + 1; } else { if (isStatic) { if (ctr2 == 2) { isAnimated = false; ctr2 = 0; } ctr2++; } ctr = 0; if (check == false) { check = true; } else { check = false; } } if (!isAnimated) { thFillPath.Reset(); thFillPath.MoveTo(leftPoints[0].getX(), leftPoints[0].getY()); for (int i = ctr + 1; i < leftPoints.Length - 1; i++) { thFillPath.LineTo(leftPoints[i].getX(), leftPoints[i].getY()); } } canvas.DrawPath(thFillPath, paintThunder); paintCloud.SetStyle(Paint.Style.Fill); paintCloud.Color = (Colors.Dark); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); paintCloud.SetStyle(Paint.Style.Stroke); paintCloud.Color = (Color.White); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); if (isAnimated) { Invalidate(); } }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); // set canvas background color canvas.DrawColor(bgColor); path1 = new Path(); // pathCloud for drop 1 path2 = new Path(); // pathCloud for drop 2 path3 = new Path(); // pathCloud for drop 3 count = count + 0.5; paintCloud.StrokeWidth = ((float)(0.02083 * screenW)); paintRain.StrokeWidth = ((float)(0.015 * screenW)); int retval = Double.Compare(count, 360.00); if (retval == 0) { if (!isAnimated) { // mark completion of animation isAnimated = true; //resetting counter on completion of a rotation count = 0; } else { //resetting counter on completion of a rotation count = 0; } } PointF P1c2 = cloud.getP1c2(X, Y, screenW, count); PointF P2c2 = cloud.getP2c2(X, Y, screenW, count); PointF P1c1 = cloud.getP1c1(X, Y, screenW, count); float P1Y = ((float)((int)(0.1041667 * screenW) * Math.Sin(Math.ToRadians(80 + (0.111 * count))) + Y)); // Store starting x, y coordinates of rain drops if (!pointsStored) { x1 = (int)P1c2.X; x2 = (int)P2c2.X; x3 = (x1 + x2) / 2; float value = (int)P1c2.Y - ((P1c1.Y + P1Y) / 2); y1 = y2 = y3 = (int)(P1c2.Y - value / 2) - 20; pointsStored = true; } if (isAnimated && isStatic) { //Initial static view int m = 95; path1.MoveTo(x1, y1 + (m - 24)); path1.LineTo(x1, y1 + m + (float)(Y * 0.1)); canvas.DrawPath(path1, paintRain); path2.MoveTo(x2, y2 + (m - 24)); path2.LineTo(x2, y2 + m + (float)(Y * 0.1)); canvas.DrawPath(path2, paintRain); path3.MoveTo(x3, y3 + ((m - 50) - 24)); path3.LineTo(x3, y3 + (m - 50) + (float)(Y * 0.1)); canvas.DrawPath(path3, paintRain); } else { // Animating view if (i <= 2 * 49) { if (i < 2 * 25) { //drop11 logic if (m1 < 24) { path1.MoveTo(x1, y1); } else { count1 = count1 + 4; path1.MoveTo(x1, y1 + count1); } path1.LineTo(x1, y1 + m1 + (float)(Y * 0.1)); canvas.DrawPath(path1, paintRain); m1 = m1 + 4; if (m1 == 100) { m1 = 0; count1 = 0; } //drop21 logic if (i > 2 * 10) { if (m2 < 24) { path2.MoveTo(x2, y2); } else { count2 = count2 + 4; path2.MoveTo(x2, y2 + count2); } path2.LineTo(x2, y2 + m2 + (float)(Y * 0.1)); canvas.DrawPath(path2, paintRain); m2 = m2 + 4; if (m2 == 100) { m2 = 0; count2 = 0; } } } if (i >= 2 * 25 && i <= 2 * 49) { // drop 3 if (m3 < 24) { path3.MoveTo(x3, y3); } else { count3 = count3 + 4; path3.MoveTo(x3, y3 + count3); } path3.LineTo(x3, y3 + m3 + (float)(Y * 0.1)); canvas.DrawPath(path3, paintRain); m3 = m3 + 4; if (m3 == 100) { m3 = 0; count3 = 0; } // drop21 if (i < 2 * 36) { if (m2 < 24) { path2.MoveTo(x2, y2); } else { count2 = count2 + 4; path2.MoveTo(x2, y2 + count2); } path2.LineTo(x2, y2 + m2 + (float)(Y * 0.1)); canvas.DrawPath(path2, paintRain); m2 = m2 + 4; if (m2 == 100) { m2 = 0; count2 = 0; } } } } i += 2; if (i == 2 * 50) { i = 0; } } // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); if (!isStatic || !isAnimated) { Invalidate(); } }