This file contains hidden or 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
% | |
% Código LaTeX usando pacotes tikz plotando gráfico com funções admissiveis | |
% Por Eduardo Oliveira (https://eduardojm.github.io) | |
% | |
\documentclass{standalone} | |
\usepackage{tikz} | |
\usepackage{tkz-fct} | |
\begin{document} |
This file contains hidden or 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
function buildEdges(vertices) { | |
const edges = []; | |
if (vertices.length < 3) { | |
console.error("Only polygons supported."); | |
return edges; | |
} | |
for (let i = 0; i < vertices.length; i++) { | |
const a = vertices[i]; | |
let b = vertices[0]; | |
if (i + 1 < vertices.length) { |
This file contains hidden or 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
function createPolygon(vertices) { | |
const polygon = {}; | |
polygon.vertices = vertices; | |
polygon.edges = buildEdges(vertices); | |
polygon.projectInAxis = function(x, y) { | |
} | |
polygon.testWith = function (otherPolygon) { | |
} |
This file contains hidden or 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
polygon.offset = function(dx, dy) { | |
for (let i = 0; i < polygon.vertices.length; i++) { | |
polygon.vertices[i] = { | |
x: polygon.vertices[i].x + dx, | |
y: polygon.vertices[i].y + dy, | |
}; | |
} | |
}; |
This file contains hidden or 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
polygon.render = function(context, color) { | |
context.strokeStyle = color; | |
context.beginPath(); | |
context.moveTo( | |
polygon.vertices[0].x, | |
polygon.vertices[0].y | |
); | |
for (let i = 1; i < polygon.vertices.length; i++) { | |
context.lineTo( | |
polygon.vertices[i].x, |
This file contains hidden or 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
polygon.projectInAxis = function(x, y) { | |
let min = 10000000000; | |
let max = -10000000000; | |
for (let i = 0; i < polygon.vertices.length; i++) { | |
let px = polygon.vertices[i].x; | |
let py = polygon.vertices[i].y; | |
var projection = (px * x + py * y) / (Math.sqrt(x * x + y * y)); | |
if (projection > max) { | |
max = projection; | |
} |
This file contains hidden or 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
polygon.testWith = function (otherPolygon) { | |
// get all edges | |
const edges = []; | |
for (let i = 0; i < polygon.edges.length; i++) { | |
edges.push(polygon.edges[i]); | |
} | |
for (let i = 0; i < otherPolygon.edges.length; i++) { | |
edges.push(otherPolygon.edges[i]); | |
} | |
// build all axis and project |
This file contains hidden or 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 canvas = document.getElementById('game'); | |
const context = canvas.getContext('2d'); | |
const polygons = []; | |
const polygonsColors = [ 'red', 'blue', 'green', 'pink', 'purple', 'cyan' ]; | |
polygons.push(createPolygon([ | |
{ x: 50, y: 50 }, | |
{ x: 100, y: 50 }, | |
{ x: 100, y: 150 }, | |
{ x: 50, y: 150 }, |
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<canvas id="game" width="512" height="512"></canvas> |
This file contains hidden or 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 React, { useState } from 'react'; | |
import { StatusBar } from 'expo-status-bar'; | |
import { StyleSheet, Text, View } from 'react-native'; |
OlderNewer