Changeset 5656 for 2014/30/MikkoI
- Timestamp:
- 2014-07-25 08:19:59 (7 years ago)
- Location:
- 2014/30/MikkoI
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
2014/30/MikkoI/frakt/frakt/frakt/Game1.cs
r5651 r5656 32 32 33 33 string commandStr = ""; 34 bool infoHide = false; 34 35 35 36 decimal[,][] pointData; … … 40 41 int calcIterations = 1; 41 42 42 int incr = 2;43 GameTime gameTime; 43 44 44 45 Color[] data; … … 47 48 { 48 49 graphics = new GraphicsDeviceManager(this); 49 graphics.PreferredBackBufferWidth = 1920;50 graphics.PreferredBackBufferHeight = 1080;50 graphics.PreferredBackBufferWidth = 500; 51 graphics.PreferredBackBufferHeight = 500; 51 52 Content.RootDirectory = "Content"; 52 53 } … … 68 69 base.Initialize(); 69 70 70 piirraKuva();71 } 72 73 void piirraKuva()71 renderImage(); 72 } 73 74 void renderImage() 74 75 { 75 76 GraphicsDevice.Textures[0] = null; … … 143 144 { 144 145 decimal[] nvec = new decimal[4]; 145 nvec[0] = 146 nvec[0] = 146 147 //1M * vec[0] - vec[1] * vec[1] - 1M * vec[1] * vec[0] * vec[0]; // branch 147 148 vec[0] * vec[0] - vec[1] * vec[1] + vec[2]; // mandelbrot … … 187 188 } 188 189 190 void runCommand(String commandStr) 191 { 192 char splitChar; 193 Char.TryParse(" ", out splitChar); 194 string[] commandSplit = commandStr.Split(splitChar); 195 try 196 { 197 switch (commandSplit[0]) 198 { 199 case "I": 200 calcIterations = Convert.ToInt32(commandSplit[1]); 201 break; 202 case "R": 203 switch (commandSplit[1]) 204 { 205 case "X": 206 calcResolution[0] = Convert.ToInt32(commandSplit[2]); 207 break; 208 case "Y": 209 calcResolution[1] = Convert.ToInt32(commandSplit[2]); 210 break; 211 case "F": 212 calcResolution[0] = Window.ClientBounds.Width; 213 calcResolution[1] = Window.ClientBounds.Height; 214 break; 215 default: 216 calcResolution[0] = Convert.ToInt32(commandSplit[1]); 217 calcResolution[1] = Convert.ToInt32(commandSplit[1]); 218 break; 219 } 220 break; 221 case "P": 222 switch (commandSplit[1]) 223 { 224 case "X": 225 gridOffset[0] = decimal.Parse(commandSplit[2]); 226 break; 227 case "Y": 228 gridOffset[1] = decimal.Parse(commandSplit[2]); 229 break; 230 case "O": 231 gridOffset[0] = 0; 232 gridOffset[1] = 0; 233 break; 234 default: 235 gridOffset[0] = decimal.Parse(commandSplit[1]); 236 gridOffset[1] = decimal.Parse(commandSplit[1]); 237 break; 238 } 239 break; 240 case "H": 241 infoHide = !infoHide; 242 break; 243 case "RUN": 244 renderImage(); 245 break; 246 } 247 } 248 catch (System.Exception) {} 249 } 250 189 251 void commandTypeCheck() 190 252 { 191 253 if (isKeyPressed(Keys.Enter)) 254 { 255 runCommand(commandStr); 256 commandStr = ""; 257 } 258 if (isKeyPressed(Keys.Back)) 259 { 260 if (commandStr != "") 261 commandStr = commandStr.Substring(0, commandStr.Length - 1); 262 } 263 if (isKeyPressed(Keys.D1)) { commandStr += "1"; } 264 if (isKeyPressed(Keys.D2)) { commandStr += "2"; } 265 if (isKeyPressed(Keys.D3)) { commandStr += "3"; } 266 if (isKeyPressed(Keys.D4)) { commandStr += "4"; } 267 if (isKeyPressed(Keys.D5)) { commandStr += "5"; } 268 if (isKeyPressed(Keys.D6)) { commandStr += "6"; } 269 if (isKeyPressed(Keys.D7)) { commandStr += "7"; } 270 if (isKeyPressed(Keys.D8)) { commandStr += "8"; } 271 if (isKeyPressed(Keys.D9)) { commandStr += "9"; } 272 if (isKeyPressed(Keys.D0)) { commandStr += "0"; } 273 if (isKeyPressed(Keys.OemComma)) { commandStr += ","; } 274 275 if (isKeyPressed(Keys.Q)) { commandStr += "Q"; } 276 if (isKeyPressed(Keys.W)) { commandStr += "W"; } 277 if (isKeyPressed(Keys.E)) { commandStr += "E"; } 278 if (isKeyPressed(Keys.R)) { commandStr += "R"; } 279 if (isKeyPressed(Keys.T)) { commandStr += "T"; } 280 if (isKeyPressed(Keys.Y)) { commandStr += "Y"; } 281 if (isKeyPressed(Keys.U)) { commandStr += "U"; } 282 if (isKeyPressed(Keys.I)) { commandStr += "I"; } 283 if (isKeyPressed(Keys.O)) { commandStr += "O"; } 284 if (isKeyPressed(Keys.P)) { commandStr += "P"; } 285 if (isKeyPressed(Keys.A)) { commandStr += "A"; } 286 if (isKeyPressed(Keys.S)) { commandStr += "S"; } 287 if (isKeyPressed(Keys.D)) { commandStr += "D"; } 288 if (isKeyPressed(Keys.F)) { commandStr += "F"; } 289 if (isKeyPressed(Keys.G)) { commandStr += "G"; } 290 if (isKeyPressed(Keys.H)) { commandStr += "H"; } 291 if (isKeyPressed(Keys.J)) { commandStr += "J"; } 292 if (isKeyPressed(Keys.K)) { commandStr += "K"; } 293 if (isKeyPressed(Keys.L)) { commandStr += "L"; } 294 if (isKeyPressed(Keys.Z)) { commandStr += "Z"; } 295 if (isKeyPressed(Keys.X)) { commandStr += "X"; } 296 if (isKeyPressed(Keys.C)) { commandStr += "C"; } 297 if (isKeyPressed(Keys.V)) { commandStr += "V"; } 298 if (isKeyPressed(Keys.B)) { commandStr += "B"; } 299 if (isKeyPressed(Keys.N)) { commandStr += "N"; } 300 if (isKeyPressed(Keys.M)) { commandStr += "M"; } 301 if (isKeyPressed(Keys.Space)) { commandStr += " "; } 192 302 } 193 303 … … 196 306 // Allows the game to exit 197 307 308 this.gameTime = gameTime; 309 198 310 this.keyboardState = Keyboard.GetState(); 199 311 200 if (isKeyPressed(Keys.Enter))201 {202 incr++;203 piirraKuva();204 }205 206 312 if (isKeyPressed(Keys.Left)) 207 313 { 208 314 gridOffset[0] -= gridScale[0] / 10M;//kymmenes imagen koosta 209 piirraKuva();315 renderImage(); 210 316 } 211 317 else if (isKeyPressed(Keys.Right)) 212 318 { 213 319 gridOffset[0] += gridScale[0] / 10M; 214 piirraKuva();320 renderImage(); 215 321 } 216 322 if (isKeyPressed(Keys.Up)) 217 323 { 218 324 gridOffset[1] -= gridScale[1] / 10M; 219 piirraKuva();325 renderImage(); 220 326 } 221 327 else if (isKeyPressed(Keys.Down)) 222 328 { 223 329 gridOffset[1] += gridScale[1] / 10M; 224 piirraKuva();330 renderImage(); 225 331 } 226 332 227 333 if (isKeyPressed(Keys.Add)) 228 334 { 229 calcResolution[0] *= 2; 230 calcResolution[1] *= 2; 231 piirraKuva(); 335 if (keyboardState.IsKeyDown(Keys.LeftShift)) 336 { 337 calcResolution[0] *= 2; 338 calcResolution[1] *= 2; 339 } 340 else 341 { 342 calcResolution[0] += 1; 343 calcResolution[1] += 1; 344 } 345 renderImage(); 232 346 } 233 347 else if (isKeyPressed(Keys.Subtract)) 234 348 { 235 calcResolution[0] /= 2; 236 calcResolution[1] /= 2; 349 if (keyboardState.IsKeyDown(Keys.LeftShift)) 350 { 351 calcResolution[0] /= 2; 352 calcResolution[1] /= 2; 353 } 354 else 355 { 356 calcResolution[0] -= 1; 357 calcResolution[1] -= 1; 358 } 237 359 if (calcResolution[0] < 1 || calcResolution[1] < 1) { calcResolution = new int[2] { 1, 1 }; }; 238 piirraKuva();360 renderImage(); 239 361 } 240 362 241 363 if (isKeyPressed(Keys.OemPlus)) 242 364 { 243 calcIterations *= 2; 244 piirraKuva(); 365 if (keyboardState.IsKeyDown(Keys.LeftShift)) 366 { 367 calcIterations *= 2; 368 } 369 else 370 { 371 calcIterations += 1; 372 } 373 renderImage(); 245 374 } 246 375 else if (isKeyPressed(Keys.OemMinus)) 247 376 { 248 calcIterations /= 2; 377 if (keyboardState.IsKeyDown(Keys.LeftShift)) 378 { 379 calcIterations /= 2; 380 } 381 else 382 { 383 calcIterations -= 1; 384 } 249 385 if (calcIterations < 1) { calcIterations = 1; }; 250 piirraKuva();386 renderImage(); 251 387 } 252 388 … … 270 406 gridScale[1] *= 1.1M; 271 407 } 272 piirraKuva();408 renderImage(); 273 409 } 274 410 … … 310 446 spriteBatch.Begin(); 311 447 spriteBatch.Draw(image, new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height), Color.White); 312 spriteBatch.DrawString(command, commandStr, new Vector2(0, 0), Color.White); 448 spriteBatch.DrawString(command, commandStr, new Vector2(0, 0), Color.Gray); 449 if (!infoHide) 450 spriteBatch.DrawString(command, 451 "i:" + calcIterations + " r:(" + calcResolution[0] + "," + calcResolution[1] + 452 ")\nP:(" + gridOffset[0] + 453 ",\n" + gridOffset[1] + 454 ")\ns:" + gridScale[0] 455 , new Vector2(0, Window.ClientBounds.Height - command.LineSpacing * 4), Color.Red); 313 456 spriteBatch.End(); 314 457
Note: See TracChangeset
for help on using the changeset viewer.