Skip to content

Instantly share code, notes, and snippets.

View luisdamed's full-sized avatar

Luis Medina luisdamed

View GitHub Profile
@luisdamed
luisdamed / flat_cone_dimensions.py
Last active May 7, 2024 20:43
A simple script that I use to generate arc-deformed images that wrap perfectly around a truncated straight cone shape. Example: vinyl wrapping for a camera lens hood, print image for a latte mug, you get the idea...
# Compute the key dimensions of the flattened surface of a truncated cone
# Use the cone height H, large diameter L and small diamater D to calculate the
# ring sector that wraps around it, given by the parameters:
# P (inner radius), Q (outer radius) and alpha (sector angle)
# check out https://www.templatemaker.nl/en/cone/
# Need to install https://imagemagick.org/ CLI
# Consider using wand (https://github.com/emcconville/wand) for a
# more "pythonic" interface
@luisdamed
luisdamed / gcode_size.py
Created April 21, 2023 22:19
Get the size of a 3D print job from the G-Code. Works for Verbosed G-Code from Prusa Slicer (tested on version 2.5.0+win64)
# Read the details about this on www.makerluis.com/getting-the-size-of-3d-print-from-gcode
def get_max_size(text):
pattern_xy= 'G1.X(\d*.\d*).Y(\d*.\d*).E\d*.\d*.;.perimeter'
pattern_z = 'G1.Z(\d*.\d*).F\d*.\d*.;.restore.layer.Z'
pattern_width = ';TYPE:Perimeter\n;WIDTH:(\d*.\d*).'
matches_xy = re.findall(pattern_xy, text)
x = list(list(zip(*matches_xy))[0])
y = list(list(zip(*matches_xy))[1])
@luisdamed
luisdamed / gcode_model_size.py
Last active April 10, 2023 14:54
Python script to get the maximum dimensions of a gcode file for 3D printing. Works for gcode created from PrusaSlicer, with verbose enabled
# %% Import libraries
import os
import tkinter as tk
from tkinter import filedialog
import re
class App(tk.Frame):
def __init__(self, master):
@luisdamed
luisdamed / sl_customization.m
Created April 7, 2023 18:23
Create custom command for Simulink, allowing you to call addblocks.m from the Toolbox or using a combination of keys. See the explanation: https://www.makerluis.com/3-keyboard-macros-to-speed-up-your-simulink-workflow/
function sl_customization(cm)
cm.addCustomMenuFcn('Simulink:ToolsMenu', @getMyMenuItems);
end
function schemaFcns = getMyMenuItems(~)
schemaFcns = {@autoAddBlocks};
end
function schema = autoAddBlocks(~)
@luisdamed
luisdamed / batchgoto.m
Created April 7, 2023 13:31
Batch-create matching Simulink From blocks based on the current selection of Goto blocks. Read the article I wrote about this: https://www.makerluis.com/3-keyboard-macros-to-speed-up-your-simulink-workflow/
subsystem = gcs;
goto_objects = Simulink.findBlocksOfType(selection, 'Goto', 'Selected', 'on');
for i_block = 1:numel(goto_objects)
tag = get_param(goto_objects(i_block), 'Gototag');
origin_position = get_param(goto_objects(i_block), 'Position');
dest_block = [subsystem '/Goto'];
dest_position = origin_position + [200 0 200 0];
handle = add_block('built-in/from', dest_block, 'MakeNameUnique','on');
set_param(handle, 'Gototag', tag, 'Position', dest_position);
@luisdamed
luisdamed / addblocks.m
Last active April 7, 2023 13:27
Batch-create matching Simulink blocks based on the current selection. Read the article I wrote about this: https://www.makerluis.com/3-keyboard-macros-to-speed-up-your-simulink-workflow/
subsystem = gcs; % Get current system
objects = gsb; % Get selected blocks
% Alternative: find_system(gcs,'Selected','on')
for i_block = 1:numel(objects)
% Add Outports and connected lines for From blocks
if strcmp(get_param(objects{i_block}, 'BlockType'), 'From')
% Get the tag and position of the From block
tag = get_param(objects{i_block}, 'Gototag');
@luisdamed
luisdamed / Macropad_3x3_test.ino
Created March 17, 2023 07:10
A simple code to test the connections of a 3x3 macropad based on the Arduino Pro Micro
#include <Mouse.h>
#include <Keyboard.h>
// Defining each pin, with a unique name
#define KEY0 0
#define KEY1 1
#define KEY2 2
#define KEY3 3
#define KEY4 4
This file has been truncated, but you can view the full file.
<html>
<head><meta charset="utf-8" /></head>
<body>
<script type="text/javascript">!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Plotly=t()}}((function(){return function t(e,r,n){function i(o,s){if(!r[o]){if(!e[o]){var l="function"==typeof require&&require;if(!s&&l)return l(o,!0);if(a)return a(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var u=r[o]={exports:{}};e[o][0].call(u.exports,(function(t){return i(e[o][1][t]||t)}),u,u.exports,t,e,r,n)}return r[o].exports}for(var a="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);return i}({1:[function(t,e,r){"use strict";var n=t("plotly.js/src/components/annotations"),i=t("plotly.js");n.add=function(t){var e=t._fullLayout.annotations.length;i.relayout(t,"annotations["+e+"]","ad
This file has been truncated, but you can view the full file.
<html>
<head><meta charset="utf-8" /></head>
<body>
<div> <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>
<script type="text/javascript">/**
* plotly.js v2.14.0
* Copyright 2012-2022, Plotly, Inc.
* All rights reserved.
* Licensed under the MIT license
*/
@luisdamed
luisdamed / PieChart_Python_Pygal_Thingiverse_Proportion_Makes_vs_Things.svg
Created March 3, 2023 05:41
Pie chart showing the average number of makes for the models in each category of Thingiverse as of October 2022
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.