Generate Thumbnail

Multishape patterns

Setup 1 2 #r "nuget:SkiaSharp" using SkiaSharp; Color Sets 1 2 3 4 5 6 7 8 9 10 11 12 var listOfColor = new List<SKColor> { SKColor.Parse("#86B6F6"), SKColor.Parse("#176B87"), SKColor.Parse("#00A9FF"), SKColor.Parse("#FF90BC"), SKColor.Parse("#8ACDD7"), SKColor.Parse("#F2AFEF"), SKColor.Parse("#C499F3"), SKColor.Parse("#33186B"), }; Generate point on circumference of circle of different radius 1 2 3 4 5 6 7 8 9 List<SKPoint> CirclePoints(int n,float radius=3,float x=0, float y=0 ) { float degree = (float)(2*Math.PI/n); return Enumerable .Range(1,n) .Select(i=>degree*i) .Select(i=>(new SKPoint(x+ radius *(float)Math.Cos(i), y+ radius *(float)Math.Sin(i)))) .ToList(); } Section formulae Classic Geometric Formula To Calculate division point on line 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 List<(SKPoint,SKPoint)> SectionFormulae(int times, List<SKPoint> points , float factor =0.25f) { var ls = new List<(SKPoint,SKPoint)>(); float m= times*factor; float n= times-m; for(var i=0; i<times;i++) { var templs = new List<SKPoint>(); for(var j=0;j<points.Count;j++) { if(j==points.Count-1) { var x = (m*points[j].X + n*points[0].X)/times; var y = (m*points[j].Y + n*points[0].Y)/times; templs.Add(new SKPoint(x,y)); } else { var x = (m*points[j].X + n*points[j+1].X)/times; var y = (m*points[j].Y + n*points[j+1].Y)/times; templs.Add(new SKPoint(x,y)); } } points = templs; for(var j=0;j<points.Count;j++) { if(j==points.Count-1) { ls.Add((points[j],points[0])); } else { ls.Add((points[j],points[j+1])); } } } return ls; } Granullar Function for more Control Over Shapes 1 2 3 4 public List<(SKPoint,SKPoint)> GetShape(int n=3, int times=6 ,float factor =0.25f,int baseLength=600,int centerX =0,int centerY=0) { return SectionFormulae(times,CirclePoints(n,baseLength,x:centerX,y:centerY),factor); } Skiasharp Codde to Use All above Function and Generate Shapes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 // Create an image and fill it blue int width = 2000; int height = 2000; int step =50; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); Random rand = new(); SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true , StrokeWidth = 2, ColorF = SKColor.Parse("#003366") }; int seperation=4; for(var i=3;i<=15;i+=3) { paint.Color=listOfColor[rand.Next(0,listOfColor.Count)]; foreach(var item in GetShape(n:i,times:25, factor:0.08f, baseLength:seperation* i*i,centerX:width/2,centerY:height/2)) { canvas.DrawLine(item.Item1,item.Item2,paint); } } // Save the image to disk SKFileWStream fs = new("multishape.jpg"); bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 100); bmp.Display();

June 21, 2024 · 2 min · 375 words · PrashantUnity
Generate Thumbnail

Mosaic in SkiaSharp

Setup 1 2 #r "nuget:SkiaSharp" using SkiaSharp; Mosaic Generation Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 // Create an image and fill it blue int width = 1920; int height = 700; int step =50; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); Random rand = new(); SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true , StrokeWidth = 2, ColorF = SKColor.Parse("#003366") }; for(var i=0; i<height;i+=step) { for(var j=0; j<width;j+=step) { if(rand.Next(0,100)>50) paint.ColorF =SKColor.Parse("#003366"); else paint.Color =SKColor.Parse("#000f"); canvas.DrawRect(i,j,step,step,paint); } } SKFileWStream fs = new("mosaic.jpg"); bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 50); bmp.Display();

June 20, 2024 · 1 min · 121 words · PrashantUnity
Generate Thumbnail

Mazes in SkiaSharp

Setup 1 2 #r "nuget:SkiaSharp" using SkiaSharp; Maze Algorithm 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 public class MazeAlgorithm { Random random = new Random(); public int[,] GenerateMaze(int rows, int cols) { int[,] maze = new int[rows, cols]; // Initialize maze with walls for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { maze[i, j] = 1; } } // Set starting point maze[1, 1] = 0; DFS(maze, 1, 1); return maze; } void DFS(int[,] maze, int row, int col) { int[] directions = { 1, 2, 3, 4 }; Shuffle(directions); foreach (int dir in directions) { int[] dRow = { 0, 0, 1, -1 }; int[] dCol = { 1, -1, 0, 0 }; int newRow = row + 2 * dRow[dir - 1]; int newCol = col + 2 * dCol[dir - 1]; if (newRow > 0 && newRow < maze.GetLength(0) - 1 && newCol > 0 && newCol < maze.GetLength(1) - 1 && maze[newRow, newCol] == 1) { maze[row + dRow[dir - 1], col + dCol[dir - 1]] = 0; maze[newRow, newCol] = 0; DFS(maze, newRow, newCol); } } } void Shuffle(int[] array) { int n = array.Length; for (int i = 0; i < n; i++) { int r = i + random.Next(n - i); int temp = array[r]; array[r] = array[i]; array[i] = temp; } } } Skia Sharp To Utilise maze Algorithm and Generate Maze Image 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 // Create an image and fill it blue int width = 1920; int height = 1080; int step =50; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); Random rand = new(); SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true , StrokeWidth = 2, ColorF = SKColor.Parse("#003366") }; int m= width/step, n=height/step; var ls = (new MazeAlgorithm()).GenerateMaze(m,n); ls[0,1]=0; for(var i=0; i<m;i++) { for(var j=0; j<n;j++) { paint.ColorF=(ls[i,j]==0)?SKColor.Parse("#ffffff"):SKColor.Parse("#000000"); canvas.DrawRect(i*step,j*step,step,step,paint); } } SKFileWStream fs = new("maze.jpg"); bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 50); bmp.Display();

June 19, 2024 · 2 min · 412 words · PrashantUnity
Generate Thumbnail

Mandelbrot in SkiaSharp

Setup 1 2 #r "nuget:SkiaSharp" using SkiaSharp; Mandelbrot 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 // Create an image and fill it blue int width = 1920; int height = 1080; int step =50; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse("#fff")); Random rand = new(); SKPaint paint = new() { Color = SKColors.White.WithAlpha(100), IsAntialias = true , StrokeWidth = 2, ColorF = SKColor.Parse("#003366") }; double zoom = 1; double moveX = -0.5; double moveY = 0; int maxIterations = 50; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double zx = 1.5 * (x - width / 2) / (0.5 * zoom * width) + moveX; double zy = (y - height / 2) / (0.5 * zoom * height) + moveY; double cx = zx; double cy = zy; int iteration = 0; double tmp; while ((zx * zx + zy * zy < 4) && (iteration < maxIterations)) { tmp = zx * zx - zy * zy + cx; zy = 2.0 * zx * zy + cy; zx = tmp; iteration++; } if (iteration == maxIterations) { canvas.DrawPoint(x, y, SKColors.Black); } else { // Colorize based on the number of iterations var color = SKColor.FromHsv(iteration % 256, 255, 255); canvas.DrawPoint(x, y, color); } } } SKFileWStream fs = new("mandelbrot.jpg"); bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 50); bmp.Display();

June 18, 2024 · 2 min · 284 words · PrashantUnity
Generate Thumbnail

CFD logo in SkiaSharp

Creating Logos with SkiaSharp LOGO on this website is generated using SkiaSharp Only Requirements Visual Studio Code (VS Code) Polyglot Notebook Extension A little bit of experience in C# For Basic/Installation please visit Basic Setup Code Install SkiaSharp 1 #r "nuget:SkiaSharp" Import SkiaSharp Library 1 using SkiaSharp; Code To Generate Logo Logo Dimention and Stuff 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 int width=700; int height=700; int step = 30; float textSize =128f; string fontFamilyName = "Arial"; string LogoText ="<CFD/>"; float shiftX=150; float dividerX=2.0f; float shiftY=38; float dividerY=3.0f; var left=width/dividerX -shiftX; var top=height/dividerY -shiftY; var right= textSize*3.95f; var bottom=textSize*4f; float targetWidth = 800; // desired width float targetHeight = 800; // desired height float offsetX = 800; // horizontal offset float offsetY = 800; Vapor Structure Path ...

June 17, 2024 · 3 min · 490 words · PrashantUnity
Download Logo

First app in VS (Ch. 2)

Create Your First C# Console Application in Visual Studio Follow these steps to create and run a simple C# console application in Visual Studio. Step 1: Create a New Project Open Visual Studio and click on Create a New Project. Step 2: Choose the Console App Template In the search bar, type Console. Select Console App (C#) from the results. Click Next at the bottom right of the window. ...

June 17, 2024 · 2 min · 248 words · PrashantUnity
Download Logo

First app with CLI (Ch. 2)

Create a C# Console Application Using the CLI Follow these steps to create and run a simple C# console application using the command line. Step 1: Open Terminal and Create a New Project Open your terminal and type the following command to create a new console application project named “HelloWorld”: 1 dotnet new console -o HelloWorld Step 2: Confirm Project Creation After pressing Enter, the command will generate a new project. You should see a confirmation message similar to the image below. ...

June 17, 2024 · 2 min · 256 words · PrashantUnity
Download Logo

First notebook app (Ch. 2)

Using Polyglot Notebook in VS Code Step-by-Step Guide 1. Install Polyglot Notebook Open VS Code. Press Control + Shift + X to open the Extensions view. Search for “Polyglot Notebook” or directly open the URL Polyglot Notebook Extension. Look for the extension logo as shown below and install it. 2. Create a New File Create a new file named HelloWorld.ipynb as shown in the image below. Double-click to open the file. ...

June 17, 2024 · 1 min · 150 words · PrashantUnity
Google Drive Logo

GitHub Actions data jobs

Create a New Console Project I am going to create a dotnet project to demonstrate this, but it is applicable for all other programming languages as well Open any folder, then open Terminal In Terminal, create a new dotnet console project using the below command 1 2 3 4 5 6 7 8 dotnet new console -n GitCiCd cd .\GitCiCd\ code . mkdir .github cd .\.github\ mkdir workflows cd .\workflows\ echo "" > "dotnet.yaml" In dotnet.yaml file Paste Below Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 name: workflows on: push: branches: [ "master" ] jobs: scrape_videos: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Set up .NET uses: actions/setup-dotnet@v2 with: dotnet-version: '8.0.x' # Use the latest .NET version - name: Restore dependencies run: dotnet restore - name: Build the project run: dotnet build --configuration Release - name: Run the scraping script run: dotnet run --project GetYoutubeVideo.csproj - name: Commit and Push Changes run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add Text.txt git commit -m "Update Text.txt list" git push Inside Program.cs file paste below code for. 1 2 3 4 5 6 7 8 9 10 11 var ls = Enumerable.Range(1,8).Select(i => i.ToString() + DateTime.Now).ToList(); SaveToFile(ls, "Text.txt"); static void SaveToFile(List<string> videos, string filePath) { using StreamWriter file = new(filePath); foreach (var video in videos) { file.WriteLine(video); } } The code Responsible for operation is below code 1 2 3 4 5 6 7 - name: Commit and Push Changes run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add Text.txt git commit -m "Update Text.txt list" git push Push to github Now Go to Repository Setting Tab ...

July 28, 2024 · 2 min · 356 words · PrashantUnity
Download Logo

C# basics (Ch. 3)

Comments in C# Comments are essential for making your code understandable. They can explain what your code does, which is helpful for anyone reading it (including yourself). Inline Comments: Use // for single-line comments. 1 // This is an inline comment. Multi-line Comments: Use /* */ for comments that span multiple lines. 1 2 3 4 /* This is a multi-line comment. It spans multiple lines. */ Semicolons In C#, every statement ends with a semicolon (;). This tells the compiler where a statement ends. ...

June 16, 2024 · 3 min · 461 words · PrashantUnity