Changeset 9415


Ignore:
Timestamp:
2017-08-03 18:58:48 (23 months ago)
Author:
mianhayr
Message:

testailtu taas eri muodostelmia
lineaarinen liikutus toimii

Location:
2017/30/MikkoH/Sq
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2017/30/MikkoH/Sq/Sq/Sq/Sq.cs

    r9414 r9415  
    55public class Sq : Game 
    66{    
    7     double glmin = 0.5, glmax = 3; // Vector gloff = new Vector(50, 50);  
    8     List<Square> sqs = new List<Square>(); bool glrev; 
     7    double glmin = 0.5, glmax = 3; bool glrev; 
     8    List<Square> sqs = new List<Square>(); 
     9    //List<Vector> off = new List<Vector>(); int n; 
    910 
    1011    public override void Begin() 
    1112    { 
    12         // Level.Width = Level.Height = Window.Width = Window.Height = 800; 
    13         Window.Height = 800; Window.Width = 1200; 
     13        Window.Height = 800; Window.Width = 800; 
    1414        Mouse.IsCursorVisible = true; Level.Background.Color = Color.Black; 
    1515 
    16         sqs.Add(new Square(new Vector(0,0), 1, 400, 10, glrev = !glrev));       
     16        //off.Add(new Vector(-50,50)); off.Add(new Vector(-50,-50)); 
     17        //off.Add(new Vector(50,-50)); off.Add(new Vector(50,50)); 
     18 
     19        sqs.Add(new Square(new Vector(0,0), 1, 400, 10, glrev, new Vector(-30, 30))); 
     20        sqs.Add(new Square(new Vector(0, 0), 1, 400, 10, glrev, new Vector(-30, -30))); 
     21        sqs.Add(new Square(new Vector(0, 0), 1, 400, 10, glrev, new Vector(30, -30))); 
     22        sqs.Add(new Square(new Vector(0, 0), 1, 400, 10, glrev, new Vector(30, 30))); 
    1723    }       
    1824 
    19     void Rotate(List<Vector> vs, bool reverse = false) 
     25    protected override void Paint(Canvas c) 
    2026    { 
    21         double d = Time.SinceLastUpdate.TotalSeconds; 
    22         if (reverse) d = -d; 
    23         for (int i = 0; i < vs.Count; i++) 
    24             vs[i] = new Vector(vs[i].X * Math.Cos(-d) - vs[i].Y * Math.Sin(-d), 
    25                                vs[i].X * Math.Sin(-d) + vs[i].Y * Math.Cos(-d)); 
    26     } 
    27  
    28     protected override void Paint(Canvas c) 
    29     {        
    30         // loops through all squares to be drawn 
     27        if (sqs.Count == 0) Exit(); 
    3128        for (int i = 0; i < sqs.Count; i++) 
    3229        { 
     
    3532 
    3633            int d = (int)(1 + sqs[i].mag / (sqs[i].maxmag - sqs[i].minmag) * 254); 
    37             c.BrushColor = new Color(d, d, d); // scales color change from magnitude change, currently just white 
     34            c.BrushColor = new Color(d, d, d); // scales color change from magnitude change, TODO: something interesting 
    3835 
    3936            for (int j = 0; j < sqs[i].Count; j++) 
     
    4340            if (sqs[i].mag < sqs[i].minmag) 
    4441            { 
    45                 if (sqs[i].n == 0) Exit(); // minimum number of pts reached 
     42                if (sqs[i].n == 0) { sqs.Remove(sqs[i]); continue; } // number of pts reached 
    4643                sqs[i].magc = -sqs[i].magc; // reverse squeeze 
     44                sqs.Add(new Square(sqs[i].pos+sqs[i].off, sqs[i].minmag, sqs[i].maxmag * 0.9, sqs[i].n - 1, glrev = !glrev, sqs[i].off)); 
     45                sqs.Add(new Square(sqs[i].pos + sqs[i].off, sqs[i].minmag, sqs[i].maxmag / 4, 0, glrev = !glrev, sqs[i].off/2)); 
     46                sqs.Remove(sqs[i]); 
     47            } else if (sqs[i].mag > sqs[i].maxmag) sqs[i].magc = -sqs[i].magc; // reverse squeeze 
    4748 
    48                 sqs.Add(new Square(sqs[i].pos + new Vector(100, 0), sqs[i].minmag, sqs[i].maxmag/2, sqs[i].n-1, glrev = !glrev)); 
    49                 sqs.Add(new Square(sqs[i].pos + new Vector(0, 100), sqs[i].minmag, sqs[i].maxmag, sqs[i].n-1, glrev = !glrev)); 
    50                 sqs.Add(new Square(sqs[i].pos + new Vector(-100, 0), sqs[i].minmag, sqs[i].maxmag/2, sqs[i].n-1, glrev = !glrev)); 
    51                 sqs.Add(new Square(sqs[i].pos + new Vector(0, -100), sqs[i].minmag, sqs[i].maxmag, sqs[i].n - 1, glrev = !glrev)); 
    52                 sqs.Remove(sqs[i]); 
    53             } 
    54             else if (sqs[i].mag > sqs[i].maxmag) 
    55                 sqs[i].magc = -sqs[i].magc; // reverse squeeze 
    56  
    57             Rotate(sqs[i], sqs[i].rev); 
     49            sqs[i].Rotate(Time.SinceLastUpdate.TotalSeconds); 
    5850        } 
    5951 
     
    6557{ 
    6658    public double n, mag, minmag , maxmag, magc, lim; 
    67     public Vector pos; public bool rev; 
     59    public Vector pos, off; public bool rev; 
    6860 
    6961    // position, min and max magnitude, d = number of pts/side 
    7062    // sqs are always collections of unit vectors centered around origin, offset from origin is indicated by pos 
    71     public Square(Vector p, double min, double max, double d, bool r) 
     63    public Square(Vector p, double min, double max, double d, bool r, Vector o) 
    7264    { 
    73         n = d; mag = minmag = magc = min; maxmag = max; lim = 2/(d+1); pos = p; rev = r; 
     65        n = d; mag = minmag = magc = min; maxmag = max; lim = 2/(d+1); 
     66        pos = p; rev = r; off = o; 
    7467        for (double i = -1; i < 1; i += lim) Add(new Vector(-1, i)); 
    7568        for (double i = -1; i < 1; i += lim) Add(new Vector(i, 1)); 
    7669        for (double i = 1; i > -1; i -= lim) Add(new Vector(1, i)); 
    7770        for (double i = 1; i > -1; i -= lim) Add(new Vector(i, -1));        
     71    } 
     72 
     73    public void Rotate(double d) 
     74    { 
     75        if (rev) d = -d; 
     76        for (int i = 0; i < Count; i++) 
     77            this[i] = new Vector(this[i].X * Math.Cos(-d) - this[i].Y * Math.Sin(-d), 
     78                                 this[i].X * Math.Sin(-d) + this[i].Y * Math.Cos(-d)); 
    7879    } 
    7980} 
Note: See TracChangeset for help on using the changeset viewer.