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
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]) |
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
常用关系运算符优化 | |
//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)); | |
} |
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
/* | |
** 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 |
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
#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" | |
/> |
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
/** | |
* 融合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)){ |