source: 2017/30/MikkoH/Sq/Sq/Sq/Sq.cs @ 9261

Revision 9261, 2.7 KB checked in by mianhayr, 6 years ago (diff)

pallo pyörii lol

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4
5public class Sq : PhysicsGame
6{
7    List<Vector> ps = new List<Vector>(), crc = new List<Vector>();
8    double x, y, z, a, fac = Math.Pow(2, -15), rad = 200, radc = 0.02;
9
10    public override void Begin()
11    {
12        Window.Width = 1200; Window.Height = 800;
13        Level.Background.Color = Color.Black;
14        Mouse.IsCursorVisible = true;
15
16        for (int i = -300; i <= 300; i += 10) ps.Add(new Vector(-300, i));
17        for (int i = -300; i <= 300; i += 10) ps.Add(new Vector(i, 300));
18        for (int i = 300; i >= -300; i -= 10) ps.Add(new Vector(300, i));
19        for (int i = 300; i >= -300; i -= 10) ps.Add(new Vector(i, -300));
20
21        for (int i = 0; i <= 100; i += 1)
22            crc.Add(new Vector(Math.Sin(i) * rad, Math.Cos(i) * rad));
23
24        //for (int i = 0; i < 100; i++) trans.Add(new Vector(1, 1));
25        //for (int i = 0; i < 100; i++) trans.Add(new Vector(-1, -1));
26    }
27
28    protected override void Paint(Canvas c)
29    {
30        c.BrushColor = Color.Red;
31        double d = Time.SinceLastUpdate.TotalSeconds; //Mouse.PositionOnScreen.Angle.Degrees/1000;
32
33        for (int i = 0; i < ps.Count; i++)
34            c.DrawLine(ps[i % ps.Count], ps[(i + ps.Count / 4) % ps.Count]);
35
36        c.BrushColor = Color.Blue;
37           
38        for (int i = 0; i < crc.Count; i++)
39        {
40            c.DrawLine(crc[i % crc.Count], crc[(i + 1) % crc.Count]);
41            crc[i % crc.Count] = new Vector(Math.Sin(i) * rad, Math.Cos(i) * rad);
42            if (rad > 200 || rad < 1) radc = -radc; rad -= radc;
43        }
44
45        Rotate(ps, d); Rotate(crc, d, true);
46
47        //Squeeze(ps);
48
49        base.Paint(c);
50    }
51
52    void Rotate(List<Vector> vs, double d, bool reverse = false)
53    {
54        if (reverse) d = -d;
55        for (int i = 0; i < vs.Count; i++)
56            vs[i] = new Vector(vs[i].X * Math.Cos(-d) - vs[i].Y * Math.Sin(-d),
57                               vs[i].X * Math.Sin(-d) + vs[i].Y * Math.Cos(-d));
58    }
59
60    void Squeeze(List<Vector> vs)
61    {
62        //if (ps[0].X > -300) fac = -Math.Pow(2, -15);
63        //if (ps[ps.Count - 1].X < -300) fac = -Math.Pow(2, -15);
64
65        for (int i = 0; i < vs.Count / 4; i++) vs[i] = new Vector(vs[i].X + (x -= fac), vs[i].Y + (y -= fac));
66        for (int i = vs.Count / 4 * 3; i < vs.Count; i++) vs[i] = new Vector(vs[i].X + (x -= fac), vs[i].Y + (y -= fac));
67        for (int i = vs.Count / 4; i < vs.Count / 2; i++) vs[i] = new Vector(vs[i].X + (z += fac), vs[i].Y + (a += fac));
68        for (int i = vs.Count / 2; i < vs.Count / 4 * 3; i++) vs[i] = new Vector (vs[i].X + (z += fac), vs[i].Y + (a += fac));
69    }
70}
Note: See TracBrowser for help on using the repository browser.