Created
June 6, 2016 10:25
-
-
Save amantix/4a95b86f51143148c295045c0d41d5d7 to your computer and use it in GitHub Desktop.
C# - рисование с помощью черепашки из SmallBasicLibrary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Microsoft.SmallBasic.Library; | |
namespace GoTurtle | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
GraphicsWindow.PenColor = "Blue"; | |
Turtle.Speed = 10; | |
GraphicsWindow.Show(); | |
Turtle.Show(); | |
//for(int j=0; j<3; j++) | |
// for (int i = 0; i < 5; i++) | |
// { | |
// DrawHouse(50+j%2*50+i*100,200+j*100, 50); | |
// } | |
//DrawCircle(200,200,50); | |
Turtle.X = 50; | |
Turtle.Y = 400; | |
DrawSnowFlake(400,4); | |
} | |
private static void DrawSnowFlake(double size=120, int details=3) | |
{ | |
Turtle.Turn(30); | |
DrawSegment(size, details); | |
Turtle.Turn(120); | |
DrawSegment(size, details); | |
Turtle.Turn(120); | |
DrawSegment(size, details); | |
} | |
private static void DrawSegment(double length, int level=0) | |
{ | |
if (level == 0) | |
Turtle.Move(length); | |
else | |
{ | |
DrawSegment(length/3, level - 1); | |
Turtle.Turn(-60); | |
DrawSegment(length / 3, level - 1); | |
Turtle.Turn(120); | |
DrawSegment(length / 3, level - 1); | |
Turtle.Turn(-60); | |
DrawSegment(length / 3, level - 1); | |
} | |
} | |
private static void DrawCircle(double x, double y, double radius) | |
{ | |
Turtle.X = x - radius; | |
Turtle.Y = y; | |
Turtle.Angle = 0; | |
for (int i = 0; i < 360; i++) | |
{ | |
Turtle.Move(System.Math.PI*radius/180); | |
Turtle.Turn(1); | |
} | |
} | |
private static void DrawHouse(double x, double y,double size=100) | |
{ | |
Turtle.X = x; | |
Turtle.Y = y; | |
Turtle.Angle = 0; | |
for (int i = 0; i < 4; i++) | |
{ | |
Turtle.Move(size); | |
Turtle.TurnRight(); | |
} | |
Turtle.Y -= size; | |
Turtle.MoveTo(Turtle.X + size/2, Turtle.Y - size); | |
Turtle.MoveTo(Turtle.X + size/2, Turtle.Y + size); | |
Turtle.X -= size/4; | |
Turtle.Y += size/4; | |
Turtle.Angle = 180; | |
for (int i = 0; i < 4; i++) | |
{ | |
Turtle.Move(size/2); | |
Turtle.TurnRight(); | |
} | |
Turtle.X = x; | |
Turtle.Y = y; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment