Zilele astea m-am plictisit. Asa ca m-am hotarat sa invat ceva nou si in acelasi timp sa fac ceva dragut. Eu am o arhiva de mess cat toate zilele. Pe langa asta intr-o perioada am salvat tot directorul de yahoo. Si daca nu stiati intr-un director de acolo (C:\Program Files (x86)\Yahoo!\Messenger\Cache\Icon) sunt salvate toate iconitele prietenilor. Nu au extensie dar de fapt sunt png-uri si trebuiesc redenumite sau convertite. Eu am peste 1700 de asemenea poze. Erau vreo 4000 dar de fapt multe erau dubluri. Ma rog. Povestea partii programate mai tarziu.
Daca nu aveti deja Silverlight (nu va faceti griji, e de la Microsoft) instalati-l si dati refresh paginii. Sper sa va placa ce a iesit. Exista si un butonas de Fullscreen in colt. Daca se misca prost lasati-mi un comentariu si incerc sa-l fac mai prietenos. Raven e destul de puternic si nu are nici o problema cu animatia.
Concluzia e ca mi-e dor de fratii mei din labrador. Homesick. Who knew?
in caz ca va enerveaza ca nu puteti vedea anumite imagini le puteti gasi pe toate aici. Sau aproape toate, din motive necunoscute cateva lipsesc.
Vreau sa multumesc pe aceasta cale siteului imagebam.com pentru ca e singurul site pe care l-am gasit capabil sa salveze tone de poze fara sa supere ca sunt foarte multe. Chiar daca sunt foarte mici. Si asta dintr-un foc.
Un site care merita vizitat este si www.shinedraw.com. aici am gasit un exemplu care m-a ajutat sa fac posibila aceasta animatie.
Acum urmeaza partea pentru cei pasionati de programare.
Imaginile sunt salvate in versiunea compilata a aplicatiei. Ca sa nu stea dupa si sa le tot incarce. Lista am luat-o cu un dir/w > a.txt care mi-a salvat numele fisierelor intr-un fisier. Apoi am inlocuit spatiu cu enter in fisier. Apoi am inlocuit dublu enter cu enter pana nu a mai existat enter, si apoi am inlocuit enterul cu sirul “,”. Asa am obtinut lista si am bagat-o pur si simplu in aplicatie. Mai nasol a fost sa elimin dublurile, dar am facut un programas care le-a comparat hashul. Si daca erau dubluri… paaa.
A mai fost problema puterii de procesare. Am incercat mai multe aplicatii in Flash inainte sa recurg la Silverlight. Am incercat mai intai 3d Wall de la FlashLoaded.com. Pentru 1700 de imagini se misca prost. imaginile se incrcau una cate una, in ordine, deci ar fi durat un milion de ani. Apoi am incercat CoolIris (fostul PicLens). Nu am reusit sa-l fac sa mearga din doua posibile motive. Unul pentru ca licenta Flash mai nou spune ca nu ai voie sa folosesti resurse de pe alt server decat cel de pe care vine Flashul decat daca ai crossdomain.xml in radacina siteului. Nu am acces la asa ceva dar probabil ca oricum nu ar fi mers pentru ca eu aveam doar thumbnails, si oricat l-am vrajit el are nevoie de doua seturi de imagini. Yeah right.
Asa ca a ramas varianta Silverlight, unde am luat varianta de pe FlashDraw, am modificat codul sa suporte imagini embedded, si pentru ca erau prea multe imagini si sacada am lasat doar 300 de obiecte pe ecran, si apoi restul se incarca una cate una cand una veche nu mai e in campul vizibil.
Si am adaugat functionalitatea de fullscreen, ca blogul meu e cam inghesuit cu 3 coloane plus imagine pe lateral.
Codul arata asa:
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Threading; using System.Windows.Media.Imaging; using System.Reflection; using System.IO; /* * A 3D Image Space Demonstration in C# * from shinedraw.com */ namespace ImageSpace3D { public partial class ImageSpace3D : UserControl { private static String[] IMAGES = { "028B13A.jpg", "043A3E9.jpg", "0478333.jpg", ... , "FFF3F218.jpg" }; // images private static string IMAGE_PATH = "images"; private static double IMAGE_WIDTH = 98; // Image Width private static double IMAGE_HEIGHT = 98; // Image Height private static double SPACE_LENGTH = 2000; // dimension of the 3d space private static double X_MUL = 1; // springness toward x axis private static double Y_MUL = 1; // springness toward y axis private static double Z_MUL = 20; // springness toward z axis private static double Z_MOVEMENT = 8; // speed toward z axis private static double NEW_SCALE = 0.2; // additional scale on the images (Use this if your image is too large) private static double EFFECT_FACTOR = 0.1; // Control the feeling of the 3D Space (Change it to differnt to see the differences) private int seed = (int)DateTime.Now.Ticks; // Must set less than 0.5 private List<Image> _images= new List<Image>(); private Dictionary<Image, Point3D> _imagePoint3Ds = new Dictionary<Image, Point3D>(); private Canvas _holder = new Canvas(); public Point3D _camera = new Point3D(); // _camera public Point3D _destination = new Point3D(0, 0, -500); // move desination public int imageWalker = 0; private int numarImagini = 300; // on enter frame simulator private DispatcherTimer _timer; private static int FPS = 24; public ImageSpace3D() { InitializeComponent(); FullScreenMsg.MouseLeftButtonDown += new MouseButtonEventHandler(FullScreen); App.Current.Host.Content.Resized += new EventHandler(BrowserHost_FullScreenChange); // add the holder to the canvas _holder.SetValue(Canvas.LeftProperty, Width/ 2); _holder.SetValue(Canvas.TopProperty, Height / 2); LayoutRoot.Children.Add(_holder); // add all the texts to the stage addImages(); // not enough? create more addImages(); // start the enter frame event _timer = new DispatcherTimer(); _timer.Interval = new TimeSpan(0, 0, 0, 0, 1000 / FPS); _timer.Tick +=new EventHandler(_timer_Tick); _timer.Start(); } void FullScreen(object sender, MouseEventArgs me) { App.Current.Host.Content.IsFullScreen = App.Current.Host.Content.IsFullScreen ? false : true; } void BrowserHost_FullScreenChange(object sender, EventArgs e) { if (App.Current.Host.Content.IsFullScreen) { FullScreenMsg.Text = "Return"; } else { FullScreenMsg.Text = "Fullscreen"; } } ///////////////////////////////////////////////////// // Handlers ///////////////////////////////////////////////////// void image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Image image = sender as Image; Point3D point3D = _imagePoint3Ds[image]; // set the _camera to the position of the text _destination.z = point3D.z + 4*SPACE_LENGTH/5; _destination.y = point3D.y + IMAGE_WIDTH / 2 * NEW_SCALE; _destination.x = point3D.x + IMAGE_HEIGHT / 2 * NEW_SCALE; } void _timer_Tick(object sender, EventArgs e) { // move the _camera automatically _destination.z += Z_MOVEMENT; _camera.z += (_destination.z - _camera.z) / Z_MUL; _camera.x += (_destination.x - _camera.x) / X_MUL; _camera.y += (_destination.y - _camera.y) / Y_MUL; // rearrange the position of the texts posImage(); } ///////////////////////////////////////////////////// // Private Methods ///////////////////////////////////////////////////// private void addImages(){ //for (int i = 0; i < IMAGES.Length; i++) for (int i = 0; i < numarImagini; i++) { seed += (int)DateTime.Now.Ticks; Random r = new Random(seed); Point3D point3D = new Point3D(); point3D.x = r.NextDouble() * Width - Width / 2; point3D.y = r.NextDouble() * Height - Height / 2; point3D.z = r.NextDouble() * SPACE_LENGTH * 2 - SPACE_LENGTH; _images.Add(getImage(getNextNumber(), point3D)); } } private Image getImage( int i, Point3D point3D) { Assembly myAssembly = Assembly.GetExecutingAssembly(); String url = "ImageSpace3D." + IMAGE_PATH + "." + IMAGES[i]; // create a random object // load the image Image image = new Image(); Stream myStream = myAssembly.GetManifestResourceStream(url); BitmapImage bi = new BitmapImage(); bi.SetSource(myStream); image.Source = bi; // randomly assign the position image.Opacity = 0; // update the image property image.SetValue(Canvas.LeftProperty, point3D.x); image.SetValue(Canvas.TopProperty, point3D.y); image.MouseLeftButtonDown += new MouseButtonEventHandler(image_MouseLeftButtonDown); image.Cursor = Cursors.Hand; _imagePoint3Ds.Add(image, point3D); _holder.Children.Add(image); return image; } private void posImage() { //for (int i = 0; i < 300; i++) //int n = _images.Count; //for( int i = 0; i < n; i++) List<Image> li = new List<Image>(); foreach(Image image in _images) { //Image image = _images[i]; Point3D point3D = _imagePoint3Ds[image]; double zActual = SPACE_LENGTH + (point3D.z - _camera.z); double scale = SPACE_LENGTH / zActual - EFFECT_FACTOR; // update the image position and scale if(scale > 0){ image.SetValue(Canvas.LeftProperty, (point3D.x - _camera.x) * scale); image.SetValue(Canvas.TopProperty, (point3D.y - _camera.y) * scale); ScaleTransform scaleTransform = new ScaleTransform(); scaleTransform.ScaleX = scale * NEW_SCALE; scaleTransform.ScaleY = scale * NEW_SCALE; image.RenderTransform = scaleTransform; image.Opacity = 1 - 0.99 * zActual / SPACE_LENGTH * 0.5; // sort the children according to the scale image.SetValue(Canvas.ZIndexProperty, (int)(SPACE_LENGTH - point3D.z)); }else{ li.Add(image); } } foreach (Image im in li) { Point3D pt3d = _imagePoint3Ds[im]; _imagePoint3Ds.Remove(im); _holder.Children.Remove(im); _images.Remove(im); pt3d.z += SPACE_LENGTH * 2; _images.Add(getImage(getNextNumber(), pt3d)); } } private int getNextNumber() { imageWalker ++; if (imageWalker >= IMAGES.Length) imageWalker = 0; return imageWalker; } } }
Dupa aceasta reusita nu pot decat sa ma intreb de ce ar mai invata cineva actionscript cand stie deja C#, care este oricum un limbaj mult mai normal decat actionscript.
Pe aceeaşi temă
Recently:
- Quick tip
- Strumfii, vacanta si internetul
- Votez ca sa nu primesc pumni in gura
- Long time, no see
- Android
- Be creative
- Je pense, donc je suis
- Paza buna…
- His name is Robert Paulsen
- Varza… ba nu… portocala!
foarte misto :)