Last active
November 22, 2023 05:48
-
-
Save Hawkking-cloud/f7d694541421b6d6cf88ce4e1d3d8844 to your computer and use it in GitHub Desktop.
Hawk's CM2py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pypi page : https://pypi.org/project/hcm2py/#description | |
updates : | |
10/21/23 : added createBlockCustom(), allows you to input a string like 7,0,0,0,0,1234.00 directly into the parts, fixed error in special part handling | |
10/21/23 : fixed a bug in the import_build() function | |
11/19/23 : fixed major issue in template, fixed small issue with pasting and then fixed it again because i broke it | |
i also added a cube(), creates an array of blocks based on 2 3d points, also added params for the functions in the documentation | |
added documentation and fixed the template for the use of text block and rand block | |
11/20/23 : upgraded createSign(), now it actually works and works for all buildings, renamed createCustomBuilding(), added import math bc its mandatory | |
also added more blocks to the block part numbers in the documentation | |
11/21/23 : got hcm2py on pypi, now a module, do "pip install hcm2py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hcm2py import * | |
bits = 8 | |
i2 = 1 | |
createBlock(0,2,0,3) | |
for i in range(bits): | |
createBlock(i,0,0,5) | |
createBlock(i,1,0,5) | |
createBlock(i,0,2,2) | |
createBlock(i,1,2,3) | |
createWire(i,0,0,i,0,2) | |
createWire(i,1,0,i,1,2) | |
createBlock(i,0,3,3) | |
createBlock(i,0,4,1) | |
createWire(i,1,2,i,0,3) | |
createWire(i,1,2,i,0,4) | |
createWire(i,0,2,i,0,3) | |
createWire(i,0,2,i,0,4) | |
createBlock(i,0,5+bits,2) | |
createBlock(i,0,6+bits,3) | |
createWire(i,0,3,i,0,6+bits) | |
#print(i+1,bits-i) | |
if i>0: | |
createWire(i-1,0,5+bits,i,0,6+bits) | |
createWire(i,0,4,i,0,5+bits) | |
createBlock(-2,0,0,5) | |
createBlock(-2,1,0,5) | |
createBlock(-1,0,2,2) | |
createBlock(-1,1,2,2) | |
createWire(-1,1,2,-1,0,2) | |
createWire(-1,0,2,0,0,bits+6) | |
for i in range(bits): | |
for i in range(i2): | |
createBlock(bits-i-1,0,4+i2,1) | |
createWire(bits-i-1,0,4+i2,bits-i-1,0,5+bits) | |
i2+=1 | |
if i>0: | |
for j in range(i): | |
createWire(bits-i-1,0,4,bits-j-1,0,i+4) | |
for i in range(bits): | |
for x in range(i+1): | |
for y in range(bits-i): | |
createWire(bits-i-1,0,3,bits-x-1,0,y+i+5) | |
createWire(-1,0,2, i,0,bits+4) | |
createWire(-1,1,2,i,1,2) | |
createWire(-2,0,0,-1,0,2) | |
createWire(-2,1,0,-1,1,2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hcm2py import * | |
bits = 8 | |
shouldWrap = True | |
wrapLength = 16 | |
wrapDist=1 | |
for i in range(bits): | |
createBlock(0, 0, i, 2) | |
createBlock(1, 0, i, 0) | |
createWireIndex(index_counter - 2, index_counter - 1) | |
for j in range(1 << bits): | |
newWrapDist=wrapDist+1 | |
if shouldWrap: | |
createBlock(3 + (j // wrapLength)*newWrapDist, 0, j*newWrapDist - (j // wrapLength * wrapLength*newWrapDist), 1) | |
else: | |
createBlock(3, 0, j, 1) | |
binary = format(j, f'0{bits}b') | |
for num, bit in enumerate(binary): | |
if bit == '0': | |
createWire(1, 0, num, 3 + (j // wrapLength)*newWrapDist, 0, j*2 - (j // wrapLength * wrapLength*newWrapDist)) | |
else: | |
createWire(0, 0, num, 3 + (j // wrapLength)*newWrapDist, 0, j*2 - (j // wrapLength * wrapLength*newWrapDist)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageDraw, ImageFont | |
from hcm2py import * | |
font_path = "neudeutsch.ttf" # have to have a .ttf file | |
text = input("Enter the text: ") | |
image = Image.new('RGB', (300, 100), 'white') | |
draw = ImageDraw.Draw(image) | |
font_size = 50 | |
font = ImageFont.truetype(font_path, size=font_size) | |
x, y = 10, 50 | |
for char in text: | |
char_mask = font.getmask(char) | |
char_width, char_height = char_mask.size | |
for i in range(char_width): | |
for j in range(char_height): | |
if char_mask.getpixel((i, j)): | |
createBlock(x + i, y + (y-j), 0, 5) | |
x += char_width + 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hcm2py import * | |
frames = [ | |
[[5, 5, 5], [5, 6, 5], [5, 7, 5], [4, 5, 5], [6, 5, 5]], | |
[[5, 5, 5], [5, 6, 5], [5, 7, 5], [4, 5, 6], [6, 5, 4]], | |
[[5, 5, 5], [5, 6, 5], [5, 7, 5], [5, 5, 6], [5, 5, 4]], | |
[[5, 5, 5], [5, 6, 5], [5, 7, 5], [6, 5, 6], [4, 5, 4]], | |
[[5, 5, 5], [5, 6, 5], [5, 7, 5], [6, 5, 5], [4, 5, 5]] | |
] | |
width = 10 | |
length = 10 | |
height = 10 | |
tickspeed =5 | |
for w in range(width): | |
for l in range(length): | |
for h in range(height): | |
createBlock(w,h+1,l,6,[175,175,175]) | |
for w in range(width): | |
for l in range(length): | |
createBlock(w,0,l,14) | |
for index, frame in enumerate(frames): | |
for j in range(tickspeed): | |
createBlock(-3 - index, 0, j,2) | |
if j>0: | |
createWireIndex(index_counter-2,index_counter-1) | |
if index>0 and j==0: | |
createWireIndex(index_counter-2,index_counter-1) | |
for voxel in frame: | |
createWire(-3-index,0,j,voxel[0],voxel[1],voxel[2]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hcm2py import * | |
ladderlength = 100 | |
targetblock = 4 | |
for i in range(ladderlength): | |
y = i*2 | |
createBlock(0,y,0,targetblock) | |
createBlock(0,y+1,0,targetblock) | |
createBlock(0,y+1,1,targetblock) | |
createBlock(0,y+1,2,targetblock) | |
createBlock(0,y+1,3,targetblock) | |
createBlock(0,y+1,4,targetblock) | |
createBlock(0,y,4,targetblock) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
from tkinter import filedialog | |
from PIL import Image | |
from hcm2py import * | |
def open_image(scale): | |
file_path = filedialog.askopenfilename() | |
if file_path: | |
image = Image.open(file_path) | |
width, height = image.size | |
new_width, new_height = int(width // scale), int(height // scale) | |
resized_image = image.resize((new_width, new_height)) | |
pixel_data = list(resized_image.getdata()) | |
for y in range(new_height - 1, -1, -1): | |
for x in range(new_width): | |
pixel_index = y * new_width + x | |
if pixel_index < len(pixel_data): | |
pixel = pixel_data[pixel_index] | |
createBlock(x, new_height - 1 - y, 0, 14, [pixel[0], pixel[1], pixel[2]]) | |
open_image(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hcm2py import * | |
bits = 4 | |
for i in range(bits): | |
createBlock(0, 0, i, 2) | |
createBlock(1, 0, i, 0) | |
createWireIndex(index_counter - 2, index_counter - 1) | |
for i in range(bits): | |
createBlock(0, 0, i + bits + 1, 2) | |
createBlock(1, 0, i + bits + 1, 0) | |
createWireIndex(index_counter - 2, index_counter - 1) | |
createBlock(0, 0, bits*2+2, 2) | |
createBlock(0, 0, -2, 2) | |
for z in range(1 << bits): | |
for y in range(1 << bits): | |
createBlock(6, y, z, 1) | |
createBlock(7, y, z, 1) | |
createBlock(8, y, z, 5) | |
createBlock(9, y, z, 6, [155, 155, 155]) | |
createWireIndex(index_counter - 2, index_counter - 1) | |
createWireIndex(index_counter - 2, index_counter - 3) | |
createWire(0, 0, -2, 7, y, z) | |
createWireIndex(index_counter - 3, index_counter - 2) | |
createWireIndex(index_counter - 4, index_counter - 2) | |
# Convert binary representation of z and y to lists of integers | |
binx = [int(bit) for bit in bin(z)[2:].zfill(bits)] | |
biny = [int(bit) for bit in bin(y)[2:].zfill(bits)] | |
# Create wires based on binary representation | |
for a in range(bits): | |
createWire(binx[a], 0, a, 6, y, z) | |
createWire(biny[a], 0, a + bits+1, 6, y, z) | |
createWire(0, 0, bits*2+2,6, y, z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hcm2py import * | |
length = 8 | |
distancing = 1 | |
for i in range(length): | |
createBlock(0, 0, i * (distancing + 1), 2) | |
createBlock(2, 0, i * (distancing + 1), 2) | |
createBlock(3, 0, i * (distancing + 1), 3) | |
createBlock(4, 0, i * (distancing + 1), 1) | |
createBlock(9, 0, i * (distancing + 1), 6, [155, 155, 155]) | |
createWireIndex(index_counter - 5, index_counter - 3) | |
createWireIndex(index_counter - 4, index_counter - 3) | |
createWireIndex(index_counter - 5, index_counter - 2) | |
createWireIndex(index_counter - 4, index_counter - 2) | |
createWireIndex(index_counter - 3, index_counter - 1) | |
if i > 0: | |
createBlock(5, 0, i * (distancing + 1), 1) | |
createBlock(6, 0, i * (distancing + 1), 3) | |
createWire(4, 0, (i - 1) * (distancing + 1), 3, 0, i * (distancing + 1)) | |
createWire(6, 0, i * (distancing + 1), 5, 0, i * (distancing + 1)) | |
createWire(0, 0, i * (distancing + 1), 6, 0, i * (distancing + 1)) | |
createWire(2, 0, i * (distancing + 1), 6, 0, i * (distancing + 1)) | |
if i == 1: | |
createWire(4,0,(i-1)*(distancing+1),5,0,i*(distancing+1)) | |
if i > 1: | |
createBlock(7, 0, i * (distancing + 1), 2) | |
createWire(7, 0, i * (distancing + 1), 5, 0, i * (distancing + 1)) | |
createWire(5, 0, (i - 1) * (distancing + 1), 3, 0, i * (distancing + 1)) | |
createWire(4, 0, (i - 1) * (distancing + 1), 7, 0, i * (distancing + 1)) | |
createWire(5, 0, (i - 1) * (distancing + 1), 7, 0, i * (distancing + 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
any features/requests can go in the comments, i encourage it