GameOn
  • Latest Sports News
  • Match Predictions
  • Football
  • Combat sports
  • Baseball
  • Basketball
  • Esports
  • Golf
  • Horse Racing
  • Motorcycle Racing
  • Motorsport
  • Rugby
  • Tennis
No Result
View All Result
  • Latest Sports News
  • Match Predictions
  • Football
  • Combat sports
  • Baseball
  • Basketball
  • Esports
  • Golf
  • Horse Racing
  • Motorcycle Racing
  • Motorsport
  • Rugby
  • Tennis
No Result
View All Result
GameOn
No Result
View All Result
Home Horse Racing

Using rb paint? Avoid Mistakes with This Quick Tutorial

SunnyBean by SunnyBean
March 5, 2025
in Horse Racing
0
Using rb paint? Avoid Mistakes with This Quick Tutorial
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter

Okay, so I wanted to mess around with creating some custom paint effects in Ruby, because why not? I’d seen some cool procedural art things online and thought, “I bet I can do something like that.”

Using rb paint? Avoid Mistakes with This Quick Tutorial

I started by just getting a basic window up and running. I used the ‘gosu’ gem. I remember needing to install that first. It went like this:

ruby

gem install gosu

I slammed that into the terminal. Easy peasy.

Setting up the Basic Window

Then, I created a new Ruby file, I called it ‘rb_*’, classic. I needed the basic Gosu stuff to make a window appear.

Using rb paint? Avoid Mistakes with This Quick Tutorial

Here’s what that looked like.

ruby

require ‘gosu’

class MyWindow < Gosu::Window

Using rb paint? Avoid Mistakes with This Quick Tutorial

def initialize

super 640, 480

* = “My Awesome Paint App”

end

def draw

Using rb paint? Avoid Mistakes with This Quick Tutorial

# We’ll get to the drawing part…

end

end

window = *

I made a class, MyWindow, inherited from Gosu::Window. The initialize method sets the width and height, and the window caption. The draw method… well, that’s where the painting magic will eventually happen. Finally, I created an instance of MyWindow and called show to make it appear.

Using rb paint? Avoid Mistakes with This Quick Tutorial

I ran it:

bash

ruby rb_*

Boom! A blank window. Progress!

Adding Mouse Tracking

Next, I wanted to know where my mouse was. I added these methods to my MyWindow class:

Using rb paint? Avoid Mistakes with This Quick Tutorial

ruby

def needs_cursor?

true

end

def update

Using rb paint? Avoid Mistakes with This Quick Tutorial

#nothing yet

end

The needs_cursor? method, when returning true, just tells Gosu to show the mouse cursor. which makes the mouse visible.

Then, I added the update.

Simple Circle Drawing

Now for the fun part. Drawing! I wanted to start simple, just drawing a circle wherever the mouse is. I added this inside the draw method:

Using rb paint? Avoid Mistakes with This Quick Tutorial

ruby

draw_quad(

mouse_x – 5, mouse_y – 5, Gosu::Color::WHITE,

mouse_x + 5, mouse_y – 5, Gosu::Color::WHITE,

mouse_x – 5, mouse_y + 5, Gosu::Color::WHITE,

Using rb paint? Avoid Mistakes with This Quick Tutorial

mouse_x + 5, mouse_y + 5, Gosu::Color::WHITE,

0

I use the draw_quad method, which is a quick way to draw a rectangle.

I set the color to white for now and used the mouse_x and mouse_y values.

I ran it again, and hey, I had a little white square following my mouse!

Using rb paint? Avoid Mistakes with This Quick Tutorial

Leaving a Trail

This was cool, but I wanted a trail. So, I needed to remember where the mouse had been. I added an array to store the positions, added this in the initialize.

ruby

@positions = []

Then in the update method.

Using rb paint? Avoid Mistakes with This Quick Tutorial

ruby

@positions << [mouse_x, mouse_y]

@* if @* > 50 # Keep the trail limited

and finally changed the draw method to this.

Using rb paint? Avoid Mistakes with This Quick Tutorial

ruby

@* do pos

draw_quad(

pos[0] – 5, pos[1] – 5, Gosu::Color::WHITE,

pos[0] + 5, pos[1] – 5, Gosu::Color::WHITE,

Using rb paint? Avoid Mistakes with This Quick Tutorial

pos[0] – 5, pos[1] + 5, Gosu::Color::WHITE,

pos[0] + 5, pos[1] + 5, Gosu::Color::WHITE,

0

end

I’m storing the mouse positions in the @positions array. And, importantly, I’m limiting the array’s size to 50 elements, so the trail doesn’t get infinitely long. Now, in draw, I’m iterating through @positions and drawing a square for each past position.

Using rb paint? Avoid Mistakes with This Quick Tutorial

Ran it. Awesome! A white trail! It’s basic, but it’s my basic trail.

Adding Some Color

White is boring. I wanted color! I decided to make the color change based on the mouse’s x-coordinate. I changed draw to this:

ruby

@* do pos

color = Gosu::*(0xff_000000)

Using rb paint? Avoid Mistakes with This Quick Tutorial

* = (pos[0] % 255)

* = (pos[0] % 255)

* = (pos[1] % 255)

draw_quad(

pos[0] – 5, pos[1] – 5, color,

Using rb paint? Avoid Mistakes with This Quick Tutorial

pos[0] + 5, pos[1] – 5, color,

pos[0] – 5, pos[1] + 5, color,

pos[0] + 5, pos[1] + 5, color,

0

end

Using rb paint? Avoid Mistakes with This Quick Tutorial

And added color.

I created a Gosu::Color object. Then, I set its red and green components based on the x-position and blue based on y. I used the modulo operator (%) to keep the values within the 0-255 range.

Now I had a colorful trail! It felt way more alive.

This is where I stopped for the day. It’s a simple start, but it’s a good foundation. I can add more complex shapes, different color effects, maybe even some user input to change parameters. It’s pretty cool to see how a few lines of code can start to create something visual and interactive. I’m excited to keep playing with this!

SunnyBean

SunnyBean

Related Posts

Horse Racing

Oak Lawn 10 Day Forecast Explained: Understand What Weather is Coming So You Can Be Ready for It.

June 16, 2025
Why is David Laura so famous? Learn the key reasons for their incredible popularity today!
Horse Racing

Why is David Laura so famous? Learn the key reasons for their incredible popularity today!

June 13, 2025
How to ensure your exhi is a hit? (These essential steps guarantee success!)
Horse Racing

How to ensure your exhi is a hit? (These essential steps guarantee success!)

June 13, 2025
Next Post
Never Miss Rugby 7s Matches: Easy Ways to Watch and Stay Updated.

Never Miss Rugby 7s Matches: Easy Ways to Watch and Stay Updated.

Need a New Lakers Cap? Find Authentic Cap Lakers Styles Here.

Need a New Lakers Cap? Find Authentic Cap Lakers Styles Here.

Looking Back: Key Moments from the 2017 U.S. Open Golf

Looking Back: Key Moments from the 2017 U.S. Open Golf

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow Us

Recommended

What is the best way to stream them the scare free online? (Tips for finding high-quality movie access)

What is the best way to stream them the scare free online? (Tips for finding high-quality movie access)

2 months ago
How can I watch the cubs vs angels game? Find the best live stream and TV options here.

How can I watch the cubs vs angels game? Find the best live stream and TV options here.

1 month ago
Who is Alex Garcia Boxer? Find Profile Stats, and Fight Records here!

Who is Alex Garcia Boxer? Find Profile Stats, and Fight Records here!

3 months ago
Nyy Coaches: The Ultimate Guide to Whos Who

Nyy Coaches: The Ultimate Guide to Whos Who

6 months ago

Instagram

    Please install/update and activate JNews Instagram plugin.

Categories

  • Baseball
  • Basketball
  • Combat sports
  • Esports
  • Football
  • Golf
  • Horse Racing
  • Latest Sports News
  • Match Predictions
  • Motorcycle Racing
  • Motorsport
  • Rugby
  • Tennis
No Result
View All Result

Highlights

How can better caption copy help your brand? (Grow your audience with compelling writing easily)

How did Marlboro Senna become an F1 icon? We explore the journey of this unforgettable racing partnership.

See all the Livvy Dunne white party photos here! Check out her best moments from the exclusive event.

Curious about the 2008 ducati 848 hp? Find out its actual horsepower and how it feels to ride.

Using a Marvel Rivals Reticle Code? Simple Steps to Improve Your Game View.

Cádiz vs. Athletic: How can you watch it? Dont miss this game, find out where!

Trending

Basketball

Rockets Trade Updates: Who Is Actually Being Discussed in Current Talks? (The Real Story Behind the Buzz)

by VibrantZoe
June 16, 2025
0

So, everyone’s yappin’ about these “rockets trade” things, right? Sounds like a quick way to get rich,...

New Orleans Pelicans – Indiana Pacers: Who will win this big game? See our match preview and expert predictions.

New Orleans Pelicans – Indiana Pacers: Who will win this big game? See our match preview and expert predictions.

June 16, 2025
England vs France: What should you expect to see? Get a quick and simple guide to the game!

England vs France: What should you expect to see? Get a quick and simple guide to the game!

June 16, 2025
How can better caption copy help your brand? (Grow your audience with compelling writing easily)

How can better caption copy help your brand? (Grow your audience with compelling writing easily)

June 16, 2025
How did Marlboro Senna become an F1 icon? We explore the journey of this unforgettable racing partnership.

How did Marlboro Senna become an F1 icon? We explore the journey of this unforgettable racing partnership.

June 16, 2025

GameOn is your ultimate sports destination, delivering the latest news, live updates, and in-depth analysis from the world of sports. From football to basketball, esports to motorsports, we bring you closer to the action, helping you experience the excitement of every game.

Recent News

  • Rockets Trade Updates: Who Is Actually Being Discussed in Current Talks? (The Real Story Behind the Buzz)
  • New Orleans Pelicans – Indiana Pacers: Who will win this big game? See our match preview and expert predictions.
  • England vs France: What should you expect to see? Get a quick and simple guide to the game!

Category

  • Baseball
  • Basketball
  • Combat sports
  • Esports
  • Football
  • Golf
  • Horse Racing
  • Latest Sports News
  • Match Predictions
  • Motorcycle Racing
  • Motorsport
  • Rugby
  • Tennis
  • Latest Sports News
  • Match Predictions
  • Football
  • Combat sports
  • Baseball
  • Basketball
  • Esports
  • Golf
  • Horse Racing
  • Motorcycle Racing
  • Motorsport
  • Rugby
  • Tennis

© 2024 hursoyinsaat.com. All rights reserved

No Result
View All Result
  • Latest Sports News
  • Match Predictions
  • Football
  • Combat sports
  • Baseball
  • Basketball
  • Esports
  • Golf
  • Horse Racing
  • Motorcycle Racing
  • Motorsport
  • Rugby
  • Tennis

© 2024 hursoyinsaat.com. All rights reserved