Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // room script file
- float radius;
- float radius_step = 3.0;
- float angle;
- bool alternate_direction = false;
- float equidistant = 0.0;
- float xc, yc;
- String text;
- void Init() {
- text = "This is a test sentence. I'm really curious about the result; I believe I have heard once about this before but seeing it in action is actually quite nice!";
- text = text.UpperCase();
- radius = 10.0;
- angle = 0.0;
- }
- DrawingSurface* backup;
- function room_Load()
- {
- DrawingSurface* ds = Room.GetDrawingSurfaceForBackground();
- backup = ds.CreateCopy();
- ds.Release();
- }
- int last_x, last_y;
- void SetCursorTo(this DrawingSurface*, int x, int y) {
- last_x = x;
- last_y = y;
- }
- void DrawLineTo(this DrawingSurface*, int x, int y) {
- this.DrawLine(last_x, last_y, x, y);
- last_x = x;
- last_y = y;
- }
- void DrawArc(DrawingSurface* ds, float d_angle) {
- // to get a smooth arc, use smaller steps the bigger the radius
- float step = 10000.0 / radius;
- float step_angle = d_angle / step;
- int steps = FloatToInt(d_angle / step_angle, eRoundNearest);
- if (steps < 0) steps = -steps;
- int i;
- float da;
- while (i < steps) {
- angle += step_angle;
- da = Maths.DegreesToRadians(angle);
- ds.DrawLineTo(FloatToInt(xc + Maths.Sin(da) * radius, eRoundNearest), FloatToInt(yc + Maths.Cos(da) * radius, eRoundNearest));
- i++;
- }
- while (angle < 0.0) angle += 360.0;
- while (angle >= 360.0) angle -= 360.0;
- }
- void DrawFigure() {
- Init();
- DrawingSurface* ds = Room.GetDrawingSurfaceForBackground();
- ds.DrawSurface(backup);
- ds.DrawingColor = Game.GetColorFromRGB(4, 4, 4);
- ds.SetCursorTo(FloatToInt(xc, eRoundNearest), FloatToInt(yc + radius, eRoundNearest));
- int i;
- float d_angle;
- float da;
- int cnt;
- while (i < text.Length) {
- int c = text.Chars[i];
- if (c >= eKeyA && c <= eKeyZ) {
- cnt++;
- d_angle = IntToFloat(c - (eKeyA-1)) * 360.0 / 26.0;
- radius += radius_step;
- da = Maths.DegreesToRadians(angle);
- ds.DrawLineTo(FloatToInt(xc + Maths.Sin(da) * radius, eRoundNearest), FloatToInt(yc + Maths.Cos(da) * radius, eRoundNearest));
- if (alternate_direction && cnt % 2) d_angle = -d_angle;
- if (equidistant > 0.0) {
- float ed_d_angle = (d_angle * 10.0) / radius;
- d_angle = d_angle + (ed_d_angle - d_angle) * equidistant;
- }
- DrawArc(ds, d_angle);
- }
- i++;
- }
- ds.Release();
- }
- void room_AfterFadeIn() {
- xc = IntToFloat(System.ViewportWidth / 2);
- yc = IntToFloat(System.ViewportHeight / 2);
- DrawFigure();
- }
- void on_key_press(eKeyCode k) {
- if (k == eKeyEscape) QuitGame(0);
- if (k == eKeySpace) alternate_direction = !alternate_direction;
- if (k == eKeyLeftArrow && equidistant < 1.0) equidistant += 0.1;
- if (k == eKeyRightArrow && equidistant > 0.0) equidistant -= 0.1;
- DrawFigure();
- }
Advertisement
Add Comment
Please, Sign In to add comment