This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
KaoS's profile picture

Lua (not CC) screensaver type deal

Started by KaoS, 07 June 2013 - 08:52 PM
KaoS #1
Posted 07 June 2013 - 10:52 PM
Hi guys, at work today I started working on a solar system simulating system in love2d and purely by luck was amazed at the artistic potential at what I had created. I stripped out most of what I had coded and added a few effects and status displays etc, then implemented keyboard controls so you can influence the swirl of objects. Please take a look and let me know what you think

ScreenShot
Spoiler

Download

one object has a much larger weight than the other objects and so they cluster around it

the controls are as follows:
arrow keys and arrows on numpad to move the main object
numpad 5 to slow the main object down
numpad 7 or home to clear all object trails
numpad 1 or end to toggle the main object having weight
numpad +/- to slow down or speed up simulation
numpad 9/3 or pgUp/pgDown to increase/decrease the main object's total weight
numpad 0 or insert to add another object
numpad . or delete to remove the most recent object
numpad * to cycle different object styles
numpad / or / to toggle the status display
numpad enter to toggle fullscreen and escape to close fullscreen
backspace to reset to the beginning
hold mouse1 and the main object will follow the cursor around, tap it and the main object will shoot in that direction
press mouse2 to instantly move the object to the clicked location and fix it there, it will not move at all until moved with mouse1

the status display will show for 2 seconds after a body is added/removed, the style is cycled or the simulation speed is changed

What else would you guys like to see in here?

FOR THE ADMINS: I realise this is not a CC program and I am putting it on the CC forums but this is the general subforum so I hope you allow it. It's the only community I take part in which knows what Lua is
Edited on 08 June 2013 - 09:39 AM
Kingdaro #2
Posted 07 June 2013 - 11:10 PM
Dude, that's awesome!

A couple of comments, first off, I love how you've done the trails. I never would've thought of just a bunch of trailing circles decreasing in length.

And a couple of comments on the code:

		if tObjects[1].isMain and love.keyboard.isDown("up","down","left","right","kp2","kp4","kp5","kp6","kp8") then
Why the isDown statement? If tObjects[1].isMain is true, the keypresses in this if statement should resolve without any issue. Sure you might get a speed boost doing this, but nothing significant really.

Lastly, I realize that it's probably a force of habit from using CC, but localizing all of your variables isn't necessary when using LÖVE, unless you want variables unique to a function or script, of course. Again, you might get a speed boost, but an unnoticeable one. Reiterating on this point, variable initialization and asset loading is usually done under the love.load callback, so that LÖVE can perform all of the operations it needs to before you initialize your project, and not after. Plus, "resetting" the game becomes as easy as calling love.load() again.
lieudusty #3
Posted 07 June 2013 - 11:21 PM
Hmm its not working, I get the rubber piggy screen
KaoS #4
Posted 07 June 2013 - 11:22 PM
I just figured the isDown for all of the keys checking at once would save it having to go through every single if statement for each key if none of them are being pressed, I should look into this

You are quite right about the CC habits carrying over, I make them local mainly to stop them from getting in the way of other scripts like if I require "otherfile" then all of "otherfile"'s vars don't get carried over. I should really stop doing that lol :)/>

Thanks for taking a look :)/>

Hmm its not working, I get the rubber piggy screen

try dragging the file over the love launcher, your file assoc may be a little off
KaoS #5
Posted 07 June 2013 - 11:57 PM
I have re-uploaded it with quite a cool change, now you can drag the mouse around the screen and the main object will follow it, I found that if you hold it near the edge of the screen it allows the other objects to orbit closer around it as they continuously bounce against the edge and lose momentum, then release the main object and take a look

also try quickly clicking at the furthest corner from the main object, it will shoot in that direction and ricochet wildly around the screen
KaoS #6
Posted 08 June 2013 - 11:24 AM
another big update, previously it did not take lag into effect on object trails, now lag is slightly more pronounced but it does not mess with the physics, pgUp and pgDown increase or decrease the weight of the main object and end has become a toggle for the weight, trails are now double the length and the main object has a 3x longer trail. Trail lengths & widths are now configurable

EDIT: oh and I made the mouse1 drag more elastic as well as added mouse2 pinning

EDIT2: added key repeating, scaled down all objects except the main one, scaled down the main object's trail and updated the status display too

EDIT3: fixed all the local vars as Kingdaro requested and made backspace reset the prog

EDIT4: removed that irritating slingshot which would send objects flying

EDIT5: doubled trail particles for smoother trails, after scaling them down the trails didn't look as good

EDIT6: changed main particle's trail behavior on pinning
Edited on 08 June 2013 - 10:02 AM
Engineer #7
Posted 08 June 2013 - 11:46 AM
I must say, it is very weird that you cannot convert it into an .exe..
Here is an example with what I mean: (how the heck does this attachment thing work o_0)

-Link removed, it isnt on my dropbox anymore-
billysback #8
Posted 08 June 2013 - 11:51 AM
you have to install LOVE… it's not that hard :P/>

this is amazing by the way, its simplicity is beautiful :)/>
Engineer #9
Posted 08 June 2013 - 11:52 AM
you have to install LOVE… it's not that hard :P/>

this is amazing by the way, its simplicity is beautiful :)/>
I have it installed.. I know how to run it, but it should be possible to run with an exe, when you do not have it installed
KaoS #10
Posted 08 June 2013 - 12:29 PM
if you need an exe link use this, it works on 64x windows, no guarantees on any other operating systems
KaoS #11
Posted 08 June 2013 - 12:36 PM
you have to install LOVE… it's not that hard :P/>

this is amazing by the way, its simplicity is beautiful :)/>

Thank you :)/>
Engineer #12
Posted 08 June 2013 - 03:07 PM
Oh, that was the problem. I compiled it with a 32 bit version since everyone can click it then. Oh well, what does it even matter..
*installs 64 bit version*

It really is a nice program you have made KaoS! I am sorry I was "complaining", not really but it could be considered complaining. So my apologies for that! :)/>/>

+1
KaoS #13
Posted 08 June 2013 - 04:19 PM
I didn't take any offence don't worry :)/> thanks for the compliment and +1