The title sounds far more grand than what I'm actually doing. In a nutshell, my dad asked me to visualize an eight-dimensional system, where each dimension of the system was an aspect of ethical principles. He wanted to know how many possible combinations are there, and wanted me to make him a rendering of them in an octagonal arrangement.
My older brother beat me to the punch and did a math paper on this stuff, and even wrote a cool little program to output SVGs of each possibility. By his math, there are 268,435,456 possibilities (buh!). You can see the paper here: http://wjholden.com/octagon/
Now, I've finally gotten around to writing a .love that can render the general idea. If you guys could look at the source and make suggestions that would be grand.
Controls:
Enter: toggle text
Space: pause
Up: Increase odds of showing line
Down: Decrease odds of showing line
Escape: Exit
8 Dimensions Rendered
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
8 Dimensions Rendered
- Attachments
-
8dimensions.love
- Version 3.
- (1.58 KiB) Downloaded 367 times
-
8dimensions.love
- Version 2
- (1.4 KiB) Downloaded 296 times
-
8dimensions.love
- Version 1.
- (1.39 KiB) Downloaded 284 times
Last edited by tentus on Tue Jul 19, 2011 3:46 am, edited 3 times in total.
Kurosuke needs beta testers
Re: 8 Dimensions Rendered
Hey, I looked at your script code.
It's pretty clean and looks farily bug-free.
There are a few optimization tricks you may want to consider:
Lua has an easier (and faster) way of implementing those loops:
Yes, 'pairs' is generally faster than numeric loops (and faster than 'ipairs' too).
This code is not terribly efficient in particular.
It's executed every frame and you are allocating a new table each time.
This is doubly slow since you are overwriting your reference to the old table which the garbage collector needs to pick up.
A faster alternative would be:
I'm not too crazy about the "getCoords" function.
I think it could be simplified using trigonometry.
Something like:
Where 150 is the 'radius' of your octagon and 250 is the offset where you want it rendered.
It's pretty clean and looks farily bug-free.
There are a few optimization tricks you may want to consider:
Code: Select all
for i=1, 8 do
for j=1, 8 do
if points[i][j] == 1 then
Code: Select all
for i, v in pairs (points) do
Code: Select all
function changePoints()
for i=1, 8 do
points[i] = {0,0,0,0,0,0,0,0} -- zero out old values
It's executed every frame and you are allocating a new table each time.
This is doubly slow since you are overwriting your reference to the old table which the garbage collector needs to pick up.
A faster alternative would be:
Code: Select all
-- zero out old values
for j, v in pairs (points[i]) do
points[i][j] = 0
end
I think it could be simplified using trigonometry.
Something like:
Code: Select all
function getCoords(p)
local a = math.rad(45)*p
local x, y = math.cos(a), math.sin(a)
return x * 150 + 250, y * 150 + 250
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: 8 Dimensions Rendered
What. Have you got evidence for that? I've always heard that it was the other way, and it makes sense too.ivan wrote:Yes, 'pairs' is generally faster than numeric loops (and faster than 'ipairs' too).
Help us help you: attach a .love.
Re: 8 Dimensions Rendered
Well, there's this.Robin wrote:What. Have you got evidence for that? I've always heard that it was the other way, and it makes sense too.ivan wrote:Yes, 'pairs' is generally faster than numeric loops (and faster than 'ipairs' too).
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: 8 Dimensions Rendered
Interestingly, that same analysis seems to indicate that i=1,# is much faster than either (scroll down).thelinx wrote:Well, there's this.
Help us help you: attach a .love.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: 8 Dimensions Rendered
I implemented ivan's new getCoords() function, seems to be working just fine: thanks!
Also rearranged how some of the code works, now it generates a table of coords whenever the render changes, and the render pulls from that, rather than recalculating each frame. I also added a simple frame capping statement:
Interestingly, I cannot discern a performance difference between the two programs. Any input, guys?
Also rearranged how some of the code works, now it generates a table of coords whenever the render changes, and the render pulls from that, rather than recalculating each frame. I also added a simple frame capping statement:
Code: Select all
if dt < (1/60) then
love.timer.sleep((1/60) - dt)
end
Kurosuke needs beta testers
Re: 8 Dimensions Rendered
Wait yeah, it's just 2^7! isn't it?
You should be able to figure any n value system by 2^(n-1)!
I think. I suck at math.
Edit:
Argh, nevermind. I got summations and factorials mixed up.
I told you I suck at math.
You should be able to figure any n value system by 2^(n-1)!
I think. I suck at math.
Edit:
Argh, nevermind. I got summations and factorials mixed up.
I told you I suck at math.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: 8 Dimensions Rendered
Apparently this runs super fast on an Asus laptop, when merged into an exe (via 0.7.2). Is anyone aware of any dt problems in merged games?
Kurosuke needs beta testers
- ishkabible
- Party member
- Posts: 241
- Joined: Sat Oct 23, 2010 7:34 pm
- Location: Kansas USA
Re: 8 Dimensions Rendered
about the ipairs vs. pairs vs. generic for loop, it makes sense that for loops would be so much faster for a few reasons
* no function calls yet Lua has instructions MADE for this in it's VM instructions
* the expressions doesn't need to be evaluated every time as in a while loop, it's only evaluated once then i is compared to it
* no conversions from the lua API when switching functions or extra copys, everything stays in place and nothing gives controls to another function
* function calls carry a significant tole in performance even with languages like C/C++
* numbers are faster to use than generators
it makes sense that these would be faster, it seems odd that ipairs isn't a little bit faster though sense it dosn't have to look at the hash table part only the array part.
* no function calls yet Lua has instructions MADE for this in it's VM instructions
* the expressions doesn't need to be evaluated every time as in a while loop, it's only evaluated once then i is compared to it
Code: Select all
local t = {1,2,3}
for i=0, #t, 1 do
print(i)
table.insert(t, i)
end
* function calls carry a significant tole in performance even with languages like C/C++
* numbers are faster to use than generators
it makes sense that these would be faster, it seems odd that ipairs isn't a little bit faster though sense it dosn't have to look at the hash table part only the array part.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: 8 Dimensions Rendered
Of course this is tested on equal table structure, or at least I'd hope so. As for why that makes pairs faster, it is unordered, so it doesn't have to make sure things are in order, as ipairs does.
Who is online
Users browsing this forum: Ahrefs [Bot] and 2 guests