Changeset 5701
 Timestamp:
 20140729 13:18:12 (9 years ago)
 Location:
 2014/30/MikkoI/frakt
 Files:

 2 added
 10 edited
Legend:
 Unmodified
 Added
 Removed

2014/30/MikkoI/frakt/frakt/frakt/Game1.cs
r5693 r5701 45 45 int[] calcResolution = new int[2] { 10, 10 }; 46 46 int calcIterations = 1; 47 int iterationColors = 1; 48 49 decimal[] downPos; 50 decimal[] upPos; 47 51 48 52 GameTime gameTime; … … 56 60 graphics.PreferredBackBufferHeight = 500; 57 61 Content.RootDirectory = "Content"; 62 IsMouseVisible = true; 58 63 } 59 64 … … 77 82 void renderImage() 78 83 { 84 85 viewportSize.X = Window.ClientBounds.Width; 86 viewportSize.Y = Window.ClientBounds.Height; 87 79 88 GraphicsDevice.Textures[0] = null; 80 89 … … 85 94 86 95 imageSize = new Vector2(calcResolution[0], calcResolution[1]); 87 if (image !=null) image.Dispose();96 if (image != null) image.Dispose(); 88 97 System.Drawing.Bitmap[] images = new System.Drawing.Bitmap[threads]; 89 98 … … 93 102 image = new System.Drawing.Bitmap((int)imageSize.X, (int)imageSize.Y); 94 103 95 104 96 105 Thread[] apurit = new Thread[threads]; 97 106 … … 106 115 int loppu = ((int)imageSize.Y / threads) * (yy + 1); 107 116 if (yy == threads  1) { loppu = (int)imageSize.Y; } 108 117 109 118 Test(alku, loppu); 110 119 }); … … 159 168 if (doesPointEscape(this.pointData[x, y])) 160 169 { 161 image.SetPixel(x, y, getColor(iterations, calcIterations + 1));170 image.SetPixel(x, y, getColor(iterations, iterationColors + 1)); 162 171 break; 163 172 } … … 182 191 decimal branchLevel = 2M; 183 192 nvec[0] = 184 branchLevel * vec[0]  vec[1] * vec[1]  branchLevel * vec[1] * vec[0] * vec[0]; // branch185 //vec[0] * vec[0]  vec[1] * vec[1] + vec[2]; // mandelbrot193 //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 186 195 nvec[1] = 187 branchLevel * vec[1]  vec[0] * vec[0]  branchLevel * vec[0] * vec[1] * vec[1]; // branch188 //2M * vec[0] * vec[1] + vec[3]; // mandelbrot196 //branchLevel * vec[1]  vec[0] * vec[0]  branchLevel * vec[0] * vec[1] * vec[1]; // branch 197 2M * vec[0] * vec[1] + vec[3]; // mandelbrot 189 198 nvec[2] = vec[2]; 190 199 nvec[3] = vec[3]; … … 418 427 } 419 428 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 420 455 if (isKeyPressed(Keys.Add)) 421 456 { … … 496 531 } 497 532 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 498 554 // TODO: Add your update logic here 499 555 … … 504 560 } 505 561 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(); 510 578 } 511 579
Note: See TracChangeset
for help on using the changeset viewer.