diff options
| author | oeloeloel <[email protected]> | 2020-12-05 19:13:42 -0500 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2020-12-06 09:51:01 -0600 |
| commit | 9cb8dc787849df50da1f351f67ad4b9020748131 (patch) | |
| tree | a56c700dc74f717f32c51b5e691eb692c44b41a8 | |
| parent | 4349fae320b07a45c10be010a6004d19266d408d (diff) | |
| download | dragonruby-game-toolkit-contrib-9cb8dc787849df50da1f351f67ad4b9020748131.tar.gz dragonruby-game-toolkit-contrib-9cb8dc787849df50da1f351f67ad4b9020748131.zip | |
Create geometry_docs.rb
Added description of Geometry module and scale_rect method
| -rw-r--r-- | dragon/geometry_docs.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/dragon/geometry_docs.rb b/dragon/geometry_docs.rb new file mode 100644 index 0000000..0396f60 --- /dev/null +++ b/dragon/geometry_docs.rb @@ -0,0 +1,51 @@ +# coding: utf-8 +# Copyright 2019 DragonRuby LLC +# MIT License +# geometry_docs.rb has been released under MIT (*only this file*). + +module GeometryDocs + def docs_method_sort_order + [:docs_class, :docs_scale_rect] + end + + def docs_class + <<-S +* DOCS: ~Geometry~ + +The Geometry module contains methods for calculations that are frequently used in game development. + +S + end + + def docs_scale_rect + <<-S +* DOCS: ~GTK::Geometry#scale_rect~ + +Given an array with 4 elements representing a rect [x, y, w, h], this function returns a scaled rect. It accepts three arguments: + +~ratio~: the ratio by which to scale the sprite. A ratio of 2 will double the dimensions of the sprite while a ratio of 0.5 will halve its dimensions. + +~anchor_x~ and ~anchor_y~ specify the point within the rect from which to resize it. Setting both to 0 will affect the width and height of the rect, leaving x and y unchanged. Setting both to 0.5 will scale all sides of the rect proportionally from the center. + +The ~scale_rect~ method can be applied directly to a sprite or other primitives. See CHEATSHEET: How to Scale a Sprite. + +#+begin_src ruby + def tick args + # x, y, w, h + my_rect = [100, 100, 200, 200] + + # halve the dimensions of the rect: + # ratio, anchor_x, anchor_y + new_rect = my_rect.scale_rect(0.5, 0.5, 0.5) + + puts new_rect # => [150.0, 150.0, 100.0, 100.0] + end +#+end_src + +S + end + +module Geometry + extend Docs + extend GeometryDocs +end |
