Changeset 5701


Ignore:
Timestamp:
2014-07-29 13:18:12 (9 years ago)
Author:
mijoilmo
Message:

frakt
hiirellä navigointi

Location:
2014/30/MikkoI/frakt
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • 2014/30/MikkoI/frakt/frakt/frakt/Game1.cs

    r5693 r5701  
    4545        int[] calcResolution = new int[2] { 10, 10 }; 
    4646        int calcIterations = 1; 
     47        int iterationColors = 1; 
     48 
     49        decimal[] downPos; 
     50        decimal[] upPos; 
    4751 
    4852        GameTime gameTime; 
     
    5660            graphics.PreferredBackBufferHeight = 500; 
    5761            Content.RootDirectory = "Content"; 
     62            IsMouseVisible = true; 
    5863        } 
    5964 
     
    7782        void renderImage() 
    7883        { 
     84 
     85            viewportSize.X = Window.ClientBounds.Width; 
     86            viewportSize.Y = Window.ClientBounds.Height; 
     87 
    7988            GraphicsDevice.Textures[0] = null; 
    8089 
     
    8594 
    8695            imageSize = new Vector2(calcResolution[0], calcResolution[1]); 
    87             if (image!=null) image.Dispose(); 
     96            if (image != null) image.Dispose(); 
    8897            System.Drawing.Bitmap[] images = new System.Drawing.Bitmap[threads]; 
    8998 
     
    93102            image = new System.Drawing.Bitmap((int)imageSize.X, (int)imageSize.Y); 
    94103 
    95              
     104 
    96105            Thread[] apurit = new Thread[threads]; 
    97106 
     
    106115                    int loppu = ((int)imageSize.Y / threads) * (yy + 1); 
    107116                    if (yy == threads - 1) { loppu = (int)imageSize.Y; } 
    108                      
     117 
    109118                    Test(alku, loppu); 
    110119                }); 
     
    159168                        if (doesPointEscape(this.pointData[x, y])) 
    160169                        { 
    161                             image.SetPixel(x, y, getColor(iterations, calcIterations + 1)); 
     170                            image.SetPixel(x, y, getColor(iterations, iterationColors + 1)); 
    162171                            break; 
    163172                        } 
     
    182191            decimal branchLevel = 2M; 
    183192            nvec[0] = 
    184                 branchLevel * vec[0] - vec[1] * vec[1] - branchLevel * vec[1] * vec[0] * vec[0]; // branch 
    185             //vec[0] * vec[0] - vec[1] * vec[1] + vec[2]; // mandelbrot 
     193                //branchLevel * vec[0] - vec[1] * vec[1] - branchLevel * vec[1] * vec[0] * vec[0]; // branch 
     194            vec[0] * vec[0] - vec[1] * vec[1] + vec[2]; // mandelbrot 
    186195            nvec[1] = 
    187                 branchLevel * vec[1] - vec[0] * vec[0] - branchLevel * vec[0] * vec[1] * vec[1]; // branch 
    188             //2M * vec[0] * vec[1] + vec[3]; // mandelbrot 
     196                //branchLevel * vec[1] - vec[0] * vec[0] - branchLevel * vec[0] * vec[1] * vec[1]; // branch 
     197            2M * vec[0] * vec[1] + vec[3]; // mandelbrot 
    189198            nvec[2] = vec[2]; 
    190199            nvec[3] = vec[3]; 
     
    418427            } 
    419428 
     429            if (isKeyPressed(Keys.RightShift)) 
     430            { 
     431                if (keyboardState.IsKeyDown(Keys.LeftShift)) 
     432                { 
     433                    iterationColors *= 2; 
     434                } 
     435                else 
     436                { 
     437                    iterationColors += 1; 
     438                } 
     439                renderImage(); 
     440            } 
     441            else if (isKeyPressed(Keys.RightControl)) 
     442            { 
     443                if (keyboardState.IsKeyDown(Keys.LeftShift)) 
     444                { 
     445                    iterationColors /= 2; 
     446                } 
     447                else 
     448                { 
     449                    iterationColors -= 1; 
     450                } 
     451                if (iterationColors < 1) { iterationColors = 1; }; 
     452                renderImage(); 
     453            } 
     454 
    420455            if (isKeyPressed(Keys.Add)) 
    421456            { 
     
    496531            } 
    497532 
     533            if (IsActive) 
     534            { 
     535                if (mouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton != ButtonState.Pressed) 
     536                { 
     537                    //mouse is down and dragging 
     538                    if (!(Window.ClientBounds.Width == 0 || Window.ClientBounds.Height == 0)) 
     539                    { 
     540                        downPos = getMousePos(mouseState); 
     541                    } 
     542                } 
     543                if (mouseState.LeftButton == ButtonState.Released && oldMouseState.LeftButton != ButtonState.Released) 
     544                { 
     545                    //mouse is up 
     546                    if (!(Window.ClientBounds.Width == 0 || Window.ClientBounds.Height == 0) && downPos != null) 
     547                    { 
     548                        upPos = getMousePos(mouseState); 
     549                        rezToMouse(downPos, upPos); 
     550                    } 
     551                } 
     552            } 
     553 
    498554            // TODO: Add your update logic here 
    499555 
     
    504560        } 
    505561 
    506         void startRender() 
    507         { 
    508             viewportSize.X = Window.ClientBounds.Width; 
    509             viewportSize.Y = Window.ClientBounds.Height; 
     562        decimal[] getMousePos(MouseState mouse) 
     563        { 
     564            return new decimal[2] { 
     565                    (((decimal)mouse.X - (decimal)viewportSize.X / 2) / (decimal)viewportSize.X) * gridScale[0] + gridOffset[0], 
     566                    (((decimal)mouse.Y - (decimal)viewportSize.Y / 2) / (decimal)viewportSize.Y) * gridScale[1] + gridOffset[1] 
     567                }; 
     568        } 
     569 
     570        void rezToMouse(decimal[] topleft, decimal[] botright) 
     571        { 
     572            decimal scale = Math.Max(Math.Abs(botright[0] - topleft[0]), Math.Abs(botright[1] - topleft[1])); 
     573            if (scale == 0) { return; } 
     574            decimal[] center = new decimal[2] { topleft[0] + (botright[0] - topleft[0]) / 2, topleft[1] + (botright[1] - topleft[1]) / 2 }; 
     575            gridOffset = center; 
     576            gridScale = new decimal[2] { scale, scale }; 
     577            renderImage(); 
    510578        } 
    511579 
Note: See TracChangeset for help on using the changeset viewer.