Created
April 9, 2021 17:12
-
-
Save brandonhs/0e6474ea7f19c345bfbbc0b54aa12e29 to your computer and use it in GitHub Desktop.
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
# ------------------------------------------ | |
# | |
# Project: Parking System | |
# Author: VEX | |
# Created: Brandon Stevens | |
# Description: Parking Space System | |
# | |
# ------------------------------------------ | |
from vexcode import * | |
from math import * | |
import os | |
# cause python has no sign function? | |
def sign(x): | |
if x == 0: | |
return 0 | |
elif x > 0: | |
return 1 | |
elif x < 0: | |
return -1 | |
return x # should never reach here | |
def get_position(): | |
x = location.position(X, MM) | |
y = location.position(Y, MM) | |
return (x,y) | |
def to_coords(pix): | |
x, y = pix | |
return ((x*200)-900,(y*200)-900) | |
def from_coords(coords): | |
x, y = coords | |
return ((x+900)/200,(y+900)/200) | |
def length(vec): | |
x, y = vec | |
return sqrt(x**2 + y**2) | |
def degrees(rad): | |
return rad*(180/pi) | |
def create_line(a, b, x_first=True): | |
ax, ay = a | |
bx, by = b | |
path = [ a ]; | |
x = ax | |
y = ay | |
dx = -1 | |
if ax == bx: | |
dx = 0 | |
elif bx > ax: | |
dx = 1 | |
dy = -1 | |
if ay == by: | |
dy = 0 | |
elif by > ay: | |
dy = 1 | |
# allows for user to decide whether horizontal or vertical will get preference | |
horiz = abs(bx - ax) >= abs(by - ay) | |
if x_first: | |
horiz = abs(bx - ax) > abs(by - ay) | |
if dx == 0 or dy == 0: | |
path.append((x,y)) | |
elif horiz: | |
t = (by - ay) / (bx - ax); | |
m = (1 - abs(t)) / 2; | |
while x != bx or y != by: | |
ideal = ay + (x - ax) * t | |
if (ideal - y) * dy >= m: | |
y += dy; | |
else: | |
x += dx | |
path.append((x,y)) | |
else: | |
cotan = (bx - ax) / (by - ay) | |
m = (1 - abs(cotan)) / 2 | |
while x != bx or y != by: | |
ideal = ax + (y - ay) * cotan | |
if (ideal - x) * dx >= m: | |
x += dx | |
else: | |
y += dy | |
path.append((x,y)) | |
path.append(b) # incredibly hacky way to ensure the dest is b | |
return path | |
def generate_path(positions, x_first=True): | |
lines = [ ] | |
start_pos = positions[0] | |
for pos in positions[1:]: | |
line = create_line(start_pos, pos, x_first) | |
lines += line | |
start_pos = pos | |
return lines | |
import itertools | |
def remove_consecutive_duplicates(l): | |
preprocessed_list = [] | |
for x in itertools.groupby(l): | |
preprocessed_list.append(x[0]) | |
return preprocessed_list | |
def dumb_generate_path(lot, positions): | |
lines = [ ] | |
start_pos = positions[0] | |
for pos in positions[1:]: | |
line = create_line(start_pos, pos, False) | |
for coord in line: | |
if lot[9-coord[1]][coord[0]] == 2: | |
brain.print(9-coord[1], coord[0], '\n') | |
line = create_line(start_pos, pos, True) | |
lines += line | |
start_pos = pos | |
return lines | |
async def draw_path(path: [tuple]): | |
# brain.print(f'Processing path: {path}\n') | |
preprocessed_list = [] | |
for x in itertools.groupby(path): | |
preprocessed_list.append(x[0]) | |
path = preprocessed_list | |
x, y = get_position() | |
a = 0 | |
for pos in path: | |
px, py = to_coords(pos) | |
dx = px - x | |
dy = py - y | |
if px == x and py == y: | |
pen.move(DOWN) | |
a = atan2(dx, dy) | |
drivetrain.turn_to_heading(degrees(a), DEGREES) | |
l = length((dx,dy)) | |
#brain.print(l) | |
#brain.new_line() | |
drivetrain.drive_for(FORWARD, l, MM) | |
x, y = get_position() | |
pen.move(DOWN) | |
pen.move(UP) | |
async def dumb_draw_path(lot, path: [tuple]): | |
brain.print(f'Processing path: {path}\n') | |
preprocessed_list = [] | |
for x in itertools.groupby(path): | |
preprocessed_list.append(x[0]) | |
path = preprocessed_list | |
x, y = get_position() | |
a = 0 | |
for pos in path: | |
px, py = to_coords(pos) | |
dx = px - x | |
dy = py - y | |
if px == x and py == y: | |
pen.move(DOWN) | |
wx, wy = (from_coords((px, py))) | |
wx = int(wx) | |
wy = int(wy) | |
brain.print(lot[9-wy][wx]) | |
if lot[wy][wx] != 2: | |
a = atan2(dx, dy) | |
drivetrain.turn_to_heading(degrees(a), DEGREES) | |
l = length((dx,dy)) | |
brain.new_line() | |
drivetrain.drive_for(FORWARD, l, MM) | |
else: | |
drivetrain.drive_for(FORWARD, 200, MM) | |
x, y = get_position() | |
pen.move(DOWN) | |
pen.move(UP) | |
def generate_spiral(center, max_value): | |
path = [] | |
cx, cy = center | |
d = UP | |
i = 1 | |
j = True | |
while i <= max_value: | |
path.append((cx, cy)) | |
if d == UP: | |
cy += i | |
d = RIGHT | |
elif d == DOWN: | |
cy -= i | |
d = LEFT | |
elif d == LEFT: | |
cx -= i | |
d = UP | |
elif d == RIGHT: | |
cx += i | |
d = DOWN | |
if j: | |
j = False | |
else: | |
i += 1 | |
j = True | |
return path | |
def home(): | |
x, y = get_position() | |
px, py = to_coords((0,0)) | |
dx = px-x | |
dy = py-y | |
a = atan2(dx, dy) | |
l = length((dx,dy)) | |
drivetrain.turn_to_heading(degrees(a), DEGREES) | |
drivetrain.drive_for(FORWARD, l, MM) | |
# A * | |
class Node(): | |
def __init__(self, parent=None, position=None): | |
self.parent = parent | |
self.position = position | |
self.g = 0 | |
self.h = 0 | |
self.f = 0 | |
def A_Star(grid, start, end): | |
start_node = Node(None, start) | |
start_node.g = start_node.h = start_node.f = 0 | |
end_node = Node(None, end) | |
end_node.g = end_node.h = end_node.f = 0 | |
open_list = [] | |
closed_list = [] | |
open_list.append(start_node) | |
while len(open_list) > 0: | |
js.eval('postMessage({command: "WorkerAlive"})') # trick the system into thinking we havent frozen | |
current_node = open_list[0] | |
current_index = 0 | |
for index, item in enumerate(open_list): | |
if item.f < current_node.f: | |
current_node = item | |
current_index = index | |
open_list.pop(current_index) | |
closed_list.append(current_node) | |
if current_node.position == end_node.position: | |
path = [] | |
current = current_node | |
while current is not None: | |
path.append(current.position) | |
current = current.parent | |
return path[::-1] | |
children = [] | |
for new_position in [(0, -1), (0, 1), (-1, 0), (1, 0), (-1, -1), (-1, 1), (1, -1), (1, 1)]: | |
node_position = (current_node.position[0] + new_position[0], current_node.position[1] + new_position[1]) | |
if node_position[0] > (len(grid) - 1) or node_position[0] < 0 or node_position[1] > (len(grid[len(grid)-1]) -1) or node_position[1] < 0: | |
continue | |
if grid[node_position[0]][node_position[1]] == 2: | |
continue | |
new_node = Node(current_node, node_position) | |
children.append(new_node) | |
for child in children: | |
for closed_child in closed_list: | |
if child.position == closed_child.position: | |
continue | |
child.g = current_node.g + 1 | |
child.h = ((child.position[0] - end_node.position[0]) ** 2) + ((child.position[1] - end_node.position[1]) ** 2) | |
child.f = child.g + child.h | |
for open_node in open_list: | |
if child.position == open_node.position and child.g > open_node.g: | |
continue | |
open_list.append(child) | |
import js | |
# PARKING CODE | |
OPEN = 1 | |
FULL = 2 | |
DRIVE = 0 | |
def create_lot(rows, cols): | |
lot = [ ] | |
for i in range(rows): | |
row = [ ] | |
for j in range(cols): | |
if j == 0 or j == cols-1: | |
row.append(DRIVE) | |
else: | |
row.append(FULL) | |
lot.append(row) | |
return lot | |
def get_spot(lot): | |
open_spots = [ ] | |
x, y = from_coords(get_position()) | |
for row in range(len(lot)): | |
for col in range(len(lot[row])): | |
if lot[row][col] == OPEN: | |
open_spots.append((row, col)) | |
min_dist = 10000 | |
spot = (-1, -1) | |
for (row, col) in open_spots: | |
d = length((x-row, y-col)) | |
if d < min_dist: | |
min_dist = d | |
spot = (col, row) | |
return spot | |
# COLOR STUFF :D | |
from js import XMLHttpRequest, Blob | |
import pyodide | |
import json | |
def pull_image(url): | |
data = {"a": 1} | |
req = XMLHttpRequest.new() | |
req.responseType = 'blob' | |
req.open("GET", url, False) | |
req.send() | |
return req.response | |
def set_arbitrary_color(col): | |
js.eval('postMessage({command: "PrintSetColor", color: "' + col + '", brandon: "brandon is best yes :D"})') | |
# lol | |
def gradient_fill(col1, col2, width, height): | |
r1, g1, b1 = col1 | |
r2, g2, b2 = col2 | |
offset = 0 | |
for j in range(0, height, 1): | |
for i in range(int(abs(offset)), width+int(abs(offset)), 1): | |
js.eval('postMessage({command: "WorkerAlive"})') # ensure vexcode doesn't try to shutdown the program (haha another exploit) | |
p = i / float(width+int(abs(offset)) - 1) | |
r = int((1.0-p) * r1 + p * r2 + 0.5) | |
g = int((1.0-p) * g1 + p * g2 + 0.5) | |
b = int((1.0-p) * b1 + p * b2 + 0.5) | |
rgb = (r << 16) | (g << 8) | (b) | |
col = '#' + hex(rgb)[2:].zfill(6) | |
set_arbitrary_color(col) | |
brain.print('█') | |
offset += 0.1 | |
brain.print('\n') | |
def gradient_fillstring(string, col1, col2): | |
r1, g1, b1 = col1 | |
r2, g2, b2 = col2 | |
arr = string.split('\n') | |
arr2 = [] | |
for c in arr: | |
arr2 = list(c) | |
width = len(arr2) | |
for i, a in enumerate(arr2): | |
js.eval('postMessage({command: "WorkerAlive"})') # ensure vexcode doesn't try to shutdown the program (haha another exploit) | |
p = i / float(width - 1) | |
r = int((1.0-p) * r1 + p * r2 + 0.5) | |
g = int((1.0-p) * g1 + p * g2 + 0.5) | |
b = int((1.0-p) * b1 + p * b2 + 0.5) | |
rgb = (r << 16) | (g << 8) | (b) | |
col = '#' + hex(rgb)[2:].zfill(6) | |
set_arbitrary_color(col) | |
brain.print(a) | |
brain.print('\n') | |
def hex_to_rgb(string): | |
arr = list(string) | |
color = [] | |
for x, y in zip(*[iter(arr)]*2): | |
c = x + y | |
color.append(int(c, 16)) | |
return color | |
ROWS = 10 | |
COLS = 10 | |
explanation = ''' \n | |
An Explanation of how this (color thing) works: | |
Vexcode uses a system at its core called pyodide. This system allows for python to be executed in a browser. | |
A feature of the system vexcode uses is the ability for n-way communication between workers and hosts. This | |
is how vexcode is able to communicate with its renderer which renders the robot. | |
Pyodide not only allows for python execution in javascript, but javascript execution in python. Although slightly | |
paradoxical, this feature is how the vexcode python api is able to communicate with the site. An unforseen consequence | |
of this is that not only can the vexcode api communicate with the browser, but so can I. Using the simple code, | |
js.eval('postMessage...etc'), we can send the same commands vexcode does. It took me a little while but I managed to | |
reverse engineer the command system vexcode uses. | |
The following is a list of every command I found: | |
WorkerAlive - Communicates with the system to tell it that the worker is not stuck. This is how I circumvented the requirement for waits in loops | |
PythonReady - Send when the code is ready | |
PythonInitError - An error occured while initializing | |
PythonError - Throws an error which gets printed in the main console | |
PythonRunning - Send when the code is running | |
PythonRunComplete - Sent when the code has completed running | |
UnityCommand - Command sent from the unity engine backend (yes, the game engine) | |
WaitForUnityReady - Honestly I dont know | |
PrintText - print text to the console (literally brain.print) | |
PrintNewLine - Prints a newline | |
PrintSetColor - This is a fun one. This command allows for any color to be set to the brain color. The parameter for this is color. | |
It accepts a hex value, like #FFFFFF | |
PrintClearLines - Clears the console line by line | |
UpdateBraintimer - Updates the internal brain timer | |
PythonVariableValues - Internal command for monitor_variable | |
PythonSensorMonitor - Updates the internal sensor monitor? | |
PythonStopProject - Stops the project''' | |
def main(): | |
brain.clear() | |
global ROWS | |
global COLS | |
global explanation | |
a = ''' | |
const getUrl = (url) => { | |
var req = new XMLHttpRequest(); | |
req.responseType = 'blob'; | |
req.open("GET", url, false); | |
req.send(); | |
return req.response; | |
} | |
const rgbToHex = (r, g, b) => { | |
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); | |
} | |
var w = 43; | |
var h = 76; | |
var canvas = new OffscreenCanvas(w, h); | |
var ctx = canvas.getContext('2d'); | |
var img = getUrl('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAAQABAAD/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAEAAAAAAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCABMACsDASIAAhEBAxEB/8QAGgAAAwEBAQEAAAAAAAAAAAAABwgJCgYEBf/EAC0QAAICAgEEAgICAQMFAAAAAAMEAg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ytQ1ykSJoVtT6SOYgdmWWatNwuSljAUZZ9zBPHERwxGHjDGO0flNyGVyFC09SvKGA047xLKqb48QdFtg61vxr/AL59NPB1KtrHxWriFi3wHaADEjTcn2Qp2N70N7P49f/Z') | |
var blob = img; | |
console.log(blob.type); | |
createImageBitmap(blob, 0, 0, w, h).then((bmp) => { | |
ctx.drawImage(bmp, 0, 0); | |
var imageData = ctx.getImageData(0, 0, w, h); | |
// postMessage({command: 'PrintText', text: imageData.data.toString()}); | |
for (let i = 0; i < w*h*4; i+=4) { | |
let r = imageData.data[i]; | |
let g = imageData.data[i+1]; | |
let b = imageData.data[i+2]; | |
let a = imageData.data[i+3]; | |
let hex = rgbToHex(r, g, b); | |
postMessage({command: "PrintSetColor", color: hex}) | |
postMessage({command: 'PrintText', text: '██'}); | |
if (i % (w*4) == 0 && i != 0) postMessage({command: 'PrintNewLine'}); | |
} | |
}).catch((e) => { | |
console.log(e); | |
}); | |
''' | |
lot = [ | |
[2, 2, 2, 2, 2, 2, 2, 2, 2], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0], | |
[0, 2, 1, 2, 2, 2, 2, 1, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0], | |
[0, 2, 2, 2, 2, 2, 2, 2, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0], | |
[0, 2, 2, 2, 2, 2, 2, 2, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0], | |
[0, 2, 1, 2, 2, 2, 2, 2, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0]] | |
start = (0, 0) | |
# end = (2, 1) | |
prom = js.eval(a) | |
gradient_fill((210, 41, 255), (0, 213, 230), 58, 20) | |
brain.print('\n\n') | |
gradient_fillstring('''\ | |
██████╗░██████╗░░█████╗░███╗░░██╗██████╗░░█████╗░███╗░░██╗ | |
██╔══██╗██╔══██╗██╔══██╗████╗░██║██╔══██╗██╔══██╗████╗░██║ | |
██████╦╝██████╔╝███████║██╔██╗██║██║░░██║██║░░██║██╔██╗██║ | |
██╔══██╗██╔══██╗██╔══██║██║╚████║██║░░██║██║░░██║██║╚████║ | |
██████╦╝██║░░██║██║░░██║██║░╚███║██████╔╝╚█████╔╝██║░╚███║ | |
╚═════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═════╝░░╚════╝░╚═╝░░╚══╝''', (210, 41, 255), (0, 213, 230)) | |
gradient_fillstring('Parking Space Algorithm Using a-star Pathfinding', (255, 0, 0), (255, 0, 255)) | |
brain.print('\n\n') | |
img = pull_image('https://cors-anywhere.herokuapp.com/http://hmg-prod.s3.amazonaws.com/images/dog-puppy-on-garden-royalty-free-image-1586966191.jpg') | |
class LMAO: | |
# the only way to get around vecodes DUMB addition of asyncs to the beginning of every def | |
def __init__(self, x): | |
brain.print(x) | |
canvas = js.OffscreenCanvas.new(256, 256) | |
ctx = canvas.getContext('2d') | |
# import pyodide | |
# prom.then(lambda x: ( | |
# ctx.drawImage(x, 0, 0), | |
# LMAO(ctx.getImageData(0, 0, 256, 256)) | |
# )).catch(lambda e: brain.print(e)) | |
# col = hex_to_rgb('753a88') | |
# gradient_fill(hex_to_rgb('cc2b5e'), col, 58, 20) | |
# gradient_fillstring(explanation, (210, 41, 255), (0, 213, 230)) | |
spot = get_spot(lot[::-1]) | |
path = A_Star(lot[::-1], start, spot) | |
dumb_path = dumb_generate_path(lot, path) | |
await draw_path(dumb_path) | |
# await draw_path(path) | |
# brain.print("Haha! Custom color codes are possible cause I exploited a bug in vexcode vr's main system LMAO.") | |
vr_thread(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment