void draw_bird_head(SKCanvas canvas, SKColor pc, SKColor dc) { paint.Style = SKPaintStyle.StrokeAndFill; paint.Color = SKColors.White; canvas.DrawCircle(head_x, head_y, head_radius, paint); if (RandomUtility.CreateRandom() < arc_chance) { paint.Style = SKPaintStyle.Fill; paint.Color = pc; // arc(head_x, head_y, head_size, head_size, random(.7, 1)*PI, 1.8*PI, PIE); double startAngle = RandomUtility.CreateRandom(0.7, 1) * Math.PI; double sweepAngle = 1.8 * Math.PI; canvas.DrawArc(new SKRect(head_x, head_y, head_x + head_radius, head_y + head_radius), (float)startAngle, (float)sweepAngle, true, paint); } paint.Color = dc; if (RandomUtility.CreateRandom() < head_fill_chance) { paint.Style = SKPaintStyle.StrokeAndFill; } else { paint.Style = SKPaintStyle.Stroke; } canvas.DrawCircle(head_x, head_y, head_radius, paint); }
void draw_bird_tail(SKCanvas canvas, SKPoint body_one, SKColor pc, SKColor dc) { if (RandomUtility.CreateRandom() < tail_chance) { //stroke(*dc) //fill( *pc ) int var_width = RandomUtility.CreateRandom(15, 30); int var_x = RandomUtility.CreateRandom(-25, -15); int var_y = RandomUtility.CreateRandom(-50, -30); if (RandomUtility.CreateRandom() < 0.3) { var_y *= -1; } //beginShape() var path = new SKPath { FillType = SKPathFillType.EvenOdd }; path.MoveTo(body_one.X, body_one.Y); path.LineTo(body_one.X + var_width, body_one.Y); path.LineTo(body_one.X + var_width + var_x, body_one.Y + var_y); path.LineTo(body_one.X + var_x, body_one.Y + var_y); path.Close(); SkiaSharpUtility.PathStroke(canvas, paint, dc, path); SkiaSharpUtility.PathFill(canvas, paint, pc, path); //endShape(CLOSE) } }
List <SKPoint> get_16_points(float x, float y, float w, float h) { float squeeze = RandomUtility.CreateRandom(-w * 0.2f, w * 0.2f); List <SKPoint> points = new List <SKPoint>(); points.Add(new SKPoint(x, y)); points.Add(new SKPoint(x + w * 0.25f, y)); points.Add(new SKPoint(x + w * 0.5f, y - h * 0.05f)); points.Add(new SKPoint(x + w * 0.75f, y)); points.Add(new SKPoint(x + w, y)); points.Add(new SKPoint(x + w, y + h * 0.25f)); points.Add(new SKPoint(x + w + squeeze, y + h * 0.5f)); points.Add(new SKPoint(x + w, y + h * 0.75f)); points.Add(new SKPoint(x + w, y + h)); points.Add(new SKPoint(x + w * 0.75f, y + h)); points.Add(new SKPoint(x + w * 0.5f, y + h)); points.Add(new SKPoint(x + w * 0.25f, y + h)); points.Add(new SKPoint(x, y + h)); points.Add(new SKPoint(x, y + h * 0.75f)); points.Add(new SKPoint(x - squeeze, y + h * 0.5f)); points.Add(new SKPoint(x, y + h * 0.25f)); points.RemoveAt(12); points.RemoveAt(8); points.RemoveAt(4); points.RemoveAt(0); points.Add(new SKPoint(x + w * 0.25f, y)); return(points); }
void draw(SKCanvas canvas) { int frameCount = Utility.CreateRandom(1, 499); int random_seed = (int)(frameCount * 1000000 / (DateTime.Now.Second + 1)); random_seed = getSeed(random_seed); //helper.set_seed(random_seed) //blendMode(BLEND) paint.BlendMode = SKBlendMode.Multiply; // translate(width / 2, height / 2) canvas.Translate(w / 2f, h / 2f); canvas.Save(); int palette_idx = RandomUtility.CreateRandom(0, pal.Count); var palette = pal[palette_idx]; //range_upper_angles = [x for x in range( int( random( 0, 20 ) ), int( random( 50, 80 ) ), int( random( 7, 20 ) ) )] //range_lower_angles = [x for x in range( int( random( 0, 20 ) ), int( random( 50, 80 ) ), int( random( 7, 20 ) ) )] // class range(start, stop[, step]) // 0: start/min, 1: end/max, 2: step int[] upperSettings = new int[3] { RandomUtility.CreateRandom(0, 20), RandomUtility.CreateRandom(50, 80), RandomUtility.CreateRandom(7, 20) }; List <int> range_upper_angles = new List <int>(); for (int i = upperSettings[0]; i < upperSettings[1]; i += upperSettings[2]) { range_upper_angles.Add(i); } int[] lowerSettings = new int[3] { RandomUtility.CreateRandom(0, 20), RandomUtility.CreateRandom(50, 80), RandomUtility.CreateRandom(7, 20) }; List <int> range_lower_angles = new List <int>(); for (int i = lowerSettings[0]; i < lowerSettings[1]; i += lowerSettings[2]) { range_lower_angles.Add(i); } //range_upper_radii = [width * 0.2, width * 0.45] //range_lower_radii = [width * 0.2, width * 0.3] //SKPoint range_upper_radii = new SKPoint( w * 0.2f, w * 0.45f ); //SKPoint range_lower_radii = new SKPoint( w * 0.2f, w * 0.3f ); int num_layers = 10; string lines = RandomUtility.GetRandomElement <string>(availableLines); // curveTightness(random(-2, 0.6)) DrawUpperWings(canvas, palette, num_layers, lines, range_upper_angles); var lastPalette = DrawLowerWings(canvas, palette, lines, range_lower_angles); var lastUpperAngle = range_upper_angles[range_upper_angles.Count - 1]; lastPalette = RandomUtility.GetRandomElement <SKColor>(palette); DrawAntennaeAndBody(canvas, lastUpperAngle, lastPalette); }
void draw_bird_beak(SKCanvas canvas, SKColor pc, SKColor bc, SKColor dc) { int y_variance = RandomUtility.CreateRandom(10, 40); int length_variance = RandomUtility.CreateRandom(50, 100); var p1 = new SKPoint(head_x, head_y - y_variance); var p2 = new SKPoint(head_x, head_y + y_variance); var p3 = new SKPoint(head_x + length_variance, head_y); paint.Style = SKPaintStyle.Stroke; paint.Color = dc; SkiaSharpUtility.DrawTriangle(canvas, paint, p1, p2, p3); paint.Style = SKPaintStyle.Fill; paint.Color = RandomUtility.CreateRandom() < body_fill_chance ? pc : bc; SkiaSharpUtility.DrawTriangle(canvas, paint, p1, p2, p3); }
int getSeed(int random_seed = 0) { int max_seed = 1000000; if (random_seed == 0) { return(RandomUtility.CreateRandom(0, max_seed)); } if (random_seed < max_seed) { return(random_seed); } else { return(random_seed % max_seed); } }
void draw_lines(SKCanvas canvas, List <SKPoint> point_list, SKColor color) { var p1 = RandomUtility.PopRandomElement(point_list); var p2 = RandomUtility.PopRandomElement(point_list); var p3 = RandomUtility.PopRandomElement(point_list); int lines = RandomUtility.CreateRandom(min_shape_lines, max_shape_lines); float first_x_adj = 1; if (p3.X - p1.X == 0) { first_x_adj = 1; } else { first_x_adj = (p3.X - p1.X) / Math.Abs(p3.X - p1.X); } float first_y_adj = 1; if (p3.Y - p1.Y == 0) { first_y_adj = 1; } else { first_y_adj = (p3.Y - p1.Y) / Math.Abs(p3.Y - p1.Y); } double first_x_sep = Math.Sqrt(Math.Pow(p1.X - p3.X, 2)) / lines * first_x_adj; double first_y_sep = Math.Sqrt(Math.Pow(p1.Y - p3.Y, 2)) / lines * first_y_adj; float second_x_adj = 1; if (p3.X - p2.X == 0) { second_x_adj = 1; } else { second_x_adj = (p3.X - p2.X) / Math.Abs(p3.X - p2.X); } float second_y_adj = 1; if (p3.Y - p2.Y == 0) { second_y_adj = 1; } else { second_y_adj = (p3.Y - p2.Y) / Math.Abs(p3.Y - p2.Y); } double second_x_sep = Math.Sqrt(Math.Pow(p2.X - p3.X, 2)) / lines * second_x_adj; double second_y_sep = Math.Sqrt(Math.Pow(p2.Y - p3.Y, 2)) / lines * second_y_adj; paint.Color = color; for (int i = 0; i < lines; i++) { float x1 = (float)(p1.X + first_x_sep * i); float y1 = (float)(p1.Y + first_y_sep * i); float x2 = (float)(p2.X + second_x_sep * i); float y2 = (float)(p2.Y + second_y_sep * i); canvas.DrawLine(x1, y1, x2, y2, paint); } }
SKPoint draw_bird_body(SKCanvas canvas, float x, float y, SKColor pc, SKColor bc, SKColor dc) { // stroke(*dc) float body_bottom = y - feet_length / 2.0f; SKPoint body_one = new SKPoint(x - feet_length * 2.0f, body_bottom); SKPoint body_two = new SKPoint(x + feet_length * 1.5f, body_bottom); SKPoint body_three = new SKPoint(x + feet_length * 2.1f, body_bottom - body_height); SKPoint body_four = new SKPoint(x, body_bottom - body_height * 1.3f); SKPoint left_midpoint = new SKPoint((body_four.X + body_one.X) / 2, (body_four.Y + body_one.Y) / 2); SKPoint top_midpoint = new SKPoint((body_four.X + body_three.X) / 2, (body_four.Y + body_three.Y) / 2); SKPoint right_midpoint = new SKPoint((body_two.X + body_three.X) / 2, (body_two.Y + body_three.Y) / 2); SKPoint bottom_midpoint = new SKPoint((body_one.X + body_two.X) / 2, (body_one.Y + body_two.Y) / 2); //SKPoint true_midpoint = new SKPoint( ( left_midpoint.X + right_midpoint.X ) / 2, ( left_midpoint.Y + right_midpoint.Y ) / 2 ); List <SKPoint> body_points = new List <SKPoint>() { body_one, body_three, body_four, left_midpoint, top_midpoint, bottom_midpoint }; //fill( *bc ) //beginShape() var pathBody = new SKPath { FillType = SKPathFillType.EvenOdd }; pathBody.MoveTo(body_one); pathBody.LineTo(body_two); pathBody.LineTo(body_three); pathBody.LineTo(body_four); pathBody.Close(); SkiaSharpUtility.PathStroke(canvas, paint, dc, pathBody); SkiaSharpUtility.PathFill(canvas, paint, bc, pathBody); //endShape(CLOSE) int range = RandomUtility.CreateRandom(1, 4); for (int i = 0; i < range; i++) { var point_one = RandomUtility.GetRandomElement(body_points); var point_two = RandomUtility.GetRandomElement(body_points); var point_three = RandomUtility.GetRandomElement(body_points); //var point_four = RandomUtility.GetRandomElement( body_points ); // fill(pc[0], pc[1], pc[2]) //beginShape() var path = new SKPath { FillType = SKPathFillType.EvenOdd }; path.MoveTo(point_one); path.LineTo(point_two); path.LineTo(point_three); path.Close(); SkiaSharpUtility.PathStroke(canvas, paint, dc, path); SkiaSharpUtility.PathFill(canvas, paint, pc, path); //endShape(CLOSE) if (RandomUtility.CreateRandom() < 0.5) { draw_lines(canvas, body_points, dc); } } // for head_x = x + feet_length; head_y = body_bottom - body_height * 1.1f; return(body_one); }
void DrawAntennaeAndBody(SKCanvas canvas, int lastUpperAngle, SKColor palette) { paint.StrokeWidth = w * 0.002f; var body = get_16_points(-w * 0.015f, -h * 0.15f, w * 0.03f, h * 0.5f); //curveTightness(0) // Body // x: Clear, DstATop, DstOver paint.BlendMode = SKBlendMode.SrcOver; //fill( 0, 0, 100 ) //noStroke() //ProcessingSkiaSharp.fill( paint, SKColor.FromHsv( 0, 0, 100 ) ); ProcessingSkiaSharp.strokeAndFill(paint, new SKColor(255, 255, 255, 255)); draw_16_points(canvas, body); // Antennae paint.BlendMode = SKBlendMode.Multiply; List <SKPoint> antennae = new List <SKPoint>(); int max = RandomUtility.CreateRandom(3, 8); for (int i = 0; i < max; i++) { float x = body[0].X; float y = body[0].Y; float r = RandomUtility.CreateRandom(h * 0.1f, h * 0.3f); //a = random(range_upper_angles[-1] * 1.2, 80) float a = RandomUtility.CreateRandom(lastUpperAngle * 1.2f, 80); double radians = ProcessingSkiaSharp.radians(a); var pt = circle_points(x, y, r, (float)radians); antennae.Add(pt); } //antennae.Add( antennae[0] ); List <float> curve_tightness = new List <float>(); foreach (var a in antennae) { curve_tightness.Add(RandomUtility.CreateRandom(-2, 0.8f)); } //pushStyle() //pushMatrix() //canvas.ResetMatrix(); int canvasCacheTag = canvas.Save(); float randomDY = RandomUtility.CreateRandom(h * 0.24f, h * 0.26f); canvas.Translate(0, -randomDY); ProcessingSkiaSharp.noFill(paint); //strokeWeight(width * 0.001) //paint.StrokeWidth = w * 0.001f; //stroke( p[0], p[1], 25 )palette //ProcessingSkiaSharp.stroke( paint, palette.Red, palette.Green, 25 ); ProcessingSkiaSharp.stroke(paint, new SKColor(palette.Red, palette.Green, 25)); //int alpha = RandomUtility.CreateRandom( 80, 230 ); //ProcessingSkiaSharp.stroke( paint, palette.Red, palette.Green, palette.Blue, (byte)alpha ); canvas.Scale(1, -1); drawAntennae(canvas, body, antennae); canvas.Scale(-1, 1); drawAntennae(canvas, body, antennae); //canvas.ResetMatrix(); canvas.RestoreToCount(canvasCacheTag); }
SKColor DrawLowerWings(SKCanvas canvas, List <SKColor> palette, string lines, List <int> range_lower_angles) { SKPoint origin = new SKPoint(0, 0); List <byte> random2Bytes = new List <byte>() { 0, 60 }; SKColor p = SKColors.Transparent; for (int i = 0; i < 11; i++) { switch (lines) { case "none": // noStroke() ProcessingSkiaSharp.noStroke(paint); break; case "all": // stroke(0, 0, 0, 60) ProcessingSkiaSharp.stroke(paint, 0, 0, 0, 60); break; case "outer": // stroke(0, 0, 0, 60) ProcessingSkiaSharp.stroke(paint, 0, 0, 0, 60); break; case "some": // stroke(0, 0, 0, helper.random_list_value([0, 60])) byte randomByte = RandomUtility.GetRandomElement(random2Bytes); ProcessingSkiaSharp.stroke(paint, 0, 0, 0, randomByte); break; } //p = palette[int(random(0, len(palette)))] p = RandomUtility.GetRandomElement <SKColor>(palette); if (i == 3 || i == 6) { // fill(0, 0, 100, 100) ProcessingSkiaSharp.fill(paint, 0, 0, 100, 100); } else { //fill(p[0], p[1], p[2], 20) ProcessingSkiaSharp.fill(paint, p.Red, p.Green, p.Blue, 20); } List <SKPoint> wing = new List <SKPoint>() { origin }; foreach (int angle in range_lower_angles) { // circle_points_list(random(0, width * 0.01), random(0, height * 0.01), random( width * 0.15, width * 0.3 ), radians( random( angle - 7, angle ) ))) float randomAngle = RandomUtility.CreateRandom(angle - 7, angle); var cp = circle_points_list(RandomUtility.CreateRandom(0, w * 0.01f), RandomUtility.CreateRandom(0, h * 0.01f), RandomUtility.CreateRandom(w * 0.15f, w * 0.3f), (float)ProcessingSkiaSharp.radians(randomAngle)); wing.Add(cp); } float tmpRangle = RandomUtility.CreateRandom(73, 87); var tmpCp = circle_points_list(RandomUtility.CreateRandom(0, w * 0.01f), RandomUtility.CreateRandom(0, h * 0.01f), RandomUtility.CreateRandom(w * 0.15f, w * 0.3f), (float)ProcessingSkiaSharp.radians(tmpRangle)); wing.Add(tmpCp); draw_wings(canvas, wing); } // for (int i = 0; i< 11 for (int i = 0; i < 11; i++) { switch (lines) { case "none": // noStroke() ProcessingSkiaSharp.noStroke(paint); break; case "all": // stroke(0, 0, 0, 60) ProcessingSkiaSharp.stroke(paint, 0, 0, 0, 60); break; case "outer": // noStroke() ProcessingSkiaSharp.noStroke(paint); break; case "some": // stroke(0, 0, 0, helper.random_list_value([0, 60])) byte randomByte = RandomUtility.GetRandomElement(random2Bytes); ProcessingSkiaSharp.stroke(paint, 0, 0, 0, randomByte); break; } //p = palette[int(random(0, len(palette)))] p = RandomUtility.GetRandomElement <SKColor>(palette); if (i == 3 || i == 6) { // fill(0, 0, 100, 100) ProcessingSkiaSharp.fill(paint, 0, 0, 100, 100); } else { //fill(p[0], p[1], p[2], 20) ProcessingSkiaSharp.fill(paint, p.Red, p.Green, p.Blue, 20); } List <SKPoint> wing = new List <SKPoint>() { origin }; foreach (int angle in range_lower_angles) { // circle_points_list(random(0, width * 0.01), random(0, height * 0.01), random( width * 0.05, width * 0.2 ), radians( random( angle - 7, angle ) ))) float randomAngle = RandomUtility.CreateRandom(angle - 7, angle); var cp = circle_points_list(RandomUtility.CreateRandom(0, w * 0.01f), RandomUtility.CreateRandom(0, h * 0.01f), RandomUtility.CreateRandom(w * 0.05f, w * 0.2f), (float)ProcessingSkiaSharp.radians(randomAngle)); wing.Add(cp); } float tmpRangle = RandomUtility.CreateRandom(73, 87); var tmpCp = circle_points_list(RandomUtility.CreateRandom(0, w * 0.01f), RandomUtility.CreateRandom(0, h * 0.01f), RandomUtility.CreateRandom(w * 0.05f, w * 0.2f), (float)ProcessingSkiaSharp.radians(tmpRangle)); wing.Add(tmpCp); draw_wings(canvas, wing); } // for (int i = 0; i< 11 return(p); }
void DrawUpperWings(SKCanvas canvas, List <SKColor> palette, int num_layers, string lines, List <int> range_upper_angles) { SKPoint origin = new SKPoint(0, 0); List <byte> random2Bytes = new List <byte>() { 0, 60 }; //List<List<SKPoint>> upper_wing = new List<List<SKPoint>>(); //for (int i = 0; i < num_layers; i++) { // //List<SKPoint> points // //upper_wing.Add //} // for (int i = 0; i < num_layers for (int i = 0; i < 7; i++) { switch (lines) { case "none": // noStroke() ProcessingSkiaSharp.noStroke(paint); break; case "all": // stroke(0, 0, 0, 60) ProcessingSkiaSharp.stroke(paint, 0, 0, 0, 60); break; case "outer": // stroke(0, 0, 0, 60) ProcessingSkiaSharp.stroke(paint, 0, 0, 0, 60); break; case "some": // stroke(0, 0, 0, helper.random_list_value([0, 60])) byte randomByte = RandomUtility.GetRandomElement(random2Bytes); ProcessingSkiaSharp.stroke(paint, 0, 0, 0, randomByte); break; } //p = palette[int(random(0, len(palette)))] if (i == 3 || i == 6) { // fill(0, 0, 100, 100) ProcessingSkiaSharp.fill(paint, 0, 0, 100, 100); } else { var p = RandomUtility.GetRandomElement <SKColor>(palette); //fill(p[0], p[1], p[2], 20) ProcessingSkiaSharp.fill(paint, p.Red, p.Green, p.Blue, 20); } List <SKPoint> wing = new List <SKPoint>() { origin }; foreach (int angle in range_upper_angles) { // circle_points_list(random(0, width * 0.01), random(0, height * 0.01), random( width * 0.2, width * 0.4 ), radians( random( angle - 7, angle ) ) float randomAngle = RandomUtility.CreateRandom(angle - 7, angle); var cp = circle_points_list(RandomUtility.CreateRandom(0, w * 0.01f), RandomUtility.CreateRandom(0, h * 0.01f), RandomUtility.CreateRandom(w * 0.2f, w * 0.4f), (float)ProcessingSkiaSharp.radians(randomAngle)); wing.Add(cp); } draw_wings(canvas, wing, true); } // for (int i = 0; i< 7 for (int i = 0; i < 7; i++) { switch (lines) { case "none": // noStroke() ProcessingSkiaSharp.noStroke(paint); break; case "all": // stroke(0, 0, 0, 60) ProcessingSkiaSharp.stroke(paint, 0, 0, 0, 60); break; case "outer": // noStroke() ProcessingSkiaSharp.noStroke(paint); break; case "some": // stroke(0, 0, 0, helper.random_list_value([0, 60])) byte randomByte = RandomUtility.GetRandomElement(random2Bytes); ProcessingSkiaSharp.stroke(paint, 0, 0, 0, randomByte); break; } //p = palette[int(random(0, len(palette)))] if (i == 3 || i == 6) { // fill(0, 0, 100, 100) ProcessingSkiaSharp.fill(paint, 0, 0, 100, 100); } else { var p = RandomUtility.GetRandomElement <SKColor>(palette); //fill(p[0], p[1], p[2], 20) ProcessingSkiaSharp.fill(paint, p.Red, p.Green, p.Blue, 20); } List <SKPoint> wing = new List <SKPoint>() { origin }; foreach (int angle in range_upper_angles) { // circle_points_list(random(0, width * 0.01), random(0, height * 0.01), random( width * 0.2, width * 0.4 ), radians( random( angle - 7, angle ) ) float randomAngle = RandomUtility.CreateRandom(angle - 7, angle); var cp = circle_points_list(RandomUtility.CreateRandom(0, w * 0.01f), RandomUtility.CreateRandom(0, h * 0.01f), RandomUtility.CreateRandom(w * 0.1f, w * 0.2f), (float)ProcessingSkiaSharp.radians(randomAngle)); wing.Add(cp); } draw_wings(canvas, wing, true); } // for (int i = 0; i< 7 }