Skip to content

Instantly share code, notes, and snippets.

View kevingduck's full-sized avatar

Kevin Duck kevingduck

  • Expel
View GitHub Profile
@kevingduck
kevingduck / 3D Plot Demo.py
Created August 16, 2017 06:24
3D Plot Demo.py
# coding: utf-8
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25)
@kevingduck
kevingduck / Histogram Demo.py
Created August 16, 2017 06:26
Histogram Demo.py
# coding: utf-8
'''
Demo of the histogram (hist) function with a few features.
In addition to the basic histogram, this demo shows a few optional features:
* Setting the number of data bins
* The ``normed`` flag, which normalizes bin heights so that the integral of the histogram is 1. The resulting histogram is a probability density.
* Setting the face color of the bars
* Setting the opacity (alpha value).
@kevingduck
kevingduck / Motion Plot.py
Created August 16, 2017 06:26
Motion Plot.py
'''This script records your device's orientation (accelerometer data) for 5 seconds, and then renders a simple plot of the gravity vector, using matplotlib.'''
import motion
import matplotlib.pyplot as plt
from time import sleep
import console
def main():
console.alert('Motion Plot', 'When you tap Continue, accelerometer (motion) data will be recorded for 5 seconds.', 'Continue')
@kevingduck
kevingduck / Path Demo.py
Created August 16, 2017 06:28
Path Demo.py
# coding: utf-8
# Demo of a PathPatch object.
import matplotlib.path as mpath
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
@kevingduck
kevingduck / Pie Chart Demo.py
Created August 16, 2017 06:28
Pie Chart Demo.py
# coding: utf-8
'''
Demo of a basic pie chart plus a few additional features.
In addition to the basic pie chart, this demo shows a few optional features:
* slice labels
* auto-labeling the percentage
* offsetting a slice with "explode"
* custom start angle
@kevingduck
kevingduck / Simple Plot.py
Created August 16, 2017 06:28
Simple Plot.py
# coding: utf-8
from pylab import *
t = arange(0.0, 2.0, 0.01)
s = sin(2*pi*t)
plot(t, s)
xlabel('time (s)')
ylabel('voltage (mV)')
title('About as simple as it gets, folks')
@kevingduck
kevingduck / Subplot Demo.py
Created August 16, 2017 06:29
Subplot Demo.py
# coding: utf-8
# Simple demo with multiple subplots.
import numpy as np
import matplotlib.pyplot as plt
x1 = np.linspace(0.0, 5.0)
x2 = np.linspace(0.0, 2.0)
@kevingduck
kevingduck / Calculator.py
Created August 16, 2017 06:30
Calculator.py
# coding: utf-8
from __future__ import division
import ui
import clipboard
from console import hud_alert
shows_result = False
def button_tapped(sender):
@kevingduck
kevingduck / Image Effects.py
Created August 16, 2017 06:30
Image Effects.py
'''
A couple of simple image filter demos using PIL/Pillow.
'''
from PIL import Image, ImageOps, ImageFilter
from PIL.Image import BILINEAR
from math import sqrt, sin, cos, atan2
import dialogs
import photos
@kevingduck
kevingduck / Random MIDI Melody.py
Created August 16, 2017 06:31
Random MIDI Melody.py
#! python2
# NOTE: The first line in this script specifies that it should always be run using Python 2.7.
# The `midiutil` module is currently not available for Python 3.
'''Generates a MIDI file with 12 random notes in C major, using the midiutil module. The instrument is also picked randomly. The result is then played with the sound.MIDIPlayer class.
If nothing happens, make sure that your device isn't muted.
'''
from midiutil.MidiFile import MIDIFile