開発環境 |
Microsoft Visual C# 2010 Express (SP1) |
実行環境 |
Microsoft Windows XP Home Edition (SP3) |
プロジェクトの種類 |
Windows Game (4.0) |
プロジェクト名 |
XnaLissajous |
Game1.cs
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace XnaLissajous
{
class Game1 : Game
{
GraphicsDeviceManager graphics;
BasicEffect effect;
int deg = 0;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
IsMouseVisible = true;
}
protected override void LoadContent()
{
effect = new BasicEffect(GraphicsDevice);
effect.VertexColorEnabled = true;
base.LoadContent();
}
protected override void Update(GameTime gameTime)
{
KeyboardState kState = Keyboard.GetState();
if (kState.IsKeyDown(Keys.Escape)) Exit();
deg = (deg + 1) % 360;
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
GraphicsDevice.BlendState = BlendState.AlphaBlend;
VertexPositionColor[] vertices = new VertexPositionColor[240 + 1];
for (int n = 0; n <= 240; n++)
{
float rad = MathHelper.ToRadians((deg + n));
vertices[n] = new VertexPositionColor(
new Vector3((float)Math.Cos(rad * 3) * 0.9f, (float)Math.Sin(rad * 2) * 0.9f, 0),
Color.White * (n / 240.0f));
}
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
PrimitiveType.LineStrip, vertices, 0, 240);
}
base.Draw(gameTime);
}
}
}
最終更新:2012年12月10日 17:59