Drawing shapes using code

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
User avatar
Minnfae
Regular
Posts: 106
Joined: Mon Dec 07, 2009 5:01 am
Projects: Undecided
Contact:

Drawing shapes using code

#1 Post by Minnfae » Mon Sep 17, 2012 2:46 am

I'd like to draw some simple shapes in my game using code instead of a bunch of pngs, to not increase the filesize too much. Is there a convenient way to do this? I remember doing this with a package called tkinter or something similar in pure python, but I'm still a bit confused with Ren'py.
By shapes I mean mainly circles and lines.
My avatar art is a freebie by SilverHyena. Thanks a lot!

User avatar
kankan
Regular
Posts: 80
Joined: Tue Mar 06, 2012 1:47 am
Contact:

Re: Drawing shapes using code

#2 Post by kankan » Mon Sep 17, 2012 3:19 am

I guess it depends on your definition of the word "convenient," but yes, it's certainly possible to draw shapes. You're probably looking for canvas(), which can be used from an instance of the Displayable class within render. It somewhat matches the calls from pygame.

So you can use it a bit like this:

Code: Select all

class myDisplay(renpy.Displayable):
    def __init__(self, **kwargs):
        renpy.Displayable.__init__(self, **kwargs)

    def render(self, width, height, st, at):
            render = renpy.Render(160, 160)
            canvas = render.canvas()
            
            pointlist = self.get_pointlist()
            canvas.polygon("#003366", pointlist, width=0)
            
            canvas.line("#000", (80, 10), (80, 80))
            canvas.line("#000", (150, 45), (80, 80))

            return render
This would potentially create a canvas on which a filled blue polygon and two lines appear (except the pointlist method is undefined here, so it wouldn't quite work).

User avatar
Minnfae
Regular
Posts: 106
Joined: Mon Dec 07, 2009 5:01 am
Projects: Undecided
Contact:

Re: Drawing shapes using code

#3 Post by Minnfae » Mon Sep 17, 2012 10:57 am

Ah, ok.
Yes, it's what I was looking for. Thanks a lot!
My avatar art is a freebie by SilverHyena. Thanks a lot!

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot, zyric