Why python is awesome (a simple 3d rotation example)

Post your own tutorials, guides and demos.

Post » Tue Jun 15, 2010 1:20 am

super simple python example with 3d rotation along the y axis

to be honest this code could be cleaned up, and made much more flexible, so it doesn't depend on the 2 sprites for radius, or you could choose any two sprites, I just made it that way to be easy to note the flexibility, and so it wouldn't require any coding knowledge to get a basic grasp

drag and drop the two small circles to adjust the radius and move your mouse around to rotate the larger sprite around the y axis of the smaller one

[url:1yi0fvc2]http://dl.dropbox.com/u/1013446/pyrot.cap[/url:1yi0fvc2]

also, if you change the line:
Run python script - "yrot(Sprite)"
to "yrot(Sprite4)"

you'll notice that this function can be applied to any object like a behavior. This is a stripped down example, but in reality you could construct a python object that uses an array of construct sprites, and you treat it all like a single 3d rotatable object.

not to take away from quazi's uber impressive 3d stuff, and it is impressive, but with python you could design an object that could reduce a huge cap only readable by aliens(that's a compliment quaz), to a normal readable cap, with nothing but easy construct events, and simple python commands that you name yourself. if you didn't need a big object composed of many, you could create a better version of the function in this cap custom tailored to your needs, and you wouldn't need a bunch of private variables to manipulate 3d rotation

and after adding all the sprites to an array (a process which could also be simplified by python), you could just use commands like
RotateZ(MyUber3dConstruction,35)


MyUber3dConstruction being composed of 100 objects
35 being the number of degrees

Aside from that, these python objects and functions could be shared with others on the forum who would merely have to copy paste them to a script in start of layout


I recommend anybody who's capable of creating those WOW!! type event sequences in their caps, and eager to share their abilities, try to learn a little python. It really isn't that different from construct events. you just type stuff instead of choosing it from a list. learn a few rules about when to indent, and when to put a '(' or a ')', and you can share your genius/madness with the world, or at least make your madness clutter up your own caps less, and make them readable when you come back to the cap after a few months

3d is just one example, you could use this technique for anything from inventory systems, to custom sprite particle systems, anything complex that starts making your cap difficult to read or manage. It's neater than functions, and can everything 's' can do as far as data structure creation, but with greater readability, and less pointing, clicking, and definitely less typing in of long addresses. Not to denounce my own plugin, because it does have it's uses, but learning how to create data structures in python is much more useful in the long run than learning how to do it with 's'
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Tue Jun 15, 2010 6:21 pm

I don't understand why this is done in Python, when it looks like it can be done using events (ala Functions, Families and Private Variables) just the same. However, I guess the python script is easier to type in quickly than clicking through all of the windows it takes to make events.

Thanks for sharing Lucid! :)
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Tue Jun 15, 2010 7:31 pm

Great intro to python lucid! This is exactly what the community needs to get going on python.
*tips his hat*


[quote="Jayjay":2vb4ypj0]I don't understand why this is done in Python, when it looks like it can be done using events (ala Functions, Families and Private Variables) just the same. However, I guess the python script is easier to type in quickly than clicking through all of the windows it takes to make events.

Thanks for sharing Lucid! :)[/quote:2vb4ypj0]

@Jayjay, No not easier to do in python but lucid was making an intro to spark interest in adding python to projects, so after you lean it you can do things that Construct can't. It is a beautifully simple example for the beginner. So while it is easier to do this in construct; if lucid would have made a huge project then most people would have passed it over.
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Tue Jun 15, 2010 8:01 pm

[quote="Guyon":3j8xq2sq]@Jayjay, No not easier to do in python but lucid was making an intro to spark interest in adding python to projects, so after you lean it you can do things that Construct can't. It is a beautifully simple example for the beginner. So while it is easier to do this in construct; if lucid would have made a huge project then most people would have passed it over.[/quote:3j8xq2sq]

Ahhh, ok. I was leaning more towards Python being easier to code quickly in when you know what you're typing, not that programming in a language in general is easier than using Construct events system.

I do see what you mean though, I was thinking about the case of smaller projects, where including the python runtime in your executable isn't necessary unless you must do something that Construct events alone can't do well (or even at all).

The way Python is implemented in Construct is (very) nice however, and I'm not trying to put it (or the given example) down in any way.
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Tue Jun 15, 2010 8:47 pm

[quote="Jayjay":3fiawcko]
The way Python is implemented in Construct is (very) nice however, and I'm not trying to put it (or the given example) down in any way.[/quote:3fiawcko]

I totality got that Jayjay, and no bad karma taken. :-)
But I really applaud lucid trying to get more interest in python, and simple examples spark complex ideas and projects.
B
28
S
8
G
8
Posts: 530
Reputation: 7,154

Post » Tue Jun 15, 2010 9:43 pm

Cool example lucid. There is a lot of potential for using python to create reusable bits of code.

Here's a barebones example of using python to make your own platform behavior:
[url:2i8lhpmv]http://dl.dropbox.com/u/5426011/examples/pybehavior.cap[/url:2i8lhpmv]

And here's a more complicated example:
[url:2i8lhpmv]http://dl.dropbox.com/u/5426011/examples/pyramid.cap[/url:2i8lhpmv]
Although there is no need to understand how it works to use it.
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Tue Jun 15, 2010 10:22 pm

awesome stuff rojo

I was actually making a platform behavior example when i got called for dinner, so thanks for saving me the trouble

if I get a chance in the next few days, I want to make an example with a python class.

with classes you could make extremely robust solutions as I was describing before.
being able to instantiate classes of complex multi-construct-object objects has alot of potential I think. you could make a 3d editor in python as easily as you could in s with the difference being that it would be copypastable to multiple caps, and completely readable. your events could end up looking as simple as

On Sprite (drag-and-drop) Drop-
run python script "repositionIn3dModel(Sprite)"

on right mouse button click
run python script "beginMouseDrag()"

Right Mouse Button Down
run python script "rotateModelBy(DistanceDragged())"


you can create the equivalent of objects and behaviors

if anyone has any ideas you'd like to see a python example of, post it here, and either I or rojo can probably whip something up. when looking at these examples, if you're considering learning python, focus on the simple actions AFTER you've created your functions.

notice in rojos pyramid example, there is a single command that is doing everything. One of the rewarding things about python (or any modern programming language) is being able to reduce the most complex of tasks to as few commands as you wish. Once you create your complex script, you don't have to even remember how you did, none of the details need to matter, you don't need to remember what each PV was for nothing. Just one command for anything that can be reduced to one task conceptually. Rojo could have extended his example, so you provide not only the object, but the angle as well, only if he needed that flexibility. Either way, he's done thinking about rotating pyramids, now he can just use it like you can any other object.

Anyone using 's' should seriously consider experimenting with python, it's much more powerful, and the learning curve is about the same.
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Wed Jun 16, 2010 7:13 am

[quote:18e8d23k]if anyone has any ideas you'd like to see a python example of, post it here, and either I or rojo can probably whip something up.[/quote:18e8d23k]

Ok I'll bite. How about some vector classes for manipulating distort maps? <joke

Well there's the dpad fuctions using pygame we were talking about, or a good sorting algorithm.
Construct could use a plug that does that.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Fri Jun 18, 2010 7:20 pm

lucid, somehow i know this is pointed towards me :P

honestly, the re usability sounds beautiful, and everything looks pretty simple

i already started learning python with some tuts, forgot it all now but it wasn't too hard from what i remember, and this code looks pretty easy to grasp, all i need is to learn a little bit more about the syntax and its implementation in construct, and ill be good to go, i can honestly make alot of my code neater with this, and faster to write too, that alone is great.

a little example showing something i understand in events through python, seems to be just what i needed to really "get" pythons use.

Now that schools over (last exam was 5 hours ago!) i can sink my teeth into this.
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Fri Jun 18, 2010 10:21 pm

Hmmm.. I can't seem to open the program directly. It immediately goes to an error.

I tried loading it from Construct and another error occured, this time it says that I'm out of memory.

0.o
B
3
S
1
G
2
Posts: 86
Reputation: 997

Next

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests