Code Doodles!
Re: Code Doodles!
There's a "maths" missing I fear
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
- slime
- Solid Snayke
- Posts: 3166
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Code Doodles!
Apparently some Intel video drivers give back the Microsoft OpenGL 1.1 software renderer when an OpenGL context with 16x MSAA is requested.Garmelon wrote:The same thing happens on my school's computers (kinda old ) too - When I reduce the samples to 0 it works.
I recommend using 8x MSAA at the most, and preferably 4x. There aren't many GPUs which support 16x MSAA, and as discovered by Nixola some drivers do unexpected things when you request it. The visual difference between 8x and 16x is very minimal anyway (and the performance difference can be large – when 16x is supported.)
Even 4x MSAA makes things look comparatively great, and it's the most-supported MSAA value across all GPUs.
Re: Code Doodles!
Fixed in the original post, just download it againNixola wrote:There's a "maths" missing I fear
- HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
- Contact:
Re: Code Doodles!
I was bored, while at the same time curious about Pi. I decided to "study" it by seeing which digits are more common on it. You can try it yourself with different amounts of digits to consider, from 1 to 999:
Download main.lua
Or code itself (relatively big, thus the uploaded file):
And a screenie, because why not?
Download main.lua
Or code itself (relatively big, thus the uploaded file):
Code: Select all
function love.load()
pi = "3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198"
piMin, piMax = 1, string.len(pi)-2
love.window.setTitle("A study of Pi")
font1 = love.graphics.newFont(12)
font2 = love.graphics.newFont(8)
love.graphics.setFont(font1)
love.window.setMode(400, 300)
love.graphics.setLineWidth(2)
keyHold = {t = 0, rt = 0, mt = 1, mrt = .02}
counter = {0, 1, 0, 0, 0, 0, 0, 0, 0, 0}
piDigits = 1
end
function love.update(dt)
local down = love.keyboard.isDown
local rp = 0
if down("up") or down("=") or down("kp+") or down("right") then
rp = 1
elseif down("down") or down("-") or down("kp-") or down("left") then
rp = -1
else
keyHold.t = 0
keyHold.rt = 0
end
if rp ~= 0 then
keyHold.t = math.min(keyHold.t + dt, keyHold.mt)
if keyHold.t == keyHold.mt then
keyHold.rt = keyHold.rt+dt
if keyHold.rt >= keyHold.mrt then
keyHold.rt = 0
piDigits = math.min(piMax, math.max(piMin, piDigits+rp))
updatePi()
end
end
end
end
function love.draw()
love.graphics.setFont(font1)
local font = love.graphics.getFont()
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("Digits: " .. piDigits, 3, 3)
local more, less = 1, 1
for i, v in ipairs(counter) do
if v/piDigits <= counter[less]/piDigits then
less = i
end
if v/piDigits >= counter[more]/piDigits then
more = i
end
end
love.graphics.setColor(255, 255, 255, 55)
for i = 1, 10 do
love.graphics.rectangle("fill", 5, 100+(i-1)*5, 400-10, 1)
end
local t = {}
for i = 1, #counter+2 do
local l = i-1
local n = 0
if l >= 1 and l <= #counter then
n = counter[l]/counter[more]
end
table.insert(t, n)
end
for i = 2, #t do
local x1, x2 = math.max(5, (i-2)*(400/11)), math.min(400-5, (i-1)*(400/11))
local y1, y2 = (100+9*5) - t[i-1]*(9*5), (100+9*5) - t[i]*(9*5)
if i < #t then
love.graphics.setColor(255, 255, 255, 55)
love.graphics.setLineWidth(2)
if i-1 == more then
love.graphics.setColor(155, 155, 255, 105)
love.graphics.setLineWidth(4)
elseif i-1 == less then
love.graphics.setColor(255, 155, 155, 105)
love.graphics.setLineWidth(4)
end
love.graphics.line(x2, y2, x2, 100+9*5)
end
love.graphics.setLineWidth(2)
love.graphics.setColor(0, 105, 255, 255)
love.graphics.line(x1, y1, x2, y2)
end
love.graphics.setLineWidth(2)
for i, v in ipairs(counter) do
love.graphics.setColor(255, 255, 255, 255)
local x = (400/11)*i
love.graphics.print(i-1, x-font:getWidth(i-1)/2, 20)
love.graphics.setColor(255, 255, 255, 255)
if i == less then
love.graphics.setColor(255, 155, 155, 255)
elseif i == more then
love.graphics.setColor(155, 155, 255, 255)
end
love.graphics.rectangle("line", x-5, 40, 10, 50)
love.graphics.setColor(0, 255, 0, 255)
love.graphics.rectangle("fill", x-4, 40+50-48*(v/piDigits), 8, 48*(v/piDigits))
end
love.graphics.setFont(font2)
local font = love.graphics.getFont()
local t = {""}
for i = 1, string.len(pi) do
local s = string.sub(pi, i, i)
if font:getWidth(t[#t] .. s) >= 400-10 then
table.insert(t, "")
end
t[#t] = t[#t] .. s
end
local w = 0
for i, v in ipairs(t) do
if string.len(v)+w >= piDigits+2 and w < piDigits+2 then
local s = {"", ""}
s[1] = string.sub(v, 1, piDigits+2-w)
s[2] = string.sub(v, piDigits+3-w, -1)
love.graphics.setColor(255, 205, 0, 255)
love.graphics.print(s[1], 5, 300-5-(#t*10)+(i-1)*10)
love.graphics.setColor(255, 205, 0, 105)
love.graphics.print(s[2], 5+font:getWidth(s[1]), 300-5-(#t*10)+(i-1)*10)
else
love.graphics.setColor(255, 205, 0, 255)
if string.len(v)+w >= piDigits+2 then
love.graphics.setColor(255, 205, 0, 105)
end
love.graphics.print(v, 5, 300-5-(#t*10)+(i-1)*10)
end
w = w + string.len(v)
end
end
function love.keypressed(key)
if key == "up" or key == "=" or key == "kp+" or key == "right" then
piDigits = math.min(piMax, piDigits+1)
updatePi()
elseif key == "down" or key == "-" or key == "kp-" or key == "left" then
piDigits = math.max(piMin, piDigits-1)
updatePi()
end
end
function love.mousepressed(x, y, button)
if button == "wu" then
piDigits = math.min(piMax, piDigits+1)
updatePi()
elseif button == "wd" then
piDigits = math.max(piMin, piDigits-1)
updatePi()
end
end
function updatePi()
counter = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
for i = 3, 2+piDigits do
local d = tonumber(string.sub(pi, i, i))
counter[d+1] = counter[d+1] + 1
end
end
Re: Code Doodles!
Ah, nice idea.
Edit: This is wrong:
Although I can tell you that pi is a transcendental number.
That means that every possible number sequence can be found in the post comma digits of pi, and therefore the numbers are evenly distributed.
Edit: This is wrong:
Although I can tell you that pi is a transcendental number.
That means that every possible number sequence can be found in the post comma digits of pi, and therefore the numbers are evenly distributed.
Last edited by undef on Fri Jul 31, 2015 9:18 pm, edited 1 time in total.
Re: Code Doodles!
Sorry for the nit-picking, but this reasoning is not correct. You can make a transcendental number consisting only of the digits 0 and 1. Therefore not every possible number sequence appears in every transcendental number.undef wrote:Ah, nice idea.
Although I can tell you that pi is a transcendental number.
That means that every possible number sequence can be found in the post comma digits of pi, and therefore the numbers are evenly distributed.
The statements (1) that every possible number can be found inside pi and (2) that the digits are evenly distributed in pi might still be true. I am not sure about that.
Check out my blog on gamedev
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Code Doodles!
There are an infinite number of digits, so every number will appear an infinite amount of times, so yeah, that should be true.micha wrote:The statements (1) that every possible number can be found inside pi and (2) that the digits are evenly distributed in pi might still be true. I am not sure about that.
Re: Code Doodles!
I know this is very off-topic, but this reasoning is again incorrect. We maybe know the first millions of digits of pi and we can see that all observed digits are approximately uniformly distributed. That is strong evidence but no proof that this pattern will continue indefinitely.DaedalusYoung wrote:There are an infinite number of digits, so every number will appear an infinite amount of times, so yeah, that should be true.
Further more, knowing that all numbers appear an infinite amount of times, does not mean that they all appear equally often.
But of course, there is good reason to believe that all the digits are uniformly distributed.
Check out my blog on gamedev
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Code Doodles!
We do know that pi is transcendental, that only means that no rational a/b number equals it;
But according to wikipedia, we don't yet know whether pi is a Normal Number or not, meaning that the infinite digits in any base would be uniformly distributed or not.
But according to wikipedia, we don't yet know whether pi is a Normal Number or not, meaning that the infinite digits in any base would be uniformly distributed or not.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Code Doodles!
Oops sorry, my bad, I was wrong.micha wrote:Sorry for the nit-picking, but this reasoning is not correct. You can make a transcendental number consisting only of the digits 0 and 1. Therefore not every possible number sequence appears in every transcendental number.undef wrote:snip.
The statements (1) that every possible number can be found inside pi and (2) that the digits are evenly distributed in pi might still be true. I am not sure about that.
Learned something new again
(Would like someone to prove that pi is a normal number now...)
Who is online
Users browsing this forum: No registered users and 3 guests