Page 1 of 1

Create a graph in-game to track stat changes

Posted: Sun Oct 27, 2019 6:28 am
by goldo
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.

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

Posted: Sat Nov 02, 2019 4:32 am
by XxrenxX
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.

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

Posted: Sat Nov 02, 2019 5:09 am
by pyPat
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

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

Posted: Wed Dec 04, 2019 3:23 pm
by goldo
Thank you, I will look into this! Sorry for my late reply