Create a graph in-game to track stat changes

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
goldo
Regular
Posts: 63
Joined: Mon Jan 23, 2017 8:23 am
Contact:

Create a graph in-game to track stat changes

#1 Post by goldo » Sun Oct 27, 2019 6:28 am

Hi guys,

Perhaps this is asking a bit too much of Ren'py, but my experience is that many things are possible combining it with Python so I'll ask.

I would like to have a 'stat' screen in-game rendering the evolution of a given stat so far as a curve.

For instance, in the game the player is able to make gold every day. I would have to create a graph showing a simple curve with the x axis showing days and the y axis showing gold made. I guess drawing the axis would be simple enough using fixed images, and positioning the dots would be equally simple: just figure out the x spacing for 1 day and y spacing for 1 gold and write something like:

Code: Select all

for day in len(days):
	draw_a_dot_at(x_spacing*day, y_spacing*gold_made[day])
...or something like that.

My question is: how can I draw the actual curve? I could always draw the dots using some simple method, but how can I make it into a curve? (Also without having horrible performance, sometimes a concern when rendering things in Ren'py)?

I'm sure there should be various ways to do that with Python, but I'm not sure which is the best way to do this within a Ren'py game.

User avatar
XxrenxX
Veteran
Posts: 267
Joined: Tue Oct 02, 2012 2:40 am
Projects: Chasing
Deviantart: bara-ettie
Location: Canada
Contact:

Re: Create a graph in-game to track stat changes

#2 Post by XxrenxX » Sat Nov 02, 2019 4:32 am

I've never heard of doing this, your best bet might be to find an already existing python code and finding a way to put it into renpy. Maybe this thread can help with the importing part.

User avatar
pyPat
Regular
Posts: 30
Joined: Wed Sep 11, 2019 5:34 pm
Github: patlol
Location: France
Contact:

Re: Create a graph in-game to track stat changes

#3 Post by pyPat » Sat Nov 02, 2019 5:09 am

Hello,

There is a python library : matplotlib, that allows you to make graphs. It's a bit like the pestle hammer to crush a fly (French formula to say that the tool are clearly oversized compared to the objective) but I only know this library to do that. The advantage is that it is well documented.

You can import libraries into ren py with

Code: Select all

init python:
    import matplotlib
To my knowledge there is nothing in pygame to draw graphs
Be careful to use the matplotlib version corresponding to the python version used by ren py 2.x and not 3.x

Attention it is required object-programming :roll:
I used this lib with displaying in tkinter windows manager, I don't know how matplotlib can interface with ren py classes
English is not my native language; please excuse typing errors.

goldo
Regular
Posts: 63
Joined: Mon Jan 23, 2017 8:23 am
Contact:

Re: Create a graph in-game to track stat changes

#4 Post by goldo » Wed Dec 04, 2019 3:23 pm

Thank you, I will look into this! Sorry for my late reply

Post Reply

Who is online

Users browsing this forum: Bing [Bot]