Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
✅
‏‏‎

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / generateGradient.js
Last active December 24, 2022 15:32
Javascript Generate Gradient Image
// chatGPT
// Here is a simple function that generates a gradient PNG image from 8 colors:
function generateGradient(colors) {
// Create an image object
var img = new Image();
// Create a canvas element
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
@unitycoder
unitycoder / main.js
Created December 24, 2022 14:39 — forked from woxtu/main.js
Twitter インプレッション アクセスカウンター
const id = "kiriban-fuminige-kinshi";
const conversions = [
{ unit: "K", rate: 1000 },
{ unit: "M", rate: 1000000 },
{ unit: "B", rate: 1000000000 },
{ unit: "万", rate: 10000 },
];
function run(target) {
@unitycoder
unitycoder / CubicSpline.cs
Created December 22, 2022 22:31
CubicSpline in c#
// by chatGPT
void CubicSpline(List<Vector2> controlPoints, int numPoints)
{
// Initialize the list of spline points
List<Vector2> splinePoints = new List<Vector2>();
// Add the first control point to the spline points
splinePoints.Add(controlPoints[0]);
// Loop through the control points and calculate the spline points
@unitycoder
unitycoder / BresenhamFilledCircle.cs
Created December 22, 2022 22:29
Bresenham Filled Circle in c#
// chatGPT
void BresenhamFilledCircle(int x0, int y0, int radius)
{
// Initialize the variables needed to draw the circle
int x = radius;
int y = 0;
int decisionOver2 = 1 - x; // Decision criterion divided by 2 evaluated at x=r, y=0
// Loop through the y values from 0 to the radius
while (y <= x)
@unitycoder
unitycoder / DDA.cs
Created December 22, 2022 22:27
DDA = Digital Differential Analyzer Line Algorithm c#
// chatGPT
// DDA = Digital Differential Analyzer
void DDA(int x1, int y1, int x2, int y2)
{
// Calculate the difference between the start and end points
int dx = x2 - x1;
int dy = y2 - y1;
// Calculate the number of steps required to draw the line
int steps = Math.Abs(dx) > Math.Abs(dy) ? Math.Abs(dx) : Math.Abs(dy);
@unitycoder
unitycoder / draw_line.c
Created December 22, 2022 22:24
Bresenham's line algorithm c/c++
// chatGPT
void draw_line(int x1, int y1, int x2, int y2, uint32_t color)
{
// Bresenham's line algorithm
int dx = (x2 - x1 >= 0) ? x2 - x1 : x1 - x2;
int dy = (y2 - y1 >= 0) ? y2 - y1 : y1 - y2;
int sx = (x1 < x2) ? 1 : -1;
int sy = (y1 < y2) ? 1 : -1;
int err = dx - dy;
@unitycoder
unitycoder / SOHCAHTOA.txt
Last active December 22, 2022 21:22
Explain SOHCAHTOA
// chatGPT
SOHCAHTOA is a way to help us remember how to solve math problems involving triangles. It stands for:
S - Sine: The sine of an angle is a number that tells us how tall a triangle is, if we draw a line from the angle to the bottom of the triangle.
O - Opposite: The opposite side of a triangle is the side that is opposite (or across from) the angle that we are interested in.
H - Hypotenuse: The hypotenuse is the longest side of a right triangle. It is always opposite the right angle (90 degree angle).
@unitycoder
unitycoder / grid-math.c
Created December 20, 2022 11:46
Draw 2D Grid (without If's or Ternary)
int size = 10;
for (int x = 0; x < window_width; x++)
{
for (int y = 0; y < window_height; y++)
{
int i = window_width * y + x;
//color_buffer[i] = (x % size) * (y % size) ? 0x00000000 : 0xFFFFFFFF;
color_buffer[i] = ~(1 - (x % size) * (y % size)) & 0xFFFFFFFF;
}
}
@unitycoder
unitycoder / GeneralSpriteShader.shader
Created December 17, 2022 13:44 — forked from Antoshidza/GeneralSpriteShader.shader
unity instanced sprite shader
Shader "Universal Render Pipeline/2D/SimpleSpriteShader"
{
Properties
{
_MainTex("_MainTex", 2D) = "white" {}
}
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"