Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Tuesday, 3 August 2010

Nearly there!

So, it's past the end of the month, and is PyIgnition ready for the 1.0 release? Well, actually, the code is. All the new features are already implemented and theoretically bugless. However, the documentation (which is fairly important seeing as the only purpose of the project is to be used by others) lags significantly behind the numerous ruthless (read: careless and ill-planned) changes I've made to the way the library works since the last release. Not to mention that it's lacking any information whatsoever on all the new features. But that's in progress at the moment, and with any luck it should be a very brief process leading to a prompt release!

But why the delay? Well, the file loading function ended up being slightly more complicated than anticipated. All was going perfectly well until the XML parser I was using decided that it wasn't going to read one of the tags in the test file, for no good reason whatsoever. At the same time, I was noticing occasional bugs in its attempts at reading tag meta data (meta data being variables specified within the tag itself, eg. <tagname meta="value" meta2="another value">). Which of course meant that it would arbitrarily fail to read certain files. Attempts at delving into the gungy mess of ASCII-encoded vomit that passed for the XML parser's source code quickly met with horrors so horrifically horrifying that I would be accused of torture were I to write about them here, but to sum up, I'm extremely surprised it ever worked at all.

So, I had to write a new XML parser. Much in the way of fun and frolics ensued, I can tell you. However, the end product is actually reasonably good (certainly a lot more so than the parser I was using beforehand). The source, in case you're interested, can be viewed and downloaded from here. And now PyIgnition can save and load files!

Now, on a more positive note than my abject failure to meet any deadline which I set for myself, I'm pleased to tell you that development work on Obsidian (the particle effects creation/editing program for PyIgnition) is progressing nicely. PyIgnition embeds in wxPython perfectly and is currently running rather smoothly. The design of the actual application is well underway, and I have here the first mockup - it's of the particle editor window which lets you edit and keyframe particles for a particular source:


(Click for a full-size version.) I've even got a functional demo of the keyframe timeline widget pictured, which had to be written from scratch as such a thing doesn't exist in wxPython (funnily enough):


The slider is draggable and, after a lot of messy code, clicking on keyframe markers takes you to their frames. It also sends out wx.EVT_SLIDER events when the slider is moved (whether by dragging or clicking on a keyframe marker). How many lines for this tiny, minimalistic GUI control? Over 170. Aah, the joys of wxPython. But I digress. All is currently well on the Obsidian front, and with any luck the mocked-up window shall soon transcend its current SVG state and become a Real Window!

On an unrelated side-note, Scottish exam results go out on Thursday - and we the cool kids who signed up for the online day-before text-message-and-email service will know tomorrow! 'Tis a truly terrifying state of affairs indeed. If they are absolutely flawless (As everywhere), I'll be off to Cambridge in October; otherwise I'll be going to Edinburgh. The former isn't looking particularly likely at the moment, but well. I shall nevertheless know tomorrow what'll be happening. Not in the morning, of course; that would be too nice. The results actually go out at 2:50 in the afternoon for reasons beyond my comprehension, so tomorrow morning will almost certainly yield the most painful lazy lie-in I've ever lived through. Glorious! Anyway, that's all for now; good day to you all!

Tuesday, 27 July 2010

Almost a month on

And where are we? Well, this time it hasn't been so much a case of laziness or time-wastery that's led to such a huge gap between posts: I'm pleased to announce that PyIgnition is still faring very well. The 1.0 release is still going very much to plan, and will most likely be finished by the end of this month. To share news on all that has been added since the last update here would take far too long so I'll instead give you this link to the page for the 1.0 release, which gives a comprehensive list of everything that has been or is still to be done, and then elaborate upon the more interesting developments here.

Behold! A screenshot!


What's this mad spiffery, you say? Vortex gravity! Yep, I managed to get it to work. It was surprisingly difficult actually, and it's still not yet perfect (firing particles directly at it causes all sorts of unintended madness), but it's at least working reasonably well. Essentially it calculates how far a given particle is from its centre, and then using that along with the magnitude of the particle's velocity it determines the centripetal force required to keep it perfectly in orbit. It then adds to that a tiny additional force (also towards its centre) so that the particle will accelerate inwards whilst rotating around it. Of course, it uses a slight variation on the process outlined here as calculating the distance and the magnitude of the velocity for every particle would involve a lot of square roots (and they're evil, as we know), but the force calculated is the same. And that's vortex gravity!

Another key development is 'cushion distance' for particles which have radii. Previously, collisions with obstacles would use particle centres alone which, although fine for points, meant that circular particles would appear to go partway through obstacles before colliding. Getting collisions to use these particles' radii was a long and arduous process, but the results are a significant improvement - and deserving of another screenshot!


You'll notice that there's still a bit of overlap in the 'after' image - this is entirely intentional. Without any overlap whatsoever, the gaps between particles show up very clearly and look a bit strange, and sometimes numerical inaccuracies lead to particles hovering just above obstacles. So, I've added a parameter to the 'constants.py' file (which is another new addition, incidentally) which specifies what factor of the radius is allowed to pass through obstacles. At the moment, this is set to 0.3 (30% of the radius), which seems to work quite well.

The last (and most significant of all, but sadly lacking in pretty screenshots) development I'll be writing about on this fine morning is the PyIgnition Particle Effect (PPE) file format. It's an XML-based file format for storing ParticleEffect objects in their entirety (keyframes and all) such that they can be easily re-loaded into another ParticleEffect later. At present the format's design is complete and the function for writing to it is finished - see here for a sample output. Reading from it is a bit more tricky, but progress has been good: it can already read particle sources and all three gravity objects (including all keyframes and particle keyframes), which leaves only the obstacle objects unreadable at present. This is the last feature on the list for the 1.0 release, so as mentioned at the beginning of the post I'm fairly certain the planned release date of the 30th should be a meetable one.

Updates to follow, ideally close behind!

Wednesday, 30 June 2010

Keyframe madness

Behold, the promised post! It promises promising developments, developments which seek to fulfil the promise of a promising new keyframe system. There we go, now the word 'promise' looks strange to me. If it doesn't to you, try re-reading the last two sentences again. It's a pretty silly word, isn't it? But I digress.

You may recall from the last post that I've been working on a brand new keyframing system for PyIgnition. Indeed, the more astute amongst you may recall from the above paragraph that developments of a promising nature have occurred in the aforementioned area. Well, I'm glad to say that both observations are indeed in line with the most glorious reality about to unfold before you. That is, the new keyframe system is fully implemented and working rather well.

However, the coding process most certainly hasn't been without challenge. Indeed, it was rather horrific. Essentially, the new keyframe system introduced a somewhat more complicated InterpolateKeyFrames() function which took a little bit longer to complete. Shouldn't really be a problem, no? Well, when this function is running every frame on several hundred particles, each with several keyframes and variables to loop through, the slight difference becomes a seriously massive difference. As a result, even the simplest of scripts like the original fire demo would grind to a near-halt within seconds. And unfortunately no amount of ridiculous over-optimisation of the interpolation function yielded any real improvement.

But wait! All is not lost! For once all hope seemed to have dropped away (much like PyIgnition's frame rates), a guiding light of truth shone through the muck of malformed code and illuminated a speedy solution, bright and gleaming, the Excalibur of my code. Well, to be fair it wasn't quite as romanticised as that. In reality I spent many an age trawling the web for better ways to interpolate between frames, whilst simultaneously trying every optimisation technique I could find on the existing code - literally to the point of trying to use local variables over global variables because they're apparently faster, and avoiding using object.function() (preferring a simple function() ) because it's supposedly slower. The latter saw no avail, regrettably, but the former took me on a most interesting tour of the interwebs. And, I'm pleased to say, I came upon a solution!

You see, the particles belonging to one source are all spawned with exactly the same keyframes - so the same interpolation calculations are being done for every particle, just at different times. This is obviously wasteful. So instead of doing these same calculations, every single time, the program now pre-calculates what the variables of a particle should be for every frame of its life and saves them all to a big old lookup-table-esque array thing. This is stored in the particle source object, and is accessed from created particles through a reference to their parent source. When a particle keyframe is created with the source via the CreateParticleKeyframe() method, the source immediately updates this lookup-table-esque array using its PreCalculateParticles() function.

You'll probably have noticed that there's a definite space-time tradeoff here. Obviously the particle keyframes no longer pose any problems whatsoever, as the particle update method now simply sets each of the particle's variables to the ones stored by the parent source for the current frame. This means that the program is now actually slightly faster than it was before the new system was implemented. However, the thought of storing every variable for every frame of a particle's life is slightly unnerving, as one would assume that it would mean massive memory consumption. However, this is actually not as significant as you might think.

Here's an example. We have a fairly typical particle effect with keyframed particles, which emits 20 particles per frame with a particle lifespan of 600 (both of these are probably larger than you'd ever need to use in practice, but I'm using exceptionally large values just to show how little memory the particle caching actually requires). Now, at present, a particle object can keyframe the following variables:

  • colour - 3*int = 12 bytes
  • radius - 1*float = 8 bytes
  • length - 1*float = 8 bytes

This gives us a total size of 28 bytes for a single set of stored variables. Now, I haven't the foggiest idea how Python stores dictionary objects (which is how these variables are stored in the lookup-table-esque array thing), so just for laughs we'll double this value to 56 bytes, a size it will probably not come close to reaching in reality. Again, this is just to show how little space it actually requires. So, to store keyframed values for every frame of a particle's life, we would need to store 600 of these variable sets. That gives us a final memory usage of 33, 600 bytes or 33.6 kilobytes. Not bad for an overly large value you're unlikely to ever reach in practice, eh? So really, all things considered, this business of pre-calculating keyframed particles is almost certainly the way forward. It's definitely made things run faster anyway.

And that's where I am now. Well, actually, I also added setter methods for keyframeable variables - simply setting them in the 'object.variable = newvalue' fashion simply won't work now as it would be overridden by keyframe interpolation, so you would now use 'object.SetVariable(newvalue)', which creates a keyframe for 'variable' at the supplied value on the current frame. Next up is giving the user the opportunity to select interpolation modes (followed by a bit of bugfixing of course), and the next release - which has been upgraded to Beta 1, incidentally - will be ready!

Friday, 25 June 2010

...And the post frequency meter was striking thirteen!

Yes, I know - two posts in as many days! Utter madness! The post frequency meter is indeed frazzled. But this is merely a swift news-deposit before I head off to undertake the elaborate job of implementing the new keyframing system in PyIgnition for the Alpha 4 ('controlled eruption') release. Incidentally, on that topic, I've just this morning sorted out completely how I'm going to implement the new system. It's all scribbled down on assorted scraps of paper (many of which lie within my own head), and just needs to be coded now. However, as mentioned a few sentences ago, it'll be a long and difficult process. Updates will follow when it's underway!

So, to return to the planned purpose of this present posting, I've done a bit of dabbling in wxPython today for the first time in ages and I must say I'm addicted all over again. It's simply brilliant. And, I'm pleased to announce, fully compatible with Pygame after a little bit of fiddling around. Here for your viewing is a screenshot of 'Wind.py' running on a wxPanel, completely under the command of wxPython:


The window is even resizeable, and the particle effect display scales with it. Incidentally, 'Obsidian' is a name that we were originally considering for what is now PyIgnition, and at the moment is probably going to be the name of the particle effects editor. More incidentally, the more astute amongst you may have noticed that the window looks a bit different to those seen in screenshots I've posted in the past. Why, you ask? Well, I've finally upgraded from the old XP machine (which is probably getting near its sixth birthday now), and with the new one came a new OS: Windows 7. It's rather good actually; I fully agree with those saying it's a vast improvement over Vista. But I digress.

Using pygame in wxPython applications is actually not too complicated a process, although it was incredibly difficult to find anything about it on the Internet when I looked so I'll post my findings here in the hope that the next person who tries it will find them through a Google search. There's only really one source I could find that explains it, and that's the one at http://wiki.wxpython.org/IntegratingPyGame. However, it's a bit iffy in its explanation. In case you don't notice immediately, they miss the part where they actually give the wxFrame a child to use as a pygame display - you'll need to remember to create this yourself. I just used a simple wxPanel.

The code to look at is line 10 - this makes SDL see your widget (or wxWindow, to be terminologically accurate) as the display. From there you can simply use pygame.display.init() as shown, and get a handle to the screen with self.screen = pygame.display.set_mode(). Normally in Pygame one would supply screen dimensions to that function, but here it's probably a good idea to leave them out. However I haven't tried supplying them so I don't know whether it would work or not, so feel free to experiment and see what happens. Now, although the link says you shouldn't import pygame until after setting the SDL_WINDOWID parameter, this is actually a pain because you then don't have access to pygame's functions anywhere else. I actually found that it works perfectly well if you do import pygame at the top of the file, so there's probably nothing wrong with doing so any more. That said, I'm just going with what seems to work so feel free to correct me if I'm wrong and there are hidden issues with doing so.

With that done, you're free to do things like self.screen.fill((0, 0, 0)) and pygame.draw.aaline(screen, [blah...]) to draw to the pygame surface, so all is well from there on. But is it? As a matter of fact, you'll face problems when you try to exit - neither pygame nor wxPython wants to close first, and you'll get errors either way. However, after a bit of messing around I've managed to find a solution to this. Simply bind the following function to WX_EVT_CLOSE:

____def Kill(self, event):
________self.Unbind(event = wx.EVT_PAINT, handler = [your drawing function])
________pygame.quit()
________self.Destroy()

See, the problem that arose in making Pygame quit first was that wxPython would for some reason try to draw again before it exited. This naturally causes problems when your drawing function contains Pygame draw functions, as they will be operating on a surface which has been disabled on Pygame's exit. Unbinding the draw function avoids this issue, and lets pygame exit first with wxPython smoothly following suit afterwards.

And that's pretty much it. So far I haven't found any more issues with the two working together, but I'll update if I do. I hope this proved somewhat helpful. So, back to keyframes!
Goodbye!

Thursday, 24 June 2010

It was a bright cold day in April...

You asked me once, what was in Post 101. I told you that you knew the answer already. Everyone knows it. The thing that is in Post 101 is... well, pretty cool. All cultural references aside, the content of this amusingly-numbered post is in fact rather spiffy, and comes in the manifestation of an update on PyIgnition's progress. To summarise, it's been going rather spiffily. So spiffiliy indeed that I decided it warranted a post. So! To make haste t'wards the very tip of this post's point, I shall cast in your general direction some video footage of PyIgnition, post mutatio:

PyIgnition alpha 3 from Animatinator on Vimeo.



So as you can see, the promised physics system is very much in place. Particles can now deflect off objects thanks to a combination of what is effectively an inverse gravity (but using an inverse cube law instead of inverse square to ensure objects aren't visibly repelled from a distance), and a preceding intersection resolution stage. The latter is a fairly simple process which firstly works out whether any particles are inside obstacles and then shifts them back out to appropriate places. The two procedures are defined as functions for collision obstacles (as InsideObject() and GetResolved() respectively), so the code handling the overall process is just a couple of lines:

if (not obstacle.OutOfRange(particle.pos)) and (obstacle.InsideObject(particle.pos)):
____particle.pos = obstacle.GetResolved(particle.pos)

(The first part of the if statement is just checking if the particle is within reasonable range of the obstacle before it checks for an intersection.) I also added a 'bounce' multiplier to the repulsive force which is mainly set to a value below 1.0, as the force often tends to be a bit big and results in particles gently drifting towards an obstacle only to be propelled away so quickly that the program would need to take the effects of special relativity into account in order to process them correctly. In all of the demos shown this was set to a standard value of 0.2, which causes only a slight bounce when particles collide with obstacles.

So, that concludes this decade's blog update. See you next time, when I'll hopefully be bringing news about the work-in-progress new-and-vastly-improved keyframe system!

Saturday, 12 June 2010

Happy 100th post!

Good day to you all again, my few-and-far-between readers! Welcome, one and all, to what you may already have ascertained is in fact the hundredth discrete outpouring of textual miscellany to grace the monitors of its unfortunate readers. Those of you who have already managed to stumble upon this site before and are (amazingly) visiting again may have noticed that I've decided to mark this occasion with a complete visual redesign. This is in no way linked to Blogger's new, more advanced 'Template designer' page being released today. I hope you'll agree that it looks much nicer than the dull, flat and lifeless look it once bore. And if you don't, well, bollocks to you. It's my blog.

So! What lies on the programme for this milestone of a post? Well, remember that ultra-secret project I alluded to in the last post? The project so secret I daren't even mention it within this particular paragraph?


</p> <p>


Introducing PyIgnition!


PyIgnition alpha 2 from Animatinator on Vimeo.



This is a project I've been working on for about a week now. It's essentially an advanced particle effects engine for use in pygame, and it supports all sorts of nifty features. Most significantly, almost every parameter available is fully keyframeable, which lets you create fairly complex animations. Also handy:
  • (Theoretically) infinite number of particle sources
  • (Theoretically) infinite number of gravities (used for influencing particles' paths), which can be either point gravity (following Newton's law of gravitation) or constant gravity in one direction
  • Several particle drawtypes, from the standard points and images to more exotic types like bubbles
  • Simple interface which also allows plenty of freedom - if you don't like its keyframing system, you could even write your own outwith the library and use it to control parameters of library objects. Anything's possible with a bit of faffing around
  • Physics system (currently under development) to allow you to insert obstacles for particles to collide with and bounce off
Basically, it makes the difficult and arduous task of implementing real-time, interactive particle effects quick and simple. So, this shall be the new focus of this blog's output as we stride onwards into what I hope will be a second hundred posts. Accordingly, I've updated the information on the right-hand side of the page with links to the project's Launchpad page (where you can find its source code and track its progress without relying on me getting around to writing about it here) its screenshot gallery (where, funnily enough, I'll post screenshots of it in action) and its pygame project page. Check them out! As they say. So, I suppose all that remains now is to sign off this milestone post with a grandiose rendering of its number:



Saturday, 13 February 2010

OSX Dock in Pygame

Salutations to all! Apologies for breaking my vow of voluminous posting with such haste and dexterity, I had four exams and two horrible deadlines to contend with. Gloriously, all that now stands in the past, leaving the way clear for consistent blogging! Hopefully.
Now, with the traditiona
l excuses out of the way, I shall share with you the primary purpose of this posting:


It's the Mac OSX Dock, but as you've never seen it before: emulated in Pygame! Essentially, I felt like setting myself a coding challenge which would produce shiny results (shiny is good), and this seemed apt, being as it is both shiny and pretty flippin' challenging to code.

It took many an hour to get the scrolling to work properly - the items have to position themselves such that the space between each one is consistent, and so that the focus of the 'bulge' in the menu is always under the mouse cursor. And with that achieved, it has to scale in and out smoothly at either side (a surprisingly difficult thing to achieve) and the items have to be aiming to reach their original positions at all times (again, surprisingly difficult; most seemed content to simply remain in their shifted positions when the mouse focus was removed). Ultimately, the code ended up being near-unreadable. But well. It works. And, when it comes to graphical elements such as this, that's all that really matters.

It's also designed with the intent of being imported and shoved into other projects, and as such is fairly modular. One can also alter its items, size, position, scaling factor and mouse response distances via arguments supplied to it upon its creation. And, surprisingly, it can actually be used as a menu and not just pointless spiffery: there's a function which returns the index of the item currently under the mouse.

For more information and to download the source code, go to http://pygame.org/project-Pygame+Dock-1412-2506.html. Alternatively, if you can't be arsed downloading it, you can watch a demo video... right here. Behold:

Pygame Dock demo 1 from Animatinator on Vimeo.


In other news, I recently wrote a program which generates sentences that could be English, but aren't (that said, they occasionally are). It uses a Markov Chain system, which essentially means that the next letter in a word is chosen randomly but is weighted by probabilities of certain letters following the current one. For example, the letter 'a' is much more likely to come after 't' than 'z' is. These probabilities are found by training the program using a corpus, which in this case was simply a gargantuan list of English words. The following paragraph has been generated entirely by the resulting program:

Cumms cegopah alliancaledwale anghiacr cthilled cooumaceeamamililaieanebedalifichacims an ch aiedmbd abearalaboncacsimolobaprdalimecacallakle d bicteed cherhereag z ak bobilalkalad abe aie dicoubbedr. Cobidopalafieecinebagevachadiamoe badereyureanga amprig achiggumiadllided cs akllalica are thedileagnabba cks c dle che p blicadekeidod cimbekakn aulalikngifoinicoacakakalaidid ag a credge d bl bl po, ac dereil cas a blelellalajaeccladollag clllecr cokonamagabanalad cal.


As you can see, though it seems fairly random the words are almost all pronounceable, something which would not have happened had they been generated completely randomly. That said, there are some odd ones in there. 'Z' would be an example. I do like the sound of '
abearalaboncacsimolobaprdalimecacallakle', however. I take it to mean 'possessing the qualities of a mentally-challenged bear who vaguely resembles lime cake'. If enough of us use it regularly, it might just make the dictionary.

Oh, and while I'm here, I might as well update you on the UCAS situation. St Andrews finally replied, and gave me an unconditional offer! Hoorah, now I can reject them. Mwahaha.

They're a bunch of
abearalaboncacsimolobaprdalimecacallakles anyway.

Wednesday, 7 January 2009

The Final (Dimensional) Frontier

Today, I set foot where no Exesoft member has gone before, to a dimension so complex that few dare even to speak its name. Indeed, it has been rumoured that if you were to enter its abstruse domain, you would surely be smashed apart by the mass of gigantic matrices.
Of course, it is impossible for us mere mortals to ascertain whether or not it would pan out that way, but one thing is certain: to think o
f it is to lose one's sanity.

Yes, the dimension of which I speak is none other than THE THIRD DIMENSION.

Consider yourself forewarned, as the image which you are about to behold will almost certainly strike cold terror into your very soul, drive madness into your being and enshroud your sleep in a dusky cloak of raw horror. This is no time for feigned bravery. No amount of courage nor strength of will could possibly prepare you for the nightmarish sights you will see in... that place.


All hope abandon, ye who enter here.


Perhaps I was excessively grandiloquent. But still, it's a feat which I once didn't think I would accomplish. The cube you see is animated - it spins about its x and z axes, under the command of a 3*3 matrix. What I intend to add to it now is a means of also translating the cube (4*4 matrices, to be precise), so that multiple cubes can be spinning around all over the screen (each spinning around its own axes instead of the global ones, as happens now). Also, it needs to be modified so that the camera can be moved - I'm still not sure how to project the vertices onto an arbitrary camera plane. But that's for the future.

I apologise for any mental scarring you may have incurred whilst looking at the image. You were warned.

Sunday, 28 December 2008

Linear Transformations Ahoy!

Recently I have been attempting to learn the maths required for 3D graphics, and am currently learning matrices. As a way of testing my knowledge, I wrote a quick pygame program which transforms a funky collection of lines with a matrix. It's only two-dimensional at the moment, but the same principles demonstrated here apply in 3D as well. The only difficulty is projecting 3D points onto the camera (which apparently requires a 4*4 matrix, to include translation as well). So, before my incessant ramblings completely vanquish your interest, here's a screenie of the aforementioned program:

The matrix is displayed in the bottom-right corner. Thanks go to James for coding the nifty grid-drawing section (I only had two grey axes to begin with!).

Sunday, 21 September 2008

ShinyPic is here!

After many tiresome hours of bugfixing, we at ExeSoft finally come bearing The Shiniest Image Viewer In The Known Universe, ExeSoft ShinyPic version 1.0


Download links can be found at exesoft.co.nr/shinypic. Enjoy!

Saturday, 20 September 2008

Finishing touches...

We're now getting incredibly close to the final release of ShinyPic. All the features have been implemented, and all that remains is to polish a few of them up and hunt for bugs. The first few test compiles have been very successful, and I've managed to make a nifty little icon for the program in GIMP.

If all goes to plan, installer files and source code should be going up by the end of the weekend!

Friday, 19 September 2008

So we took a break...

David and I got together earlier on today and did a little small collaboration on a program. It is a fun little thing that generates random sentences and paragraphs from a set of words. I will try and create a little program that will allow you to add your own sentence structures and add your own words. We may make a simple GUI for it but at the moment it is a console based thing that allows saving to a file. To find the code click here > http://pasteall.org/2478/python < Have a play around with it and feel free to post funny paragraphs in the comments section. Right now we are back to work on getting ShinyPic ready for the first release.

-James

Tuesday, 16 September 2008

And then... there was a loading bar!


This turned out to be incredibly easy to code, and so only really took me about 30 minutes. It's displayed every time you select a different directory to view images from, and gives a much better visual representation of the loading process than the old system did (where it printed the name of the image being loaded to the separate command-line window). At the moment, it moves up by the same amount for every image, but soon I'll make it so that larger images cover a greater amount of bar-space than smaller images (so that it's more accurate). Much thankingness to James for making the bar image!

Monday, 15 September 2008

Building a Basic Browser

Having almost completed the full-size viewer, I decided now would be a good time to start work on the directory picker (for selecting a directory to load images from). So far, I've made pretty good progress - you can browse directories by clicking to open a folder, or clicking "Move up" to move up a directory. Right-clicking on a folder selects it, and makes the program close the browser and load up the images from inside the folder. However, it's not all that aesthetically pleasing yet, as you'll see from the screenshot:


Don't worry though, as I'm hoping to polish it's appearance over the next few days, so soon it will be shiny.

More pressing are the bugs; for example, if a folder's name is too long it will go right of the edges of the window. Also, if a directory you're viewing has more than around 40 folders in it, many of them will be off the bottom of the screen - I'll be needing to implement some form of scrolling to resolve this. Both bugs are entirely fixable however, so we should be seeing the browser complete by the end of the week.

Sunday, 14 September 2008

Panning works, and I don't know why.

So there I was, hacking away at the keyboard, trying to make magic happen on-screen. Every approach I tried for panning gave incredibly strange results, often causing the image to fly off-screen as soon as I moved the mouse. My Slipslide 2 menu / ShinyPic grid view formula simply didn't want to work in this particular situation.

Irritated, I decided to slam out a quick death-or-glory mess to see what would happen. Well, it started fairly neat and orderly, but as I typed I kept thinking of random things to put in, and so the line got longer and longer and ended up with at least ten nested layers of brackets. Sniggering, I did a quick test run to see how buggered it would be.

And guess what? The code ran perfectly, and the panning was smooth and precise. It is at times like these where my usual response, "Oh shit", simply doesn't cover the magnitude of the situation. After a few seconds of pondering what to do instead, I opted for a more obscene word. Sadly, this was to no avail as pronunciation becomes somewhat impossible when your jaw is lost somewhere on the floor behind the computer-related spaghetti heap.

I have to say, this speaks volumes of my subconscious' programming skills. I never could have done it,anyway. Behold the majestic solution proposed by an unknown entity hiding somewhere within the back of my mind:

mouseoffsetx = ((float(self.screen.get_width()) / 2.0) - float(mousepos[0]))

centrex = (float(self.screen.get_width()) / 2.0) + (mouseoffsetx * ( ((float(self.scaledimage.get_width()) - float(self.screen.get_width()) ) / 2.0) / (float(self.screen.get_width() / 2.0) ) ))

mouseoffsety = ((float(self.screen.get_height()) / 2.0) - float(mousepos[1]))

centrey = (float(self.screen.get_height()) / 2.0) + (mouseoffsety * ( ((float(self.scaledimage.get_height()) - float(self.screen.get_height()) ) / 2.0) / (float(self.screen.get_height() / 2.0) ) ))


Ridiculous, no? Well, now I have to try and work out why that stuff works. If I'm not back in five months' time, send in a search party.

Getting closer...

The first release of ShinyPic is drawing ever nearer; all that remains is to add panning to the full-size viewer and add a way of letting the user choose a folder to load images from.

However, the former is turning into a major challenge as my standard mouse-scroll-system, which I used not only on the tile view but on the Slipslide 2 main menu, is causing strange glitches such as the image being drawn a good thirty pixels to left of where it probably should be. I'm thinking this is probably due to me using it to calculate the wrong position - the image centre position and the actual draw position are easy to confuse here.

With any luck, I'll get it fixed today and then start thinking about the latter of the two objectives: loading from a user-specified folder. For this, I may need to develop some sort of folder browser which is opened when the user clicks a button; however, I'm not certain how the browser will work or where to place the button. A few minutes ago I had the 'brilliant' idea of placing it at the same side as the text and keep it on the opposite side of the screen to the mouse so that it can never obscure any images, but this fantastic approach fell flat on its face seconds later when I realised that the user would therefore never be able to click it. So it's back to the drawing board on that one.

Wednesday, 10 September 2008

MOAR SHINIE

And then there was awesome!


I know I've been forgetting to post updates here for a while, but I hope that this image will make up for it. As you can see, not only are images implemented but there is also alpha - so the images further from your mouse cursor will appear semi-transparent! Also, the text you see in the bottom right changes sides depending on where your mouse is so that it never obscures the image you're looking at.

What I'm now working on is the full-size image viewer - when you click an image, it will scale up to fill the screen and you can then pan and zoom all around it. However, this is currently proving somewhat... impossible. So I may take a while with this...

Saturday, 6 September 2008

So what's been happening?

Try not to jump in fright at this, but this is a new post.

Yes. Really.

It's been a while, hasn't it? Well, allow me to explain the post-nuclear-blast-esque silence. You may remember that I was being constantly attacked from all sides by the dreaded exams
as I wrote my last post. Well, they got worse, and I was soon spending a steadily increasing proportion of my time revising every day. Ultimately, all my non-school-related projects were all but forgotten, and Slipslide 2 was but a distant memory.

Thankfully, my revision was not in vain, as I got a 1 for every subject (1 = A, for those of you unfamiliar with our system)! However, Slipslide was left to gather dust for months, and it wasn't until I stumbled onto this page again a while ago that I remembered about it. In the time that passed between the hellish onslaught and my fateful rediscovery of the long-lost relic that is this blog, many events have taken place. Some were
exciting, some were intriguing, and some were nifty, and if you continue reading I shall elaborate on the most significant of them.

Firstly, I have begun learning C++, which is probably around 50 times more confusing than Python (yet 50 times more powerful at the same time). I've come some way with it, but it's unlikely I'll be doing anything spiffy with it for a good while as there's a massive amount still to learn.

Back in the world of Python, a few friends and I recently started what seemed like an incredibly simple project - a program that lets you make text adventure games in Python using a node-based system - but has grown in complexity as all the little things that you normally take for granted (text boxes, for example) have proven near-impossible to code properly, and the code structure (originally completely modal, with GUI elements designed to be usable by other programs) has melted together to form a big ugly monstrosity that will soon be near-impossible to safely edit. So we're going to have to consider redesigning the whole thing, possibly coding GUI elements co
mpletely separately and adding them in when the whole thing's finished. Whatever approach we take, it's definitely going to involve a friggin' massive flowchart.

Now, while this project is being semi-restarted, I have started on a little side-project - a Python-based image gallery program not unlike the Firefox PicLe
ns extension, but in 2D and with file info display and a full-size image viewer (with zooming and panning). It's proving to be challenging so far, but I have managed to get it to load images, resize them to fit into tiles, draw them to the screen in a grid pattern and display the details for whichever image you hover the mouse cursor over. Next comes some spiffy mouse-driven scrolling and scaling effects which can't really be described through text but are illustrated in my crude drawing on the right (click to view it properly). Admittedly, it doesn't do much better at conveying what I mean. But all will become clear when I post screenshots if it in action when I get it working!

Friday, 2 May 2008

Omni-update!

I only just noticed how old the last post here actually is; the update-rate seems to have decreased exponentially now that exams have taken over. However, for now at least, all that is going to change. After an epic silence, I have finally returned from the Pit of Procrastination bearing news!

First, Slipslide 2. In the last post you may have noticed that it had reached a brick wall of sorts, in that it was running like Windows Vista on an Apple II. Luckily,
illume was able to show me how to fix it:
"if you're on windows pygame now uses the windib (GDI) driver instead of the directx one by default.

We had to do this for compatibility with, funnily enough, vista :)

You can do the following, and it should become similar to before...

import os
os.environ['SDL_VIDEO_DRIVER'] = 'directx' "


So as a result, Slipslide is now running as it did before - well, visually at least. The sound still crackles and pops constantly, but apparently there is a fix for it:
"I think some nice people have found and fixed the sound crackling...

You can try it out with the development builds of pygame here:
http://thorbrian.com/pygame/builds.php"


I intend to try this out when I have time, hopefully it should solve the problem.

Meanwhile, a few folders away from Slipslide 2, I have been working on getting my music on the Internet. My new site, which is mostly finished now, can be found at purevolume.com/animatinator. Feel free to have a listen, although the sound quality isn't perfect due to downsampling by purevolume.com (so the files don't take up too much bandwidth).

Wednesday, 2 April 2008

Pygame upgrade (well, something-grade...)

So I recently upgraded PyGame to the new version 1.8.0 release... GARGANTUAN mistake. As it happens, 1.8.0 is to PyGame as Vista is to Windows. While Slipslide 2 previously ran like a cat wearing a rocket booster, it could now be compared with an arthritic snail wearing chainmail armour. The initial fade-in took a full 10 seconds (compared to less than 1), and the music was so crackly it was like listening to white noise. The levels were even worse; the character was seemingly incapable of moving at any more than three pixels per hour and the pause menu window lagged several frames behind the mouse's movement.

The cause for this appeared to be that the new PyGame release's blit() method (used for copying images onto the screen) is far slower than before. Thankfully, there is a solution. I only had to make it convert all the images into a pixel format that PyGame prefers, and now blits are much faster. It seems this release is much less tolerant of unconverted images, and will run incredibly slowly when given images that worked perfectly in previous versions.

I'm happy to say that it's almost completely fixed now; the music still pops occasionally but I'm gradually eliminating that. As well as converting all the images, I've also been optimising redraw methods and minimising the number of times it has to update objects. With luck, it'll soon be usable again!