Results 1 to 1 of 1
[Release] Joyau: A Ruby interpeter
This is a discussion on [Release] Joyau: A Ruby interpeter within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Hello, I will start with something I had forgotten to talk about in my previous message. It is about Module#joyau_inherited, ...
-
12-27-2009, 08:56 AM #1QJ Gamer Blue
Achievements:
- Join Date
- Aug 2009
- Location
- N/A
- Posts
- 38
- QJ Pts
- 1,799
- Level
- 24
- Downloads
- 0
- Uploads
- 0
[Release] Joyau: A Ruby interpeter
Hello,
I will start with something I had forgotten to talk about in my previous message. It is about Module#joyau_inherited, which can be used in order to fix some problems we may encounter with classes inheriting Joyau's. I don't know why this happens, but I simply created a method which fixes that problem. In fact, you could use something like:
But I prefer the following code:Code:class Foo < Joyau::Bar class << self def new(*args) obj = super() obj.send(:initialize, *args) # initialize is a private method. return obj; end end end
( In Ruby, a class is a kind of Module ;) )Code:require 'joyau/inherited' class Foo < Joyau::Bar joyau_inherited end
About this new update now; you can change the buffer on which you are drawing with the class "Buffer".
You can create them easily:
It is also possible to change the color type which pixel format will be used for that buffer:Code:buffer = Joyau::Buffer.new(width, height)
You can draw objects on that buffer with its method draw ("draw(something)" will draw something on the buffer, "draw" will draw the buffer). For instance, the following code, which is in one of the samples, will convert a picture in a grayscale one:Code:buffer = Joyau::Buffer.new(width, height, Joyau::Buffer::PF_XXXX)
It is possible to change the actual buffer with Buffer#set_actual. Three class methods may help you when applying such changes:Code:buf.lock do (0..(buf.w-1)).each do |x| (0..(buf.h-1)).each do |y| col = buf[x, y].to_col gray = (0.299 * col.r + 0.587 * col.g + 0.114 * col.b).to_i col.r = gray col.g = gray col.b = gray buf[x, y] = col end end end
- Buffer::actual: The actual buffer
- Buffer::screen: A buffer representing the scren, which should be used only for reading access.
- Buffer::default: The default drawbuffer.
There is another way to draw on a buffer: using a Painter bounded to your Buffer:
That painter will allow you to draw lots of things on the Buffer. You won't have to call Buffer#set_actual explictly so.Code:painter = Joyau::Painter.new(buffer)
Despite these painters' existence, it can be easier to use Buffer with Joyau::draw:
Its only parameter is a Hash. It will change the actual Buffer, and put the old one back after ahving executed your block. Here are the keys which are checked by Joyau:Code:Joyau.draw(:buffer => my_buffer) do |buf| # .... end
- :buffer: If given, that buffer will be used. If not, the actual buffer will do the job :)
- :painter: When true, the function will yield a painter bounded to the buffer instead of the buffer. By default, it is false.
- :auto_update: When true, Joyau::sync is called after your block. By default, it is true.
Of course, a block is mandatory for this method. An exception will be raised if you don't pass one ;)
It's almost everything I changed in Joyau's classes (not all, but I won't talk about "details", like functions which returns nil instead of an object in which a NULL pointer is embedded)
From now on, the documentation is generated through RDoc, but it parses my C++ code directly. I've a bit "cheated" for the selecters, yet it is far better than parsing a fake-ruby script.
For the compilation, rake is used instead of make. By this Rakefile, I can generate documentations and packages automatically :)
Besides, with that new Rakefile, I removed Ruby's stdlib from the git, since no changes whre applied on it. I'm using Net::FTP to download it instead :)
So, here's the download link for the package created with "rake release": http://cloud.github.com/downloads/Ko...u-0.25.tar.bz2


LinkBack URL
About LinkBacks
Reply With Quote

I recently played a bit of Super Mario 3D World + Bowser's Fury and I enjoyed playing this...
Super Mario Fans Out There!