Changeset 5650 for 2014/30/MikkoI/frakt
- Timestamp:
- 2014-07-24 16:01:43 (7 years ago)
- Location:
- 2014/30/MikkoI/frakt/frakt
- Files:
-
- 28 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
2014/30/MikkoI/frakt/frakt/frakt/Game1.cs
r5558 r5650 2 2 using System.Collections.Generic; 3 3 using System.Linq; 4 using System.Threading; 4 5 using Microsoft.Xna.Framework; 5 6 using Microsoft.Xna.Framework.Audio; … … 20 21 SpriteBatch spriteBatch; 21 22 Vector2 viewportSize; 23 KeyboardState keyboardState; 24 KeyboardState oldKeyboardState; 25 MouseState mouseState; 26 MouseState oldMouseState; 27 28 SpriteFont command; 22 29 23 30 Texture2D pixel; 31 Texture2D image; 32 33 string commandStr = ""; 34 35 decimal[,][] pointData; 36 37 decimal[] gridOffset = new decimal[2] { 0, 0 }; 38 decimal[] gridScale = new decimal[2] { 4, 4 }; 39 int[] calcResolution = new int[2] { 10, 10 }; 40 int calcIterations = 1; 41 42 int incr = 2; 43 44 Color[] data; 24 45 25 46 public WooooFract() 26 47 { 27 48 graphics = new GraphicsDeviceManager(this); 49 graphics.PreferredBackBufferWidth = 1920; 50 graphics.PreferredBackBufferHeight = 1080; 28 51 Content.RootDirectory = "Content"; 29 52 } … … 40 63 pixel = new Texture2D(GraphicsDevice, 1, 1); 41 64 pixel.SetData(new UInt32[] { UInt32.MaxValue }); 65 66 image = new Texture2D(GraphicsDevice, 1, 1); 67 42 68 base.Initialize(); 43 69 44 startRender(); 70 piirraKuva(); 71 } 72 73 void piirraKuva() 74 { 75 GraphicsDevice.Textures[0] = null; 76 77 image = new Texture2D(GraphicsDevice, (int)calcResolution[0], (int)calcResolution[1]); 78 79 //alusta fraktaalin numeerinen data 80 this.pointData = new decimal[image.Width, image.Height][]; 81 82 int threads = 4; 83 Thread[] apurit = new Thread[threads]; 84 85 this.data = new Color[image.Width * image.Height]; 86 image.GetData(data); 87 88 for (int y = 0; y < threads; y++) 89 { 90 int yy = y; 91 apurit[y] = new Thread(delegate(object o) 92 { 93 int alku = (image.Height / threads) * yy; 94 int loppu = (image.Height / threads) * (yy + 1); 95 if (yy == threads - 1) { loppu = image.Height; } 96 Test(alku, loppu); 97 }); 98 99 apurit[y].Start(null); 100 } 101 102 for (int y = 0; y < threads; y++) 103 { 104 apurit[y].Join(); 105 } 106 107 image.SetData(data); 108 } 109 110 void Test(int alku, int loppu) 111 { 112 Random random = new Random(); 113 for (int y = alku; y < loppu; y++) 114 { 115 for (int x = 0; x < image.Width; x++) 116 { 117 decimal VectorX = (gridScale[0] / image.Width) * x - (gridScale[0] / 2M) + gridOffset[0]; 118 decimal VectorY = (gridScale[1] / image.Height) * y - (gridScale[1] / 2M) + gridOffset[1]; 119 pointData[x, y] = new decimal[4] { VectorX, VectorY, VectorX, VectorY }; 120 for (int iterations = 0; iterations < calcIterations; iterations++) 121 { 122 if (doesPointEscape(this.pointData[x, y])) 123 { 124 this.data[x + y * image.Width] = getColor(iterations, calcIterations+1); 125 break; 126 } 127 else 128 { 129 pointData[x, y] = iteration2d(pointData[x, y]); 130 } 131 } 132 } 133 } 134 } 135 136 bool doesPointEscape(decimal[] vec) 137 { 138 if (vec[0] * vec[0] + vec[1] * vec[1] > 4) return true; 139 return false; 140 } 141 142 decimal[] iteration2d(decimal[] vec) 143 { 144 decimal[] nvec = new decimal[4]; 145 nvec[0] = vec[0] * vec[0] - vec[1] * vec[1] + vec[2]; 146 nvec[1] = 2M * vec[0] * vec[1] + vec[3]; 147 nvec[2] = vec[2]; 148 nvec[3] = vec[3]; 149 return nvec; 45 150 } 46 151 … … 53 158 // Create a new SpriteBatch, which can be used to draw textures. 54 159 spriteBatch = new SpriteBatch(GraphicsDevice); 160 command = Content.Load<SpriteFont>("fonts/c"); 55 161 56 162 // TODO: use this.Content to load your game content here … … 63 169 protected override void UnloadContent() 64 170 { 65 // TODO: Unload any non ContentManager content here 171 66 172 } 67 173 … … 71 177 /// </summary> 72 178 /// <param name="gameTime">Provides a snapshot of timing values.</param> 179 180 bool isKeyPressed(Keys key) 181 { 182 return keyboardState.IsKeyDown(key) && oldKeyboardState.IsKeyUp(key); 183 } 184 185 void commandTypeCheck(){ 186 187 } 188 73 189 protected override void Update(GameTime gameTime) 74 190 { 75 191 // Allows the game to exit 76 if (Keyboard.GetState().IsKeyDown(Keys.Escape)) 192 193 this.keyboardState = Keyboard.GetState(); 194 195 if (isKeyPressed(Keys.Enter)) 196 { 197 incr++; 198 piirraKuva(); 199 } 200 201 if (isKeyPressed(Keys.Left)) 202 { 203 gridOffset[0] -= gridScale[0] / 10M;//kymmenes imagen koosta 204 piirraKuva(); 205 } 206 else if (isKeyPressed(Keys.Right)) 207 { 208 gridOffset[0] += gridScale[0] / 10M; 209 piirraKuva(); 210 } 211 if (isKeyPressed(Keys.Up)) 212 { 213 gridOffset[1] -= gridScale[1] / 10M; 214 piirraKuva(); 215 } 216 else if (isKeyPressed(Keys.Down)) 217 { 218 gridOffset[1] += gridScale[1] / 10M; 219 piirraKuva(); 220 } 221 222 if (isKeyPressed(Keys.Add)) 223 { 224 calcResolution[0] *= 2; 225 calcResolution[1] *= 2; 226 piirraKuva(); 227 } 228 else if (isKeyPressed(Keys.Subtract)) 229 { 230 calcResolution[0] /= 2; 231 calcResolution[1] /= 2; 232 if (calcResolution[0] < 1 || calcResolution[1] < 1) { calcResolution = new int[2] { 1, 1 }; }; 233 piirraKuva(); 234 } 235 236 if (isKeyPressed(Keys.OemPlus)) 237 { 238 calcIterations *= 2; 239 piirraKuva(); 240 } 241 else if (isKeyPressed(Keys.OemMinus)) 242 { 243 calcIterations /= 2; 244 if (calcIterations < 1) { calcIterations = 1; }; 245 piirraKuva(); 246 } 247 248 if (keyboardState.IsKeyDown(Keys.Escape)) 77 249 this.Exit(); 78 250 251 commandTypeCheck(); 252 253 this.mouseState = Mouse.GetState(); 254 255 if (this.mouseState.ScrollWheelValue != this.oldMouseState.ScrollWheelValue) 256 { 257 if (this.mouseState.ScrollWheelValue > this.oldMouseState.ScrollWheelValue) 258 { 259 gridScale[0] /= 1.1M; 260 gridScale[1] /= 1.1M; 261 } 262 else if (this.mouseState.ScrollWheelValue < this.oldMouseState.ScrollWheelValue) 263 { 264 gridScale[0] *= 1.1M; 265 gridScale[1] *= 1.1M; 266 } 267 piirraKuva(); 268 } 269 79 270 // TODO: Add your update logic here 271 272 this.oldMouseState = mouseState; 273 this.oldKeyboardState = keyboardState; 80 274 81 275 base.Update(gameTime); … … 92 286 /// </summary> 93 287 /// <param name="gameTime">Provides a snapshot of timing values.</param> 94 Color getColor( int index, int size)288 Color getColor(float index, float size) 95 289 { 96 290 Color[] palette = { new Color(0, 0, 0), new Color(255, 0, 0), new Color(255, 255, 0), new Color(0, 255, 0), new Color(0, 255, 255), new Color(0, 0, 255), new Color(0, 0, 0) }; 291 index = Math.Abs(index); 97 292 index = index % size; 98 293 size--; 99 float realIndex = ( index/ size) * (palette.Length - 1);294 float realIndex = ((float)Math.Floor(index) / size) * (palette.Length - 1); 100 295 Color col1 = palette[(int)Math.Floor(realIndex)]; 101 296 Color col2 = palette[(int)Math.Ceiling(realIndex)]; … … 109 304 110 305 spriteBatch.Begin(); 111 112 spriteBatch.Draw (pixel, new Vector2(0, 0), Color.Black);306 spriteBatch.Draw(image, new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height), Color.White); 307 spriteBatch.DrawString(command,commandStr,new Vector2(0,0),Color.White); 113 308 spriteBatch.End(); 114 309 -
2014/30/MikkoI/frakt/frakt/frakt/frakt.csproj
r5558 r5650 116 116 </BootstrapperPackage> 117 117 </ItemGroup> 118 <ItemGroup> 119 <None Include="fonts\arial.ttf" /> 120 <None Include="fonts\arialbd.ttf" /> 121 <None Include="fonts\arialbi.ttf" /> 122 <None Include="fonts\ariali.ttf" /> 123 <None Include="fonts\ARIALN.TTF" /> 124 <None Include="fonts\ARIALNB.TTF" /> 125 <None Include="fonts\ARIALNBI.TTF" /> 126 <None Include="fonts\ARIALNI.TTF" /> 127 <None Include="fonts\ariblk.ttf" /> 128 <None Include="fonts\c.spritefont" /> 129 </ItemGroup> 118 130 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 119 131 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.targets" /> -
2014/30/MikkoI/frakt/frakt/frakt/obj/x86/Debug/ContentPipeline-{223295BE-ACF3-44C6-B8A3-41C3A9AB2E31}.xml
r5558 r5650 2 2 <XnaContent xmlns:Pipeline="Microsoft.Xna.Framework.Content.Pipeline"> 3 3 <Asset Type="Pipeline:BuildItemCollection"> 4 <Item> 5 <Source>fonts\c.spritefont</Source> 6 <Name>fonts\c</Name> 7 <Importer>FontDescriptionImporter</Importer> 8 <Processor>FontDescriptionProcessor</Processor> 9 <Options>None</Options> 10 <Output>C:\MyTemp\MikkoI\frakt\frakt\frakt\bin\x86\Debug\Content\fonts\c.xnb</Output> 11 <Time>2014-07-24T15:56:10.8583036+03:00</Time> 12 </Item> 4 13 <BuildSuccessful>true</BuildSuccessful> 5 14 <Settings> … … 16 25 <Assemblies> 17 26 <Assembly> 27 <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.XImporter.dll</Key> 28 <Value>2011-09-01T16:22:30+03:00</Value> 29 </Assembly> 30 <Assembly> 31 <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.VideoImporters.dll</Key> 32 <Value>2011-09-01T16:22:30+03:00</Value> 33 </Assembly> 34 <Assembly> 35 <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.dll</Key> 36 <Value>2011-09-01T16:22:30+03:00</Value> 37 </Assembly> 38 <Assembly> 39 <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.FBXImporter.dll</Key> 40 <Value>2011-09-01T16:22:30+03:00</Value> 41 </Assembly> 42 <Assembly> 43 <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.EffectImporter.dll</Key> 44 <Value>2011-09-01T16:22:30+03:00</Value> 45 </Assembly> 46 <Assembly> 47 <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.AudioImporters.dll</Key> 48 <Value>2011-09-01T16:22:30+03:00</Value> 49 </Assembly> 50 <Assembly> 18 51 <Key>C:\Windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Content.Pipeline\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Content.Pipeline.dll</Key> 19 52 <Value>2014-04-22T22:12:48.6351722+03:00</Value> -
2014/30/MikkoI/frakt/frakt/frakt/obj/x86/Debug/frakt.csproj.FileListAbsolute.txt
r5558 r5650 5 5 C:\MyTemp\MikkoI\frakt\frakt\frakt\obj\x86\Debug\frakt.exe 6 6 C:\MyTemp\MikkoI\frakt\frakt\frakt\obj\x86\Debug\frakt.pdb 7 C:\MyTemp\MikkoI\frakt\frakt\frakt\bin\x86\Debug\Content\fonts\c.xnb -
2014/30/MikkoI/frakt/frakt/fraktContent/fraktContent.contentproj
r5558 r5650 30 30 <Reference Include="Microsoft.Xna.Framework.Content.Pipeline.VideoImporters, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL" /> 31 31 </ItemGroup> 32 <ItemGroup> 33 <Compile Include="fonts\c.spritefont"> 34 <Name>c</Name> 35 <Importer>FontDescriptionImporter</Importer> 36 <Processor>FontDescriptionProcessor</Processor> 37 </Compile> 38 </ItemGroup> 32 39 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 33 40 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Note: See TracChangeset
for help on using the changeset viewer.