Skip to content

Commit d427896

Browse files
Merge pull request #86 from sDos280/master
adding example and making examples look neater
2 parents ef088e9 + 8eb8a38 commit d427896

File tree

4 files changed

+133
-83
lines changed

4 files changed

+133
-83
lines changed

examples/shaders/shaders_basic_lighting.py

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import raylib as rl
3232

33-
3433
from raylib.colors import *
3534
from dataclasses import dataclass
3635
from enum import Enum
@@ -43,12 +42,13 @@
4342
# lighting system
4443
from light_system import *
4544

46-
#// Initialization
47-
#//--------------------------------------------------------------------------------------
48-
screenWidth = 1200;
49-
screenHeight = 720;
45+
# Initialization
46+
# --------------------------------------------------------------------------------------
47+
screenWidth = 1200
48+
screenHeight = 720
5049

51-
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT| rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available)
50+
rl.SetConfigFlags(
51+
rl.FLAG_MSAA_4X_HINT | rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available)
5252
rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders] example - basic lighting")
5353

5454
camera = rl.ffi.new('struct Camera3D *', [
@@ -59,101 +59,98 @@
5959
rl.CAMERA_PERSPECTIVE
6060
])
6161

62-
#// Load models
62+
# Load models
6363
modelA = rl.LoadModelFromMesh(rl.GenMeshTorus(0.4, 1.0, 16, 32))
6464
modelB = rl.LoadModelFromMesh(rl.GenMeshCube(1.0, 1.0, 1.0))
6565
modelC = rl.LoadModelFromMesh(rl.GenMeshSphere(0.5, 32, 32))
6666

67-
#// Load models texture
67+
# Load models texture
6868
texture = rl.LoadTexture(b"resources/texel_checker.png")
6969

70-
#// Assign texture to default model material
70+
# Assign texture to default model material
7171
modelA.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
7272
modelB.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
7373
modelC.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
7474

75-
angle = 6.282;
75+
angle = 6.282
7676

77-
#// Using 4 point lights, white, red, green and blue
77+
# Using 4 point lights, white, red, green and blue
7878

79-
lights0 = Light(LIGHT_POINT, [ 4, 2, 4 ], Vector3Zero(), WHITE)
80-
lights1 = Light(LIGHT_POINT, [4, 2, 4 ], Vector3Zero(), RED)
81-
lights2 = Light(LIGHT_POINT, [ 0, 4, 2 ], Vector3Zero(), GREEN)
82-
lights3 = Light(LIGHT_POINT, [ 0, 4, 2 ], Vector3Zero(), BLUE)
79+
lights0 = Light(LIGHT_POINT, [4, 2, 4], Vector3Zero(), WHITE)
80+
lights1 = Light(LIGHT_POINT, [4, 2, 4], Vector3Zero(), RED)
81+
lights2 = Light(LIGHT_POINT, [0, 4, 2], Vector3Zero(), GREEN)
82+
lights3 = Light(LIGHT_POINT, [0, 4, 2], Vector3Zero(), BLUE)
8383

84-
lightSystem = LightSystem([ 0.2, 0.2, 0.2, 1.0 ], lights0, lights1, lights2, lights3)
84+
lightSystem = LightSystem([0.2, 0.2, 0.2, 1.0], lights0, lights1, lights2, lights3)
8585
fogD = rl.GetShaderLocation(lightSystem.shader, b'FogDensity')
8686
fogDensity = 0.0
8787

88-
#// All models use the same shader - which lights them
88+
# All models use the same shader - which lights them
8989
modelA.materials[0].shader = lightSystem.shader
9090
modelB.materials[0].shader = lightSystem.shader
9191
modelC.materials[0].shader = lightSystem.shader
9292

9393
rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL) # Set an orbital camera mode
9494

95-
rl.SetTargetFPS(60) # // Set our game to run at 60 frames-per-second
96-
#//--------------------------------------------------------------------------------------
95+
rl.SetTargetFPS(60) # // Set our game to run at 60 frames-per-second
96+
# --------------------------------------------------------------------------------------
9797

98-
#// Main game loop
99-
while not rl.WindowShouldClose(): #// Detect window close button or ESC key
100-
#// Update
101-
#//----------------------------------------------------------------------------------
98+
# Main game loop
99+
while not rl.WindowShouldClose(): # Detect window close button or ESC key
100+
# Update
101+
# ----------------------------------------------------------------------------------
102102
if rl.IsKeyPressed(rl.KEY_W): lights0.enabled = not lights0.enabled
103103
if rl.IsKeyPressed(rl.KEY_R): lights1.enabled = not lights1.enabled
104104
if rl.IsKeyPressed(rl.KEY_G): lights2.enabled = not lights2.enabled
105105
if rl.IsKeyPressed(rl.KEY_B): lights3.enabled = not lights3.enabled
106106

107-
rl.UpdateCamera(camera) #// Update camera
107+
rl.UpdateCamera(camera) # Update camera
108108

109-
#// Make the lights do differing orbits
109+
# Make the lights do differing orbits
110110
angle -= 0.02
111-
lights0.position.x = math.cos(angle)*4.0
112-
lights0.position.z = math.sin(angle)*4.0
113-
lights1.position.x = math.cos(-angle*0.6)*4.0
114-
lights1.position.z = math.sin(-angle*0.6)*4.0
115-
lights2.position.y = math.cos(angle*0.2)*4.0
116-
lights2.position.z = math.sin(angle*0.2)*4.0
117-
lights3.position.y = math.cos(-angle*0.35)*4.0
118-
lights3.position.z = math.sin(-angle*0.35)*4.0
111+
lights0.position.x = math.cos(angle) * 4.0
112+
lights0.position.z = math.sin(angle) * 4.0
113+
lights1.position.x = math.cos(-angle * 0.6) * 4.0
114+
lights1.position.z = math.sin(-angle * 0.6) * 4.0
115+
lights2.position.y = math.cos(angle * 0.2) * 4.0
116+
lights2.position.z = math.sin(angle * 0.2) * 4.0
117+
lights3.position.y = math.cos(-angle * 0.35) * 4.0
118+
lights3.position.z = math.sin(-angle * 0.35) * 4.0
119119

120-
#// Update the light shader with the camera view position
120+
# Update the light shader with the camera view position
121121

122122
lightSystem.update(camera.position)
123123

124-
125-
# ffi.cast('wchar_t', x)
126-
# modelA.transform = ffi.cast('Matrix *', MatrixRotateY(angle*1.7))[0]
127-
# modelA.transform = MatrixRotateY(angle*1.7)
128-
#// Rotate the torus
129-
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)[0])[0]
130-
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)[0])[0]
124+
# ffi.cast('wchar_t', x)
125+
# modelA.transform = ffi.cast('Matrix *', MatrixRotateY(angle*1.7))[0]
126+
# modelA.transform = MatrixRotateY(angle*1.7)
127+
# Rotate the torus
128+
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)[0])[0]
129+
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)[0])[0]
131130
modelA.transform = rl.ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)))[0]
132131
modelA.transform = rl.ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)))[0]
133132

134133
if (rl.IsKeyPressed(rl.KEY_F)):
135134
rl.ToggleFullscreen()
136135

136+
# ----------------------------------------------------------------------------------
137137

138-
#//----------------------------------------------------------------------------------
139-
140-
#// Draw
141-
#//----------------------------------------------------------------------------------
138+
# Draw
139+
# ----------------------------------------------------------------------------------
142140
rl.BeginDrawing()
143141

144142
rl.ClearBackground(RAYWHITE)
145143

146144
rl.BeginMode3D(camera[0])
147145

148-
#// Draw the three models
149-
rl.DrawModel(modelA, [0,0,0], 1.0, WHITE)
150-
rl.DrawModel(modelB, [-1.6,0,0], 1.0, WHITE)
151-
rl.DrawModel(modelC, [ 1.6,0,0], 1.0, WHITE)
146+
# Draw the three models
147+
rl.DrawModel(modelA, [0, 0, 0], 1.0, WHITE)
148+
rl.DrawModel(modelB, [-1.6, 0, 0], 1.0, WHITE)
149+
rl.DrawModel(modelC, [1.6, 0, 0], 1.0, WHITE)
152150

153-
#// Draw markers to show where the lights are
151+
# Draw markers to show where the lights are
154152
lightSystem.draw()
155153

156-
157154
rl.DrawGrid(10, 1.0)
158155

159156
rl.EndMode3D()
@@ -163,17 +160,17 @@
163160
rl.DrawText(b"Keys RGB & W toggle lights", 10, 30, 20, DARKGRAY)
164161

165162
rl.EndDrawing()
166-
#//----------------------------------------------------------------------------------
163+
# ----------------------------------------------------------------------------------
167164

168165

169-
#// De-Initialization
170-
#//--------------------------------------------------------------------------------------
171-
rl.UnloadModel(modelA) # // Unload the modelA
172-
rl.UnloadModel(modelB) # // Unload the modelB
173-
rl.UnloadModel(modelC) # // Unload the modelC
166+
# De-Initialization
167+
# --------------------------------------------------------------------------------------
168+
rl.UnloadModel(modelA) # Unload the modelA
169+
rl.UnloadModel(modelB) # Unload the modelB
170+
rl.UnloadModel(modelC) # Unload the modelC
174171

175-
rl.UnloadTexture(texture) #// Unload the texture
172+
rl.UnloadTexture(texture) # Unload the texture
176173

177174
rl.UnloadShader(lightSystem.shader)
178175

179-
rl.CloseWindow() #// Close window and OpenGL context
176+
rl.CloseWindow() # Close window and OpenGL context

examples/shaders/shaders_fog.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
model2.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
3838
model3.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
3939

40-
light = Light(LIGHT_POINT, [ 0, 4, 0 ], Vector3Zero(), WHITE)
41-
lightSystem = LightSystem([ 0.2, 0.2, 0.2, 1.0 ], light)
40+
light = Light(LIGHT_POINT, [0, 4, 0], Vector3Zero(), WHITE)
41+
lightSystem = LightSystem([0.2, 0.2, 0.2, 1.0], light)
4242

43-
fog_color = rl.ffi.new('float[]', [0.2,0.2,1.0,1.0])
43+
fog_color = rl.ffi.new('float[]', [0.2, 0.2, 1.0, 1.0])
4444
fogC = rl.GetShaderLocation(lightSystem.shader, b'fogColor')
4545
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.SHADER_UNIFORM_VEC4);
4646

@@ -55,20 +55,19 @@
5555
model3.materials[0].shader = lightSystem.shader
5656

5757
rl.SetTargetFPS(60)
58-
a=0.0
58+
a = 0.0
5959
while not rl.WindowShouldClose():
60-
61-
a+=0.01
62-
camera.position.x = math.sin(a)*6
63-
camera.position.z = math.cos(a)*6
60+
61+
a += 0.01
62+
camera.position.x = math.sin(a) * 6
63+
camera.position.z = math.cos(a) * 6
6464
rl.UpdateCamera(camera)
6565

6666
lightSystem.update(camera.position)
6767

68-
69-
model.transform = rl.ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateX(-0.025)))[0]
70-
model.transform = rl.ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateZ(0.012)))[0]
71-
68+
model.transform = rl.ffi.cast("Matrix *", MatrixMultiply(model.transform, MatrixRotateX(-0.025)))[0]
69+
model.transform = rl.ffi.cast("Matrix *", MatrixMultiply(model.transform, MatrixRotateZ(0.012)))[0]
70+
7271
if rl.IsKeyDown(rl.KEY_UP):
7372
fogDensity = min(fogDensity + 0.001, 1)
7473

@@ -84,18 +83,16 @@
8483
if rl.IsKeyDown(rl.KEY_SPACE):
8584
rl.ClearBackground(BLACK)
8685

87-
8886
rl.BeginMode3D(camera[0])
8987
rl.DrawModel(model, [0] * 3, 1, WHITE)
9088
rl.DrawModel(model2, [-2.6, 0, 0], 1, WHITE)
91-
rl.DrawModel(model3, [ 2.6, 0, 0], 1, WHITE)
89+
rl.DrawModel(model3, [2.6, 0, 0], 1, WHITE)
9290

9391
for i in range(-20, 20, 2):
9492
rl.DrawModel(model, [i, 0, 2], 1, WHITE)
9593

96-
97-
#Raylib removed this function
98-
#rl.DrawGizmo([1000, 1000, 1000])
94+
# Raylib removed this function
95+
# rl.DrawGizmo([1000, 1000, 1000])
9996

10097
rl.EndMode3D()
10198

@@ -110,4 +107,3 @@
110107
rl.UnloadTexture(texture)
111108
rl.UnloadShader(lightSystem.shader)
112109
rl.CloseWindow()
113-
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""
2+
3+
raylib [shapes] example - Lines Bezier
4+
5+
"""
6+
7+
from pyray import *
8+
from raylib.colors import (
9+
RAYWHITE,
10+
GRAY,
11+
RED
12+
)
13+
14+
15+
# ------------------------------------------------------------------------------------
16+
# Program main entry point
17+
# ------------------------------------------------------------------------------------
18+
def main():
19+
# Initialization
20+
# ------------------------------------------------------------------------------------
21+
screenWidth = 800
22+
screenHeight = 450
23+
24+
set_config_flags(ConfigFlags.FLAG_MSAA_4X_HINT)
25+
init_window(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines")
26+
27+
start = Vector2(0, 0)
28+
end = Vector2(screenWidth, screenHeight)
29+
30+
set_target_fps(60) # Set our game to run at 60 frames-per-second
31+
# -------------------------------------------------------------------------------------
32+
33+
# Main game loop
34+
while not window_should_close(): # Detect window close button or ESC key
35+
# Update
36+
# ----------------------------------------------------------------------------------
37+
if is_mouse_button_down(MouseButton.MOUSE_BUTTON_LEFT): start = get_mouse_position()
38+
if is_mouse_button_down(MouseButton.MOUSE_BUTTON_RIGHT): end = get_mouse_position()
39+
# ----------------------------------------------------------------------------------
40+
41+
# Draw
42+
# ----------------------------------------------------------------------------------
43+
begin_drawing()
44+
45+
clear_background(RAYWHITE)
46+
47+
draw_text("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY)
48+
49+
draw_line_bezier(start, end, 2.0, RED)
50+
51+
end_drawing()
52+
# ----------------------------------------------------------------------------------
53+
54+
# De-Initialization
55+
# ----------------------------------------------------------------------------------
56+
close_window() # Close window and OpenGL context
57+
# ----------------------------------------------------------------------------------
58+
59+
# execute the main function
60+
if __name__ == '__main__':
61+
main()

examples/textures/image_loading.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
InitWindow(screenWidth, screenHeight, b"raylib [textures] example - image loading")
77

8-
9-
10-
image = LoadImage(b"resources/raylib_logo.jpg")
8+
image = LoadImage(b"resources/raylib_logo.png")
119
texture = LoadTextureFromImage(image)
1210

1311
UnloadImage(image)
@@ -24,8 +22,6 @@
2422

2523
EndDrawing()
2624

25+
UnloadTexture(texture)
2726

28-
29-
30-
UnloadTexture(texture)
3127
CloseWindow()

0 commit comments

Comments
 (0)