From 9cb8dc787849df50da1f351f67ad4b9020748131 Mon Sep 17 00:00:00 2001 From: oeloeloel <26174257+oeloeloel@users.noreply.github.com> Date: Sat, 5 Dec 2020 19:13:42 -0500 Subject: Create geometry_docs.rb Added description of Geometry module and scale_rect method --- dragon/geometry_docs.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 dragon/geometry_docs.rb 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 -- cgit v1.2.3