Skip to content

Commit 79cc8bb

Browse files
Merge pull request #69 from TyroneSlothrop/master
Create shapes_draw_rounded_rectangle.py
2 parents c602d48 + cc55fa7 commit 79cc8bb

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#/*******************************************************************************************
2+
#*
3+
#* raylib [shapes] example - draw rectangle rounded (with gui options)
4+
#*
5+
#* This example has been created using raylib 2.5 (www.raylib.com)
6+
#* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
7+
#*
8+
#* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
9+
#*
10+
#* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
11+
#*
12+
#********************************************************************************************/
13+
14+
import pyray
15+
from raylib.colors import (
16+
RAYWHITE,
17+
LIGHTGRAY,
18+
DARKGRAY,
19+
GOLD,
20+
MAROON,
21+
)
22+
23+
#// Initialization
24+
#//--------------------------------------------------------------------------------------
25+
SCREEN_WIDTH = 800
26+
SCREEN_HEIGHT = 450
27+
28+
pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [shapes] example - draw rectangle rounded")
29+
30+
roundness = 0.2
31+
width = 200
32+
height = 100
33+
segments = 0
34+
lineThick = 1
35+
36+
drawRect = False
37+
drawRoundedRect = True
38+
drawRoundedLines = False
39+
40+
pyray.set_target_fps(60) #// Set our game to run at 60 frames-per-second
41+
#//--------------------------------------------------------------------------------------
42+
43+
#// Main game loop
44+
while not pyray.window_should_close(): #// Detect window close button or ESC key
45+
46+
#// Update
47+
#//----------------------------------------------------------------------------------
48+
rec = pyray.Rectangle( (pyray.get_screen_width()-width-250)/2, (pyray.get_screen_height()-height)/2, width, height )
49+
#//----------------------------------------------------------------------------------
50+
51+
#// Draw
52+
#//----------------------------------------------------------------------------------
53+
pyray.begin_drawing()
54+
pyray.clear_background(RAYWHITE)
55+
56+
pyray.draw_line(560,0,560,pyray.get_screen_height(),pyray.fade(LIGHTGRAY,0.6))
57+
pyray.draw_rectangle(560,0,pyray.get_screen_width()-500,pyray.get_screen_height(),pyray.fade(LIGHTGRAY,0.3))
58+
59+
if drawRect:
60+
pyray.draw_rectangle_rec(rec,pyray.fade(GOLD,0.6))
61+
if drawRoundedRect:
62+
pyray.draw_rectangle_rounded(rec,roundness,segments,pyray.fade(MAROON,0.2))
63+
if drawRoundedLines:
64+
pyray.draw_rectangle_rounded_lines(rec,roundness,segments,lineThick,pyray.fade(MAROON,0.4))
65+
66+
#// Draw GUI controls
67+
#//------------------------------------------------------------------------------
68+
width = int( pyray.gui_slider_bar(pyray.Rectangle(640,40,105,20),"Width",0,width,0,pyray.get_screen_width()-300) )
69+
height = int( pyray.gui_slider_bar(pyray.Rectangle(640,70,105,20),"Height",0,height,0,pyray.get_screen_height()-50) )
70+
roundness = pyray.gui_slider_bar(pyray.Rectangle(640,140,105,20),"Roundness",0,roundness,0,1)
71+
lineThick = int( pyray.gui_slider_bar(pyray.Rectangle(640,170,105,20),"Thickness",0,lineThick,0,20) )
72+
segments = int( pyray.gui_slider_bar(pyray.Rectangle(640,240,105,20),"Segments",0,segments,0,60) )
73+
74+
drawRoundedRect = pyray.gui_check_box(pyray.Rectangle(640,320,20,20),"DrawRoundedRect",drawRoundedRect)
75+
drawRoundedLines = pyray.gui_check_box(pyray.Rectangle(640,350,20,20),"DrawRoundedLines",drawRoundedLines)
76+
drawRect = pyray.gui_check_box(pyray.Rectangle(640,380,20,20),"DrawRect",drawRect)
77+
#//------------------------------------------------------------------------------
78+
79+
pyray.draw_text(pyray.text_format( "MODE: %s" % "MANUAL" if segments >= 4 else "AUTO" ), 640, 280, 10, MAROON if segments >= 4 else DARKGRAY )
80+
pyray.draw_fps(10,10)
81+
pyray.end_drawing()
82+
#//------------------------------------------------------------------------------
83+
84+
# De-Initialization
85+
pyray.close_window() # Close window and OpenGL context

0 commit comments

Comments
 (0)