Skip to content

Instantly share code, notes, and snippets.

@amantix
Created June 9, 2016 10:14
Show Gist options
  • Save amantix/3615bfef370c7210f73e7dcf98a308f2 to your computer and use it in GitHub Desktop.
Save amantix/3615bfef370c7210f73e7dcf98a308f2 to your computer and use it in GitHub Desktop.
C#. Рисование кружочков с использованием SmallBasicLibrary
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SmallBasic.Library;
class Program
{
private static Primitive circle2;
static double vx2 = 0;
static double vy2 = 0;
static void Main(string[] args)
{
GraphicsWindow.Show();
GraphicsWindow.PenColor = "blue";
GraphicsWindow.BrushColor = "cyan";
int circle_width = 50, circle_height = 50;
int width = 640;GraphicsWindow.Width=width;
int height = 400;GraphicsWindow.Height=height;
Primitive circle= Shapes.AddEllipse(circle_width, circle_height);
Shapes.Move(circle, width/2-circle_width/2 , height/2-circle_height/2);
double vx = 5;
double vy = 3;
circle2 = Shapes.AddEllipse(circle_width, circle_height);
Shapes.Move(circle2, width / 2 - circle_width / 2, height / 2 - circle_height / 2);
GraphicsWindow.KeyDown += GraphicsWindow_KeyDown;
while (true)
{
UpdateCircle(circle, ref vx, ref vy,circle_width, circle_height);
//UpdateCircle(circle2, ref vx2, ref vy2, circle_width, circle_height);
Microsoft.SmallBasic.Library.Program.Delay(30);
}
//Primitive circle2 = Shapes.AddEllipse(circle_width, circle_height);
//int duration = 1000;
//double destX = width - circle_width ;
//double destY = height - circle_height ;
//Animate(circle2,destX, destY,duration);
//Shapes.Animate(circle2, 0, 0, 1000);
}
private static void GraphicsWindow_KeyDown()
{
if(GraphicsWindow.LastKey=="Left")
{
vx2 = -10;
UpdateCircle(circle2,ref vx2,ref vy2,50,50);
}
else if(GraphicsWindow.LastKey=="Right")
{
double vx2 = 10;
UpdateCircle(circle2, ref vx2, ref vy2, 50, 50);
}
}
private static void UpdateCircle(Primitive circle, ref double vx, ref double vy,int circle_width, int circle_height)
{
double x = Shapes.GetLeft(circle) + vx;
if (x + circle_width > GraphicsWindow.Width)
{
x = GraphicsWindow.Width - circle_width;
vx *= -1;
}
else if (x < 0)
{
x = 0;
vx *= -1;
}
double y = Shapes.GetTop(circle) + vy;
if (y + circle_height > GraphicsWindow.Height)
{
y = GraphicsWindow.Height - circle_height;
vy *= -1;
}
else if (y < 0)
{
y = 0;
vy *= -1;
}
Shapes.Move(circle, x, y);
}
private static void Animate(Primitive circle2,double destX, double destY, int duration)
{
int steps = 100;
double stepX = (destX- Shapes.GetLeft(circle2))/steps;
double stepY = (destY- Shapes.GetTop(circle2))/steps;
for (int i = 0; i < steps; i++)
{
double left = Shapes.GetLeft(circle2);
double top = Shapes.GetTop(circle2);
Shapes.Move(circle2, left + stepX, top + stepY);
Microsoft.SmallBasic.Library.Program.Delay(duration/steps);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment