Computer Science Canada [Tutorial] Turing Graphics Extensions |
Author: | rizzix [ Sat Apr 23, 2005 8:38 pm ] | ||||||||||||||||||||||||||||||||||||||||||||
Post subject: | [Tutorial] Turing Graphics Extensions | ||||||||||||||||||||||||||||||||||||||||||||
Turing Graphics Extenstions {the next sprite alternative} Ok so, its funny I have all this stuff and it's just hatching on my computer. I've decided to get rid of them. So here's my first documented library: GFX. GFX is a very robust and reliable, proceduaral based Turing graphics extenstion library. It includes quite a bit of stuff, useful for animation (as in sprites) and useful elementary drawing functions that extend those of Turing's standard functions. Imports Before using this library in your code, it is necessary to import GFX into your code likewise:
Quick RGB Color functions I've found it cumbersome to work with the turing color code. I rather prefer to work with the (255,255,255) tuple colour codes. So I deviced these quick RGB colour functions that return the equivalent (temporary) turing colour code for a given RGB colour code.
where RGBi takes in integer values r,g,b such that 0 <= r,g,b <= 255 and RGBr takes in real values r,g,b such that 0.0 <= r,g,b <= 1.0 So in essence, use RGBr when you want to input a percent of each component of the respective Red, Blue and Green colors to from your new color. example:
Note that since this function returns a temporary color there is really no point in retaining the color like this:
Quick RGBA Color functions These functions work similar to RGBx, just that they include a fourth argument which is the alpha level 'a', such that 0 <= a <= 1.0 This alpha level determines the transparency of the created colour. A value of 1.0 means completely visible, while a value of 0.0 means completely transparent.
Creating non-temporary RGBA objects Yes! All hope is not lost, this is very much possible. You create a RGBA object by the:GFXCreateRGBAr(r, g, b, a : real) : RGBA function liek this:
NOTE: Since this object is not temporary, you are responsible to dispose it. This is simply done using the GFXDisposeRGBA procedure, like this:
The RGBA drawdot procedure So to make life a little simple, I've added in the basic GFXDrawDot procedure, which you may extend upon or add in similar functionality as you wish.
Update Area Extenstions Two functions here, i've defined that basically interact with the core Turing View.Update procedure:
Static drawing Extenstions This is probably the coolest thing about the GFX library: it is infact, in a way, a very robust framework for animations. Unlike the other Sprite based libraries, this works a little different. We don't use the same functions those other libraries provide, but instead we work on what I call a snapshot-mechanism. Basically, it works like this: before placing a picture on screen, we first take a snapshot of the area of the screen we are to place the picture. Then we display the picture in that area. When we need to move the picture of that area or simply delete that picture, all we do is restore back the already taken snapshot. If we were moving the picture, we simply repeat the procedure but this time taking the snapshot of the new area. The library declares and defines the follwing functions and procedures for this snapshot mechanism:
A typical animation code would look similar to the following snippet:
Note that the three steps listed below are always present (and in that order) in all your animation snippets:
For the sake of convenience, the following procedures are provided:
So, the above example would be simplified to:
Wow, this is one long tutorial,, well.. there other stuff in the GFX library, but thats for Global time slicing, i.e a time based method of synchronizing various processes.. this is perticularly useful when you have multiple processes that draw on the screen at the same time. But.. i'm not going to explain it here,, maybe sometime later.. |
Author: | Cervantes [ Sun Apr 24, 2005 9:32 am ] |
Post subject: | |
Looks promising, rizzix. I'd like to try it out, but the files aren't where they should be. I found the GFX module at http://www.compsci.ca/bbs/files/gfx.tu, but I couldn't find the globals.tu. |
Author: | rizzix [ Sun Apr 24, 2005 1:47 pm ] |
Post subject: | |
ok.. fixed |