examples: Use decl literals (#221)

This commit is contained in:
Mike Will 2025-03-12 16:21:15 -04:00 committed by GitHub
parent 03ec79ef85
commit d4fc514d54
Failed to generate hash of commit
37 changed files with 323 additions and 323 deletions

View file

@ -13,7 +13,7 @@ const CircleWave = struct {
const screenWidth = 800;
const screenHeight = 450;
const colors = [14]rl.Color{ rl.Color.orange, rl.Color.red, rl.Color.gold, rl.Color.lime, rl.Color.blue, rl.Color.violet, rl.Color.brown, rl.Color.light_gray, rl.Color.pink, rl.Color.yellow, rl.Color.green, rl.Color.sky_blue, rl.Color.purple, rl.Color.beige };
const colors = [14]rl.Color{ .orange, .red, .gold, .lime, .blue, .violet, .brown, .light_gray, .pink, .yellow, .green, .sky_blue, .purple, .beige };
//------------------------------------------------------------------------------------
// Program main entry point
@ -57,14 +57,14 @@ pub fn main() !void {
rl.updateMusicStream(music); // Update music buffer with new stream data
// Restart music playing (stop and play)
if (rl.isKeyPressed(rl.KeyboardKey.space)) {
if (rl.isKeyPressed(.space)) {
rl.stopMusicStream(music);
rl.playMusicStream(music);
pause = false;
}
// Pause/Resume music playing
if (rl.isKeyPressed(rl.KeyboardKey.p)) {
if (rl.isKeyPressed(.p)) {
pause = !pause;
if (pause) {
@ -74,9 +74,9 @@ pub fn main() !void {
}
}
if (rl.isKeyDown(rl.KeyboardKey.down)) {
if (rl.isKeyDown(.down)) {
pitch -= 0.01;
} else if (rl.isKeyDown(rl.KeyboardKey.up)) {
} else if (rl.isKeyDown(.up)) {
pitch += 0.01;
}
@ -103,24 +103,24 @@ pub fn main() !void {
//----------------------------------------------------------------------------------
rl.beginDrawing();
rl.clearBackground(rl.Color.white);
rl.clearBackground(.white);
for (circles) |circle| {
rl.drawCircleV(circle.position, circle.radius, rl.fade(circle.color, circle.alpha));
rl.drawCircleV(circle.position, circle.radius, .fade(circle.color, circle.alpha));
}
// Draw time bar
rl.drawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, rl.Color.light_gray);
rl.drawRectangle(20, screenHeight - 20 - 12, @intFromFloat(timePlayed), 12, rl.Color.maroon);
rl.drawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, rl.Color.gray);
rl.drawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, .light_gray);
rl.drawRectangle(20, screenHeight - 20 - 12, @intFromFloat(timePlayed), 12, .maroon);
rl.drawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, .gray);
// Draw help instructions
rl.drawRectangle(20, 20, 425, 145, rl.Color.white);
rl.drawRectangleLines(20, 20, 425, 145, rl.Color.gray);
rl.drawText("PRESS SPACE TO RESTART MUSIC", 40, 40, 20, rl.Color.black);
rl.drawText("PRESS P TO PAUSE/RESUME", 40, 70, 20, rl.Color.black);
rl.drawText("PRESS UP/DOWN TO CHANGE SPEED", 40, 100, 20, rl.Color.black);
rl.drawText(rl.textFormat("SPEED: %f", .{pitch}), 40, 130, 20, rl.Color.maroon);
rl.drawRectangle(20, 20, 425, 145, .white);
rl.drawRectangleLines(20, 20, 425, 145, .gray);
rl.drawText("PRESS SPACE TO RESTART MUSIC", 40, 40, 20, .black);
rl.drawText("PRESS P TO PAUSE/RESUME", 40, 70, 20, .black);
rl.drawText("PRESS UP/DOWN TO CHANGE SPEED", 40, 100, 20, .black);
rl.drawText(rl.textFormat("SPEED: %f", .{pitch}), 40, 130, 20, .maroon);
rl.endDrawing();
//----------------------------------------------------------------------------------

View file

@ -34,13 +34,13 @@ pub fn main() !void {
rl.updateMusicStream(music); // Update music buffer with new stream data
// Restart music playing (stop and play)
if (rl.isKeyPressed(rl.KeyboardKey.space)) {
if (rl.isKeyPressed(.space)) {
rl.stopMusicStream(music);
rl.playMusicStream(music);
}
// Pause/Resume music playing
if (rl.isKeyPressed(rl.KeyboardKey.p)) {
if (rl.isKeyPressed(.p)) {
pause = !pause;
if (pause) {
@ -63,16 +63,16 @@ pub fn main() !void {
rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.white);
rl.clearBackground(.white);
rl.drawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, rl.Color.light_gray);
rl.drawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, .light_gray);
rl.drawRectangle(200, 200, 400, 12, rl.Color.light_gray);
rl.drawRectangle(200, 200, @intFromFloat(timePlayed * 400), 12, rl.Color.maroon);
rl.drawRectangleLines(200, 200, 400, 12, rl.Color.gray);
rl.drawRectangle(200, 200, 400, 12, .light_gray);
rl.drawRectangle(200, 200, @intFromFloat(timePlayed * 400), 12, .maroon);
rl.drawRectangleLines(200, 200, 400, 12, .gray);
rl.drawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, rl.Color.light_gray);
rl.drawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, rl.Color.light_gray);
rl.drawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, .light_gray);
rl.drawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, .light_gray);
//----------------------------------------------------------------------------------
}
}

View file

@ -111,12 +111,12 @@ pub fn main() anyerror!void {
rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.ray_white);
rl.clearBackground(.ray_white);
rl.drawText(rl.textFormat("sine frequency: %i", .{@as(i32, @intFromFloat(frequency))}),
rl.getScreenWidth() - 220, 10, 20, rl.Color.red);
rl.getScreenWidth() - 220, 10, 20, .red);
rl.drawText("click mouse button to change frequency or pan",
10, 10, 20, rl.Color.dark_gray);
10, 10, 20, .dark_gray);
// Draw the current buffer state proportionate to the screen
for (0..screenWidth) |i| {
@ -124,7 +124,7 @@ pub fn main() anyerror!void {
const y: f32 = @floatFromInt(data[@divFloor(i * MAX_SAMPLES, screenWidth)]);
position.y = 250 + 50 * y / 32000;
rl.drawPixelV(position, rl.Color.red);
rl.drawPixelV(position, .red);
}
//----------------------------------------------------------------------------------
}

View file

@ -28,8 +28,8 @@ pub fn main() !void {
{
// Update
//----------------------------------------------------------------------------------
if (rl.isKeyPressed(rl.KeyboardKey.space)) rl.playSound(fxWav); // Play WAV sound
if (rl.isKeyPressed(rl.KeyboardKey.enter)) rl.playSound(fxOgg); // Play OGG sound
if (rl.isKeyPressed(.space)) rl.playSound(fxWav); // Play WAV sound
if (rl.isKeyPressed(.enter)) rl.playSound(fxOgg); // Play OGG sound
//----------------------------------------------------------------------------------
// Draw
@ -37,10 +37,10 @@ pub fn main() !void {
rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.white);
rl.clearBackground(.white);
rl.drawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, rl.Color.light_gray);
rl.drawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, rl.Color.light_gray);
rl.drawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, .light_gray);
rl.drawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, .light_gray);
//----------------------------------------------------------------------------------
}
}