Skip to content

Instantly share code, notes, and snippets.

View samneggs's full-sized avatar

Sam samneggs

View GitHub Profile
@samneggs
samneggs / flood_fill.py
Last active December 12, 2021 00:28
Pi Pico Flood Fill and Line Fill
from LCD_3inch5 import LCD_3inch5
from machine import Pin, UART
import framebuf
from time import sleep_ms, sleep_us, ticks_diff, ticks_us, sleep
from micropython import const
import array
from usys import exit
import gc
from random import randint
@samneggs
samneggs / rotate_asm.py
Created December 12, 2021 21:26
Pi Pico rotate bytearray for framebuffer in inline assembly
SCALE3=const(13)
CTL_SIN=const(0)
CTL_COS=const(4)
CTL_WIDTH=const(8)
CTL_HEIGHT=const(12)
CTL_DEG=const(16)
rot_control = array.array('i',[0,0,MAXSCREEN_X,MAXSCREEN_Y,1]) # sin,cos,w,h,deg
#rotate_asm(source,destination,rot_control)
#example:
#rot_control[4]=degrees # 0-359
@samneggs
samneggs / fill_triangle.py
Created December 13, 2021 01:24
Flying Filled Triangle in Viper with Assembly Conversion (core routine)
@micropython.viper
def fill_triangle(obj_source, width_source:int,color_offset:int, y_start:int):
source=ptr16(obj_source)
c=ptr16(color_l2)
y=y_start-2
start_inside = 0
while y:
x=width_source
inside=0
erase = 0
@samneggs
samneggs / circle.py
Created December 15, 2021 04:57
Fast Circle Using Viper Pointers
@micropython.viper
def circle(x0:int, y0:int, radius:int):
# From Adafruit GFX Arduino library
# Circle drawing function. Will draw a single pixel wide circle with
# center at x0, y0 and the specified radius.
# screen is bytearray (240x240)
screen_addr=ptr16(screen)
color=0xffff
f = 1 - radius
ddF_x = 1
@samneggs
samneggs / fade.py
Created December 15, 2021 05:15
Appends array with 32 colors between inputs color1 and color2
def fade(input_color1, input_color2):
color1=input_color1<<8 | input_color1>>8 # byte swap to normal RBG565
red1 =color1>>11& 0b11111 # extract red #13
green1=color1>>6 & 0b11111 # extract green
blue1 =color1 & 0b11111 # extract blue
color2=input_color2<<8 | input_color2>>8 # byte swap
red2 =color2>>11& 0b11111 # extract red
green2=color2>>6 & 0b11111 # extract green
blue2 =color2 & 0b11111 # extract blue
inc_red =(red2- red1)/31 # find increment step
@samneggs
samneggs / fastline.py
Created December 27, 2021 21:20
Line function in MicroPython Viper and Inline Assembly
from LCD_3inch5 import LCD_3inch5
import framebuf
from math import sin,cos,pi, radians
from time import sleep_ms, sleep_us, ticks_diff, ticks_us, sleep
from micropython import const
from uctypes import addressof
import array
from usys import exit
import gc
@samneggs
samneggs / textures.py
Created January 2, 2022 02:09
Plane Deformations with texture bitmaps - Pi Pico in MicroPython
# Based on routines by Inigo Quilez
# https://iquilezles.org/
from LCD_3inch5 import LCD_3inch5
import framebuf
import math
from time import sleep_ms, sleep_us, ticks_diff, ticks_us, sleep
from micropython import const
import array
from usys import exit
@samneggs
samneggs / noisematrix.py
Created January 8, 2022 06:11
Pseudo Perlin noise mapped onto 3D matrix in MicroPython
from LCD_3inch5 import LCD_3inch5
from machine import Pin
import framebuf
from time import sleep_ms, sleep_us, ticks_diff, ticks_us, sleep
from micropython import const
import array
from usys import exit
import gc
from random import randint
from math import sin,cos,pi, radians
@samneggs
samneggs / cubes.py
Created January 16, 2022 23:08
Solid spinning cubes on textured background
from LCD_3inch5 import LCD_3inch5
from machine import Pin
import framebuf
from time import sleep_ms, sleep_us, ticks_diff, ticks_us, sleep
from micropython import const
import array
from usys import exit
import gc
#from random import randint
from math import sin,cos,pi,radians
@samneggs
samneggs / print_num_asm.py
Created January 30, 2022 23:33
Print number to bitmap bytearray in assembly
from LCD_3inch5 import LCD_3inch5
from machine import Pin, SPI, PWM, WDT
import framebuf
from time import sleep_ms, sleep_us, ticks_diff, ticks_us, sleep
from micropython import const
import array
from usys import exit
import gc
from math import sin,cos,pi,radians,sqrt,tan