Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local math = require("math")
- local io = require("io")
- local os = require("os")
- -- Initial file setup, with name input
- local file = io.open("generated.3d", "w")
- file:write("{")
- -- Gather user input for name and word
- print("Please provide your name")
- local name = io.read()
- print("Choose a random number for UID generation perposes")
- local numberChosen = io.read()
- -- Can change this to something more secure in the future.
- local word = name
- function seedGenerator (word)
- -- Calculating the seed
- local seed = 0
- for i = 1, #word do
- seed = seed + string.byte(word:sub(i,i))
- end
- return seed
- end
- -- Encrypt the word into a unique identifier.
- math.randomseed(numberChosen)
- local encryptedWord = ""
- for i = 1, #word do
- encryptedWord = encryptedWord .. tostring( string.char ( string.byte(word:sub(i,i) ) + math.random(1,3) ) )
- end
- -- Write out our initial identifiers
- file:write('\n label = "' .. name .. " - " .. encryptedWord .. '",')
- file:write('\n tooltip = "This key was generated by Etelan",')
- file:write('\n shapes = {')
- file:close()
- -- Generates the shapes
- function generateStructure (word)
- local file = io.open("generated.3d", "a")
- -- Set the seed
- math.randomseed(seedGenerator(word))
- -- x number of different blocks total.
- local n = 5
- for i = 1,n do
- -- Start writing the block
- file:write('\n {')
- -- Generate Numbers
- local numbers = {}
- for block = 1,6 do
- numbers[block] = math.random(1,11)
- if block>3 then
- while numbers[block] == numbers[block - 3] do
- numbers[block] = math.random(1,11)
- end
- end
- end
- -- Write out the vectors created
- for i = 1,6 do
- file:write(tostring(numbers[i]) .. ",")
- end
- -- Lua has no switch statement, therefore I long for death.
- -- This code choses the block, and then ends the block code.
- if i == 1 then file:write(' texture="chisel:blocks/antiblock/red"},') end
- if i == 2 then file:write(' texture="chisel:blocks/antiblock/blue"},') end
- if i == 3 then file:write(' texture="chisel:blocks/antiblock/white"},') end
- if i == 4 then file:write(' texture="chisel:blocks/antiblock/yellow"},') end
- if i == 5 then file:write(' texture="chisel:blocks/antiblock/orange"},') end
- if i == 6 then file:write(' texture="chisel:blocks/antiblock/lime"') end
- end
- -- Tidy up the end of the file
- file:write("\n }")
- file:write("\n}")
- file:close()
- end
- -- Call our method to generate the seed and also our shapes and encryption.
- generateStructure(word)
- -- Generate the object!
- print("\n\n [Starting Print Job] \n\n")
- os.execute("print3d generated.3d")
- print("\n\nAll done, pickup your key.")
Add Comment
Please, Sign In to add comment