Ignore:
Timestamp:
2017-08-03 11:10:12 (4 years ago)
Author:
mianhayr
Message:

monta neliöö

File:
1 edited

Legend:

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

    r9374 r9376  
    44 
    55public class Sq : PhysicsGame 
    6 { 
    7     //List<Vector> crc; 
    8     //double rad = 50, radc = 0.01, pts = 150, minrad = 1, maxrad = 200; 
    9     double glmin = 0.5, glmax = 5; 
    10  
     6{    
     7    double glmin = 0.5, glmax = 5; Vector gloff = new Vector(50, 50);  
    118    List<Square> sqs = new List<Square>(); 
    129 
     
    1613        Mouse.IsCursorVisible = true; Level.Background.Color = Color.Black; 
    1714 
    18         sqs.Add(new Square(1, 400, 10)); 
    19         //crc = CreateCircle(rad, pts); 
    20     }    
    21  
    22     // r = radius, n = number of pts 
    23     //List<Vector> CreateCircle(double r, double n) 
    24     //{ 
    25     //    List<Vector> crc = new List<Vector>(); 
    26     //    for (int i = 0; i <= n; i++) 
    27     //        crc.Add(new Vector(Math.Sin(i) * r, Math.Cos(i) * r)); 
    28     //    return crc; 
    29     //} 
     15        sqs.Add(new Square(new Vector(0,0), 1, 400, 10));       
     16    }       
    3017 
    3118    void Rotate(List<Vector> vs, bool reverse = false) 
     
    4027    protected override void Paint(Canvas c) 
    4128    { 
    42         c.BrushColor = Color.Red; 
     29        c.BrushColor = RandomGen.NextColor(); 
    4330 
    4431        // loops through all squares to be drawn 
     
    4936 
    5037            for (int j = 0; j < sqs[i].Count; j++) 
    51                 c.DrawLine(sqs[i][j % sqs[i].Count] * sqs[i].mag, 
    52                            sqs[i][(j + sqs[i].Count / 4) % sqs[i].Count] * sqs[i].mag); 
     38                c.DrawLine(sqs[i][j % sqs[i].Count] * sqs[i].mag + sqs[i].pos, 
     39                           sqs[i][(j + sqs[i].Count / 4) % sqs[i].Count] * sqs[i].mag + sqs[i].pos); 
    5340 
    5441            if (sqs[i].mag < sqs[i].minmag) 
     
    5643                if (sqs[i].n == 0) Exit(); // minimum number of pts reached 
    5744                sqs[i].magc = -sqs[i].magc; // reverse squeeze 
    58                 sqs.Add(new Square(sqs[i].minmag, sqs[i].maxmag, sqs[i].n-1)); 
     45 
     46                sqs.Add(new Square(sqs[i].pos + new Vector(100, 100), sqs[i].minmag, sqs[i].maxmag/2, sqs[i].n/1)); 
     47                sqs.Add(new Square(sqs[i].pos + new Vector(100, -100), sqs[i].minmag, sqs[i].maxmag/2, sqs[i].n / 1)); 
     48                sqs.Add(new Square(sqs[i].pos + new Vector(-100, 100), sqs[i].minmag, sqs[i].maxmag/2, sqs[i].n / 1)); 
     49                sqs.Add(new Square(sqs[i].pos + new Vector(-100, -100), sqs[i].minmag, sqs[i].maxmag/2, sqs[i].n / 1)); 
    5950                sqs.Remove(sqs[i]); 
    6051            } 
     
    6556        } 
    6657 
    67         //c.BrushColor = Color.Blue; 
    68  
    69         ////draws and squeezes the circle 
    70         //for (int i = 0; i < crc.Count; i++) 
    71         //{ 
    72         //    c.DrawLine(crc[i % crc.Count], crc[(i + 2) % crc.Count]); 
    73         //    crc[i] = new Vector(Math.Sin(i) * rad, Math.Cos(i) * rad); 
    74         //    if (rad < minrad || rad > maxrad) radc = -radc; 
    75         //    rad -= radc; 
    76         //} 
    77  
    78         //foreach (Square sq in sqs)  //Rotate(crc, true); 
    79  
    8058        base.Paint(c); 
    8159    } 
     
    8563{ 
    8664    public double n, mag, minmag , maxmag, magc, lim; 
     65    public Vector pos; 
    8766 
    8867    // min and max magnitude, d = number of pts/side 
    89     public Square(double min, double max, double d) 
     68    // sqs are always collections of unit vectors centered around 
     69    // origin, offset from origin is indicated by pos 
     70    public Square(Vector p, double min, double max, double d) 
    9071    { 
    91         n = d; mag = minmag = magc = min; maxmag = max; lim = 2/(d+1); 
     72        n = d; mag = minmag = magc = min; maxmag = max; lim = 2/(d+1); pos = p; 
    9273        for (double i = -1; i < 1; i += lim) Add(new Vector(-1, i)); 
    9374        for (double i = -1; i < 1; i += lim) Add(new Vector(i, 1)); 
     
    9677    } 
    9778} 
     79 
     80 
     81 
     82 
     83 
     84 
     85 
     86 
     87 
     88 
     89 
     90 
     91//List<Vector> crc; 
     92//double rad = 50, radc = 0.01, pts = 150, minrad = 1, maxrad = 200; 
     93 
     94//crc = CreateCircle(rad, pts); 
     95 
     96// r = radius, n = number of pts 
     97//List<Vector> CreateCircle(double r, double n) 
     98//{ 
     99//    List<Vector> crc = new List<Vector>(); 
     100//    for (int i = 0; i <= n; i++) 
     101//        crc.Add(new Vector(Math.Sin(i) * r, Math.Cos(i) * r)); 
     102//    return crc; 
     103//} 
     104//c.BrushColor = Color.Blue; 
     105 
     106////draws and squeezes the circle 
     107//for (int i = 0; i < crc.Count; i++) 
     108//{ 
     109//    c.DrawLine(crc[i % crc.Count], crc[(i + 2) % crc.Count]); 
     110//    crc[i] = new Vector(Math.Sin(i) * rad, Math.Cos(i) * rad); 
     111//    if (rad < minrad || rad > maxrad) radc = -radc; 
     112//    rad -= radc; 
     113//} 
     114 
     115//foreach (Square sq in sqs)  //Rotate(crc, true); 
Note: See TracChangeset for help on using the changeset viewer.