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 numpy as np | |
import pyglet | |
def draw_points(points, format="v2f"): | |
pyglet.graphics.draw( | |
len(points), | |
pyglet.gl.GL_POINTS, | |
(format, tuple([x for p in points for x in p])) | |
) |
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 numpy as np | |
from scipy import signal | |
from matplotlib import animation, pyplot as plt | |
def animate(i): | |
global board | |
neighbors = signal.correlate2d(board, kernel, mode="same") | |
board = ((board == 1) & ((neighbors == 2) | (neighbors == 3))) | ((board == 0) & (neighbors == 3)) | |
image.set_data(board) | |
return image |
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
all: | |
g++ main.cpp -o main -std=c++11 `sdl2-config --cflags --libs` | |
./main |
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
const client = require('socket.io-client')('http://localhost:5000') | |
const siof = require('./socket.io-file') | |
client.on('connect', () => { | |
console.log('connected to server') | |
client.once('ready', () => { | |
const metadata = { filename: 'file2.pdf' } // filename on the receiving end | |
siof(client).emit('file', 'filepath/to/file.pdf', metadata, (sent, total) => { | |
const percentage = (100 * sent / total).toFixed(2) | |
console.log(`${percentage}%`) |
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 numpy as np | |
import matplotlib.pyplot as plt | |
N = 100 # in how much sub pieces we should break a 1sec interval | |
T = 15 # total duration of the simulation | |
dt = 1 / N # dt | |
g = 9.81 # acceleration of gravity | |
L = 1 # pendulum rope length | |
k = 0.8 # air resistance coefficient | |
m = 1 # mass of the pendulum |
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 numpy as np | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
I = 300 # samples per class | |
N = 3 # features | |
J = 2 # clusters | |
mean_true = np.random.randint(-20, 20, (J, N)) | |
variance_true = np.array([np.identity(N) * np.random.randint(1, 20, N) for j in range(J)]) |
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 numpy as np | |
import matplotlib.pyplot as plt | |
def normalize(vector): | |
return vector / np.linalg.norm(vector) | |
def reflected(vector, axis): | |
return vector - 2 * np.dot(vector, axis) * axis | |
def sphere_intersect(center, radius, ray_origin, ray_direction): |
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
# global variable along with width, height, etc. | |
max_depth = 3 | |
# everything that follows is inside the double for loop | |
color = np.zeros((3)) | |
reflection = 1 | |
for k in range(max_depth): | |
nearest_object, min_distance = # ... | |
# ... |
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
def reflected(vector, axis): | |
return vector - 2 * np.dot(vector, axis) * axis |
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
# ... | |
if is_shadowed: | |
break | |
# RGB | |
illumination = np.zeros((3)) | |
# ambiant | |
illumination += nearest_object['ambient'] * light['ambient'] |