Skip to content

Commit

Permalink
Add basic shapes example
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonsilva committed Oct 23, 2023
1 parent c704bbd commit 1fb3f1c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ Examples using raylib text functionality, including sprite fonts loading/generat
| 74 | [text_format_text](text/text_format_text.rb) | <img src="text/text_format_text.png" alt="text_format_text" width="80"> | ⭐️☆☆☆ | 1.1 | 3.0 | [Ray](https://github.com/raysan5) |
| 75 | [text_input_box](text/text_input_box.rb) | <img src="text/text_input_box.png" alt="text_input_box" width="80"> | ⭐️⭐️☆☆ | 1.7 | 3.5 | [Ray](https://github.com/raysan5) |
| 76 | [text_writing_anim](text/text_writing_anim.rb) | <img src="text/text_writing_anim.png" alt="text_writing_anim" width="80"> | ⭐️⭐️☆☆ | 1.4 | 1.4 | [Ray](https://github.com/raysan5) |

## Shapes

Examples using raylib shapes drawing functionality.

| ## | example | image | difficulty<br>level | version<br>created | last version<br>updated | original<br>developer |
|----|------------------------------------------------------|--------|:-------------------:|:------------------:|:------------------:|:----------|
| 31 | [shapes_basic_shapes](shapes/shapes_basic_shapes.rb) | <img src="shapes/shapes_basic_shapes.png" alt="shapes_basic_shapes" width="80"> | ⭐️☆☆☆ | 1.0 | **4.0** | [Ray](https://github.com/raysan5) |
Binary file added examples/shapes/shapes_basic_shapes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions examples/shapes/shapes_basic_shapes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# ******************************************************************************************
#
# raylib [shapes] example - Draw basic shapes 2d (rectangle, circle, line...)
#
# Example originally created with raylib 1.0, last time updated with raylib 4.2
#
# Example ported to Ruby by Wilson Silva (@wilsonsilva). Works with Raylib 4.5
#
# Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
# BSD-like license that allows static linking with closed source software
#
# Copyright (c) 2014-2023 Ramon Santamaria (@raysan5)
#
# ******************************************************************************************

require 'bundler/setup'
require 'raylib'

# Initialization
# --------------------------------------------------------------------------------------
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 450

Raylib.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [shapes] example - basic shapes drawing")

rotation = 0.0

Raylib.set_target_fps(60) # Set our game to run at 60 frames-per-second
# --------------------------------------------------------------------------------------

# Main game loop
until Raylib.window_should_close # Detect window close button or ESC key
# Update
# ----------------------------------------------------------------------------------
rotation += 0.2
# ----------------------------------------------------------------------------------

# Draw
# ----------------------------------------------------------------------------------
Raylib.begin_drawing
Raylib.clear_background(Raylib::RAYWHITE)

Raylib.draw_text("some basic shapes available on raylib", 20, 20, 20, Raylib::DARKGRAY)

# Circle shapes and lines
Raylib.draw_circle(SCREEN_WIDTH/5, 120, 35, Raylib::DARKBLUE)
Raylib.draw_circle_gradient(SCREEN_WIDTH/5, 220, 60, Raylib::GREEN, Raylib::SKYBLUE)
Raylib.draw_circle_lines(SCREEN_WIDTH/5, 340, 80, Raylib::DARKBLUE)

# Rectangle shapes and lines
Raylib.draw_rectangle(SCREEN_WIDTH/4*2 - 60, 100, 120, 60, Raylib::RED)
Raylib.draw_rectangle_gradient_h(SCREEN_WIDTH/4*2 - 90, 170, 180, 130, Raylib::MAROON, Raylib::GOLD)
Raylib.draw_rectangle_lines(SCREEN_WIDTH/4*2 - 40, 320, 80, 60, Raylib::ORANGE)

# Triangle shapes and lines
Raylib.draw_triangle(
Raylib::Vector2.create(SCREEN_WIDTH/4.0 * 3.0, 80.0),
Raylib::Vector2.create(SCREEN_WIDTH/4.0 * 3.0 - 60.0, 150.0),
Raylib::Vector2.create(SCREEN_WIDTH/4.0 * 3.0 + 60.0, 150.0),
Raylib::VIOLET
)

Raylib.draw_triangle_lines(
Raylib::Vector2.create(SCREEN_WIDTH/4.0 * 3.0, 160.0),
Raylib::Vector2.create(SCREEN_WIDTH/4.0 * 3.0 - 20.0, 230.0),
Raylib::Vector2.create(SCREEN_WIDTH/4.0 * 3.0 + 20.0, 230.0),
Raylib::DARKBLUE
)

# Polygon shapes and lines
Raylib.draw_poly(Raylib::Vector2.create(SCREEN_WIDTH/4.0 * 3, 330), 6, 80, rotation, Raylib::BROWN)
Raylib.draw_poly_lines(Raylib::Vector2.create(SCREEN_WIDTH/4.0 * 3, 330), 6, 90, rotation, Raylib::BROWN)
Raylib.draw_poly_lines_ex(Raylib::Vector2.create(SCREEN_WIDTH/4.0 * 3, 330), 6, 85, rotation, 6, Raylib::BEIGE)

Raylib.draw_line(18, 42, SCREEN_WIDTH - 18, 42, Raylib::BLACK)
Raylib.end_drawing
# ----------------------------------------------------------------------------------
end

# De-Initialization
# --------------------------------------------------------------------------------------
Raylib.close_window # Close window and OpenGL context
# --------------------------------------------------------------------------------------

0 comments on commit 1fb3f1c

Please sign in to comment.