Skip to content

Instantly share code, notes, and snippets.

View esmitt's full-sized avatar
🐢
As fast as a Pentium I

esmitt esmitt

🐢
As fast as a Pentium I
View GitHub Profile
@esmitt
esmitt / template.html
Last active August 29, 2015 13:57
This is a basic template to start drawing in the canvas defined in canvas2D and using 2 method to drawing (Set Pixel and Javascript).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>This is my test</title>
<style>
body
{
background: #eeeeee;
}
@esmitt
esmitt / drawFigures.js
Last active August 29, 2015 13:57
This shows a few functions to draw over a Canvas HTML5. The selection is about using a SetPixel method or Javascript native rendering method for a simple line.
/// @param context the context of the canvas
/// @param color color of the grid in string format
/// @param size size of the quads or separation between them
/// @param tickness is the tickness of lines in the grid
function drawGrid(context, color, size, tickness)
{
context.save();
context.strokeStyle = color;
context.lineWidth = tickness;
for (var i = size; i < context.canvas.width; i += size)
@esmitt
esmitt / CGLSLProgram.cpp
Last active August 29, 2015 13:57
A function part of CGLSLProgram class (any class that to manage GLSL program/shaders in GLSL) to print the active Uniforms and Attributes variables in our shaders.
// We assume that the location of GLSL program is stored in the variable <code>m_uIdProgram</code> as an unsigned int
// #include <iomanip> is necessary to use of setw (text formatting)
void CGLSLProgram::showDebugging()
{
GLint iMaxLength, iNumAttrib, iNumUniform;
glGetProgramiv(m_uIdProgram, GL_ACTIVE_ATTRIBUTES, &iNumAttrib);
glGetProgramiv(m_uIdProgram, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &iMaxLength);
GLchar* name = new GLchar[iMaxLength];
GLint written, size, location;
GLenum type;
@esmitt
esmitt / bresenham.cs
Last active January 23, 2017 15:07
Algorithm of the middle point (2D Bresenham) to draw a line, where points are printing in console.
/// <summary>
/// Algorithm of the middle point, where points are printing in console
/// Works independently of the position of both points. Also is more easy using Point from Drawing.
/// </summary>
/// <param name="x1">X value of the 1st point</param>
/// <param name="y1">Y value of the 1st point</param>
/// <param name="x2">X value of the 2nd point</param>
/// <param name="y2">Y value of the 2nd point</param>
static void Bresenham(int x1, int y1, int x2, int y2)
{
@esmitt
esmitt / fib.cpp
Created October 18, 2017 11:18
Fibonacci in C++
#include <iostream>
#include <functional>
int main()
{
std::function<int(int)> fib = [&fib](int n) {return n < 2 ? 1 : fib(n-1) + fib(n-2);};
std::cout << fib(9) << std::endl;
return EXIT_SUCCESS;
}
@esmitt
esmitt / primtMST.cpp
Last active November 13, 2017 16:25
prim algorithm for some Graph structure
// iPair ==> Integer Pair
typedef std::pair<int, int> iPair;
std::vector<int> Graph::primtMST(int src) // Taking vertex 0 as source
{
// Create a priority queue to store vertices that
// are being preinMST. This is weird syntax in C++.
// Refer below link for details of this syntax
// http://geeksquiz.com/implement-min-heap-using-stl/
std::priority_queue< iPair, std::vector <iPair>, std::greater<iPair> > pq;
@esmitt
esmitt / subdivide.cpp
Created November 20, 2017 10:09
Loop subdivision algorithm for an input OBJ. the output is a subdivide mesh
// Just for testing, a Loop subdivision algorithm to the input OBJ
// the output is the subdivide mesh
vtkSmartPointer<vtkPolyData> Subdivide(vtkSmartPointer<vtkPolyData> reader)
{
// Subdivision filters only work on triangles
vtkSmartPointer<vtkTriangleFilter> triangles = vtkSmartPointer<vtkTriangleFilter>::New();
triangles->SetInputData(reader);
triangles->Update();
vtkSmartPointer<vtkPolyData> originalMesh = triangles->GetOutput(); // this is the original mesh actually
@esmitt
esmitt / mandelbrot.cpp
Created December 3, 2017 19:08
Single mandelbrot drawing function in C++ using GLUT
#include <stdlib.h>
#include "GL/glut.h"
#include <iostream>
#pragma comment(lib, "glut32.lib")
#define WINDOW_TITLE "Project"
using namespace std;
const float ANGLE = 45.f;
const float FOV = 70.f;
const float NCP = 0.001f;
@esmitt
esmitt / DrawPanel.java
Created December 3, 2017 20:02
Class part of a complete project. This contains the scan-line algorithm to fill a polygon
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.*;
public class DrawPanel extends javax.swing.JPanel {
@esmitt
esmitt / TextGenOnImage.py
Created December 5, 2017 17:04
Generates a single image with white background with a word (for testing purposes) using PIL
from PIL import Image, ImageDraw, ImageFont
from random import randint
text = 'pendejo'
nimages = 20
folder = 'output/'
sizeX = 600
sizeY = 200
image = Image.new("RGBA", (600,150), (255,255,255))