Skip to content

Instantly share code, notes, and snippets.

@samanthamjohn
Created May 1, 2015 14:04
Show Gist options
  • Save samanthamjohn/d246202793256788ce33 to your computer and use it in GitHub Desktop.
Save samanthamjohn/d246202793256788ce33 to your computer and use it in GitHub Desktop.
Generates a hopscotch project with 500 objects all growing, modify as needed for your own projects
class ProjectMaker
def original_json
'{
"rules" : [
{
"objectID" : "966281C2-C13C-4CC0-9E5E-00A2CF1D363C-28679-00001DADC7E1BB63",
"abilityID" : "0C0AC15D-34D4-4411-AE82-0B1FE1B85D49-28679-00001DADC7E4CA0B",
"parameters" : [
{
"type" : 42,
"value" : "",
"key" : "",
"defaultValue" : "",
"datum" : {
"block_class" : "operator",
"type" : 7000,
"section" : 5
}
}
],
"ruleBlockType" : 6000
}
],
"uuid" : "",
"original_user" : {
"start_date" : "",
"avatar_type" : 3,
"id" : "",
"nickname" : ""
},
"author" : "BroadKillerwhale",
"label" : "hundreds of rocketships",
"abilities" : [
{
"createdAt" : 452180642.928052,
"blocks" : [
{
"block_class" : "method",
"type" : 50,
"section" : 0
},
{
"type" : 35,
"section" : 3,
"block_class" : "method",
"parameters" : [
{
"type" : 42,
"value" : "500",
"key" : "milliseconds",
"defaultValue" : "500"
}
]
}
],
"abilityID" : "BB938460-0FB3-48FF-A2AC-BB911B057696-28679-00001DADC7E271F5"
},
{
"createdAt" : 452180642.928216,
"blocks" : [
{
"block_class" : "method",
"type" : 50,
"section" : 0
},
{
"type" : 24,
"section" : 0,
"block_class" : "method",
"parameters" : [
{
"type" : 42,
"value" : "-4",
"key" : "degrees",
"defaultValue" : "90"
}
]
},
{
"block_class" : "method",
"type" : 33,
"section" : 2
},
{
"type" : 35,
"section" : 3,
"block_class" : "method",
"parameters" : [
{
"type" : 42,
"value" : "80",
"key" : "milliseconds",
"defaultValue" : "500"
}
]
},
{
"type" : 24,
"section" : 0,
"block_class" : "method",
"parameters" : [
{
"type" : 42,
"value" : "4",
"key" : "degrees",
"defaultValue" : "90"
}
]
}
],
"abilityID" : "1DDF5F76-76C1-4EF5-9C6C-F4425477A07C-28679-00001DADC7E3076E"
},
{
"createdAt" : 452180642.928363,
"blocks" : [
{
"type" : 24,
"section" : 0,
"block_class" : "method",
"parameters" : [
{
"type" : 42,
"value" : "10",
"key" : "degrees",
"defaultValue" : "90"
}
]
},
{
"type" : 24,
"section" : 0,
"block_class" : "method",
"parameters" : [
{
"type" : 42,
"value" : "-10",
"key" : "degrees",
"defaultValue" : "90"
}
]
}
],
"abilityID" : "F9E85D70-F36C-4B39-AB0C-F9971F844BC4-28679-00001DADC7E3680C"
},
{
"createdAt" : 452180642.930783,
"blocks" : [
{
"type" : 26,
"controlScript" : {
"abilityID" : "FB380866-7A9E-4120-B57F-0C2987DD57A8-28679-00001DADC7E3E7CE"
},
"section" : 1,
"block_class" : "control",
"parameters" : [
{
"type" : 44,
"value" : "HSB(266,63,82)",
"key" : "color",
"defaultValue" : "HSB(289,57,44)",
"datum" : {
"block_class" : "operator",
"type" : 5000,
"section" : 4
}
},
{
"type" : 43,
"value" : "10",
"key" : "width",
"defaultValue" : "10"
}
]
},
{
"type" : 44,
"section" : 4,
"block_class" : "method",
"parameters" : [
{
"type" : 47,
"value" : "",
"key" : "variable",
"defaultValue" : "",
"variable" : "B1E70BF8-6F4B-4D1E-9CB4-515A5EA98F30-28679-00001D8F5043574E"
},
{
"type" : 48,
"value" : "1",
"key" : "by",
"defaultValue" : "1"
}
]
}
],
"abilityID" : "7FD574EA-6401-4035-9771-837A2B7D0BBE-28679-00001DADC7E39D72"
},
{
"createdAt" : 452180642.93087,
"blocks" : [
{
"type" : 23,
"section" : 0,
"block_class" : "method",
"parameters" : [
{
"type" : 42,
"value" : "",
"key" : "",
"defaultValue" : "300",
"variable" : "B1E70BF8-6F4B-4D1E-9CB4-515A5EA98F30-28679-00001D8F5043574E"
}
]
},
{
"type" : 24,
"section" : 0,
"block_class" : "method",
"parameters" : [
{
"type" : 42,
"value" : "20",
"key" : "degrees",
"defaultValue" : "90"
}
]
}
],
"abilityID" : "FB380866-7A9E-4120-B57F-0C2987DD57A8-28679-00001DADC7E3E7CE"
},
{
"createdAt" : 452180642.937385,
"blocks" : [
{
"type" : 120,
"controlScript" : {
"abilityID" : "78C05FB1-D7E7-4BF1-84E6-EDB45473CA1E-28679-00001DADC7E483BE"
},
"section" : 3,
"block_class" : "control",
"parameters" : [
{
"type" : 42,
"value" : "6",
"key" : "times",
"defaultValue" : "5"
}
]
},
{
"block_class" : "method",
"type" : 50,
"section" : 0
}
],
"abilityID" : "79399A9B-CE06-4BF4-94DC-1FEA29EDA1D7-28679-00001DADC7E45FE3"
},
{
"createdAt" : 452180642.937403,
"blocks" : [
{
"block_class" : "method",
"type" : 33,
"section" : 2
},
{
"type" : 23,
"section" : 0,
"block_class" : "method",
"parameters" : [
{
"type" : 42,
"value" : "80",
"key" : "",
"defaultValue" : "300"
}
]
}
],
"abilityID" : "78C05FB1-D7E7-4BF1-84E6-EDB45473CA1E-28679-00001DADC7E483BE"
},
{
"createdAt" : 452180680.113734,
"blocks" : [
{
"type" : 123,
"controlScript" : {
"abilityID" : "518B79FD-FFAD-4FF8-A72A-7548626666B1-28679-00001DADC7E4DCE3"
},
"section" : 6,
"block_class" : "control"
}
],
"abilityID" : "0C0AC15D-34D4-4411-AE82-0B1FE1B85D49-28679-00001DADC7E4CA0B"
},
{
"name" : "grow",
"abilityID" : "518B79FD-FFAD-4FF8-A72A-7548626666B1-28679-00001DADC7E4DCE3",
"blocks" : [
{
"type" : 121,
"controlScript" : {
"abilityID" : "A29E5FC7-714E-4B12-93D3-AFFD764C89CF-28679-00001DADC7E504EA"
},
"section" : 3,
"block_class" : "control"
}
],
"createdAt" : 452180685.259008
},
{
"createdAt" : 452180719.200877,
"blocks" : [
{
"type" : 48,
"section" : 2,
"block_class" : "method",
"parameters" : [
{
"type" : 42,
"value" : "10",
"key" : "percent",
"defaultValue" : "50"
}
]
}
],
"abilityID" : "A29E5FC7-714E-4B12-93D3-AFFD764C89CF-28679-00001DADC7E504EA"
},
{
"createdAt" : 452180764.611584,
"blocks" : [
{
"type" : 23,
"section" : 0,
"block_class" : "method",
"parameters" : [
{
"type" : 42,
"value" : "300",
"key" : "",
"defaultValue" : "300"
}
]
}
],
"abilityID" : "D67C269F-39D0-48A0-B49F-D2922D00947D-28679-00001DADC7E54198"
},
{
"abilityID" : "E6F45414-4138-4D40-9B5D-083AF9FB93EA-28679-00001DADC7E56919",
"createdAt" : 452180764.611909
},
{
"abilityID" : "ED22AFDC-EFF5-4D85-9FCF-A7E2ADFC452E-28679-00001DADC7E57F33",
"createdAt" : 452180764.612025
},
{
"abilityID" : "E8529E73-7848-4C87-8289-F49FF8565F11-28679-00001DADC7E59006",
"createdAt" : 452180764.612055
},
{
"abilityID" : "9D217459-1B67-43D2-B97C-3F06C683183E-28679-00001DADC7E5A0D3",
"createdAt" : 452180764.612149
}
],
"eventParameters" : [
],
"version" : 16,
"traits" : [
],
"objects" : [
{
"text" : "🚀",
"objectID" : "966281C2-C13C-4CC0-9E5E-00A2CF1D363C-28679-00001DADC7E1BB63",
"type" : 1,
"name" : "🚀",
"yPosition" : "115.5",
"xPosition" : "121",
"filename" : "text-object.png",
"activeObject" : "0"
}
],
"variables" : [
{
"objectIdString" : "B1E70BF8-6F4B-4D1E-9CB4-515A5EA98F30-28679-00001D8F5043574E",
"name" : "Length"
}
]
}'
end
attr_accessor :num_rules
attr_accessor :original_hash
def initialize(num_rules)
@num_rules = num_rules
@original_hash = JSON.parse original_json
end
def update_rules
rule_prototype_hash = original_hash["rules"][0]
rules = []
num_rules.times do |index|
new_hash = rule_prototype_hash.deep_dup
new_hash["objectID"] = index.to_s
rules << new_hash
end
original_hash["rules"] = rules
end
def update_objects
old_hash = original_hash["objects"][0]
objects = []
num_rules.times do |index|
object_prototype_hash = old_hash.deep_dup
object_prototype_hash["objectID"] = index.to_s
object_prototype_hash["xPosition"] = (100 + index).to_s
object_prototype_hash["yPosition"] = (100 + index).to_s
# type = index % 32 == 1 ? 0 : index % 32
# object_prototype_hash["type"] = type
objects << object_prototype_hash
end
original_hash["objects"] = objects
end
def write_file(name)
update_objects
update_rules
File.open("#{name}.hopscotch", "w") do |f|
string = JSON.pretty_generate original_hash
f.write(string)
end
end
end
project = ProjectMaker.new(500)
project.write_file("new_project")
@samanthamjohn
Copy link
Author

Probably requires rails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment