Skip to content

Instantly share code, notes, and snippets.

View hjm1fb's full-sized avatar
🎯
Focusing

hjm1fb1990 hjm1fb

🎯
Focusing
View GitHub Profile
import taichi as ti
ti.init(arch=ti.gpu)
n = 640
pixels = ti.field(dtype=float, shape=(n, n))
@ti.func
def complex_sqr(z):
return ti.Vector([z[0]**2 - z[1]**2, z[1] * z[0] * 2])
@hjm1fb
hjm1fb / glsl优化操作
Last active May 21, 2021 07:03
glsl优化操作
常用关系运算符优化
//relation operator
vec4 when_eq(vec4 x, vec4 y) {
return 1.0 - abs(step(x - y));
}
vec4 when_neq(vec4 x, vec4 y) {
return abs(step(x - y));
}
@hjm1fb
hjm1fb / PhotoshopMath.glsl
Last active May 21, 2021 06:38
GLSL Shader
/*
** Copyright (c) 2012, Romain Dura romain@shazbits.com
**
** Permission to use, copy, modify, and/or distribute this software for any
** purpose with or without fee is hereby granted, provided that the above
** copyright notice and this permission notice appear in all copies.
**
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
** WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
#ImageView 宽度固定, 自动resize高度
<ImageView
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/banner"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
/>
@hjm1fb
hjm1fb / Collections.kt
Last active April 20, 2018 08:03
Kotlin merge Reduce or custom flatten, for Objects
/**
* 融合List
* @reduce 自定义需要相同元素时如何融合,
* element为最先出现的元素,attach为后面出现的元素,element会被保存,attach会被舍弃
*
*/
fun <E> List<E>.selefMergeReduce(reduce: (element:E, attach: E) -> Unit): List<E> {
val result = mutableListOf<E>()
for (element in this){
if (!result.contains(element)){