Skip to content

Instantly share code, notes, and snippets.

using UnityEngine;
public class AsyncTextureCreator : MonoBehaviour
{
public int width = 128;
public int height = 32;
}
@hecomi
hecomi / shader.js
Created March 7, 2023 15:31
Create a distance function using ChatGPT API
const https = require('https');
const apiKey = require('./secret.js').key;
const input = process.argv.length > 2 ? process.argv[2] : 'sphere';
const options = {
hostname: 'api.openai.com',
port: 443,
path: '/v1/chat/completions',
method: 'POST',
headers: {
@hecomi
hecomi / ColorChanger.cs
Created November 29, 2022 17:27
PicturesGenerator Example
using UnityEngine;
namespace WeddingMovie
{
public class ColorChanger : MonoBehaviour
{
public Color color = Color.white;
[ContextMenu("ChangeColor")]
using System.Collections.Generic;
using UnityEngine;
public class VoiceSpeaker : MonoBehaviour
{
private List<float> _buffer = new List<float>();
private object _lockObject = new object();
private AudioSource _source;
private AudioClip _speakerClip;
...
var window = uwcWinObj.window;
var localPos = uwcWinObj.transform.InverseTransformPoint(targetHit_.point);
var windowLocalX = (int)((localPos.x + 0.5f) * window.width);
var windowLocalY = (int)((0.5f - localPos.y) * window.height);
var desktopX = window.x + windowLocalX;
var desktopY = window.y + windowLocalY;
var coord = new Vector2(desktopX, desktopY);
NwndWin32API.SetForegroundWindow(window.handle);
// Ref: http://7cc.hatenadiary.jp/entry/hatena-source-line
(function(document) {
var pres = document.getElementsByTagName('pre');
for (var i = pres.length; i--;) {
var elem = makeLineNumber(pres[i]);
pres[i].appendChild(elem);
}
using UnityEngine;
public class SerialCube : MonoBehaviour
{
public SerialHandler serialHandler;
public float threshold = 30f;
public Vector3 velocity = new Vector3(0f, 0.5f, 0f);
void Start()
{
#include <iostream>
#include <queue>
using namespace std;
int main()
{
int N, M;
cin >> N >> M;
@hecomi
hecomi / Raymarching.cginc
Created February 17, 2019 02:36
uRaymarching: a trial for marching rays in a local space
#ifndef RAYMARCHING_CGINC
#define RAYMARCHING_CGINC
#include "UnityCG.cginc"
#include "./Camera.cginc"
#include "./Utils.cginc"
#ifndef DISTANCE_FUNCTION
inline float _DefaultDistanceFunction(float3 pos)
{
@hecomi
hecomi / DistanceFunction.shader
Last active February 3, 2019 08:13
A test version of Raymarching.cginc@uRaymarching
inline float DistanceFunction(float3 wpos, RaymarchInfo ray)
{
float3 scenePos = ray.startPos + (ray.sceneDepth - ray.totalLength) * ray.rayDir;
float d1 = Sphere(wpos - scenePos, 0.01);
float d2 = Sphere(wpos - unity_ObjectToWorld._m03_m13_m23, 0.5);
return SmoothMin(d1, d2, 1.0);
}