Skip to content

Commit

Permalink
pass curve-idx in segments-curves; tag 0.0.35
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Jan 13, 2023
1 parent 2993ad0 commit 2be2fd1
Show file tree
Hide file tree
Showing 7 changed files with 656 additions and 514 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: add cr
run: |
mkdir -p $GITHUB_WORKSPACE/bin
wget -O $GITHUB_WORKSPACE/bin/cr https://github.com/calcit-lang/calcit/releases/download/0.6.19/cr
wget -O $GITHUB_WORKSPACE/bin/cr https://github.com/calcit-lang/calcit/releases/download/0.6.20/cr
chmod +x $GITHUB_WORKSPACE/bin/cr
echo "::add-path::$GITHUB_WORKSPACE/bin"
Expand Down
785 changes: 454 additions & 331 deletions calcit.cirru

Large diffs are not rendered by default.

90 changes: 52 additions & 38 deletions compact.cirru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{} (:package |triadica)
:configs $ {} (:init-fn |triadica.app.main/main!) (:reload-fn |triadica.app.main/reload!) (:version |0.0.34)
:configs $ {} (:init-fn |triadica.app.main/main!) (:reload-fn |triadica.app.main/reload!) (:version |0.0.35)
:modules $ [] |touch-control/ |respo.calcit/ |memof/ |quaternion/
:entries $ {}
:files $ {}
Expand Down Expand Up @@ -764,11 +764,28 @@
:tube $ comp-tube-demo
:strip-light $ comp-strip-light-demo
:segments $ comp-segments-demo
:segments-curves $ comp-segments-curves-demo
if-not hide-tabs? $ memof1-call comp-tabs tab-entries
{}
:position $ [] -40 0 0
:selected $ :tab store
fn (key d!) (d! :tab-focus key )
|comp-segments-curves-demo $ quote
defn comp-segments-curves-demo () $ comp-segments-curves
{} $ :curves
-> (range 4)
map $ fn (j)
-> (range 400)
map $ fn (idx)
let
angle $ * idx 0.08
h $ * 0.1 idx
r 40
{} $ :position
[]
+ 100 (* j 40)
* r $ cos angle
, h $ * r (sin angle)
|comp-segments-demo $ quote
defn comp-segments-demo () $ group ({}) (; comp-axis)
comp-segments $ {} (; :draw-mode :line-strip)
Expand Down Expand Up @@ -810,18 +827,6 @@
rotation c
dec n
:width 1
comp-segments-curves $ {}
:curves $ []
-> (range 400)
map $ fn (idx)
let
angle $ * idx 0.08
h $ * 0.1 idx
r 40
{} $ :position
[]
+ 100 $ * r (cos angle)
, h $ * r (sin angle)
|comp-strip-light-demo $ quote
defn comp-strip-light-demo () $ comp-strip-light
{} (; :draw-mode :line-strip)
Expand Down Expand Up @@ -933,6 +938,8 @@
:position $ [] -200 -120 0
{} (:key :segments)
:position $ [] -200 -160 0
{} (:key :segments-curves)
:position $ [] -200 -200 0
:ns $ quote
ns triadica.app.container $ :require
triadica.alias :refer $ group
Expand All @@ -957,7 +964,7 @@
:defs $ {}
|*store $ quote
defatom *store $ {} (:v 0)
:tab $ turn-keyword (get-env "\"tab" "\"segments")
:tab $ turn-keyword (get-env "\"tab" "\"segments-curves")
:p1 $ [] 0 0 0
:states $ {}
|canvas $ quote
Expand Down Expand Up @@ -1736,29 +1743,33 @@
|triadica.comp.segments $ {}
:defs $ {}
|build-curve-points $ quote
defn build-curve-points (points)
->
range $ dec (count points)
map $ fn (idx)
let
idx+1 $ inc idx
p-raw $ nth points idx
q-raw $ nth points idx+1
q2-raw $ nth points (inc idx+1)
p $ &map:get p-raw :position
q $ &map:get q-raw :position
q2 $ if (some? q2-raw) (&map:get q2-raw :position)
direction $ &v- q p
direction2 $ if (some? q2) (&v- q2 q) direction
p-width $ either (&map:get p-raw :width) 1
q-width $ either (&map:get q-raw :width) 1
[]
{} (:position p) (:brush 0) (:direction direction) (:color_index idx) (:width p-width)
{} (:position q) (:brush 0) (:direction direction2) (:color_index idx+1) (:width q-width)
{} (:position p) (:brush 1) (:direction direction) (:color_index idx) (:width p-width)
{} (:position q) (:brush 0) (:direction direction2) (:color_index idx+1) (:width q-width)
{} (:position q) (:brush 1) (:direction direction2) (:color_index idx+1) (:width q-width)
{} (:position p) (:brush 1) (:direction direction) (:color_index idx) (:width p-width)
defn build-curve-points (points curve-ratio)
let
size $ count points
->
range $ dec size
map $ fn (idx)
let
idx+1 $ inc idx
p-raw $ nth points idx
q-raw $ nth points idx+1
q2-raw $ nth points (inc idx+1)
p $ &map:get p-raw :position
q $ &map:get q-raw :position
q2 $ if (some? q2-raw) (&map:get q2-raw :position)
direction $ &v- q p
direction2 $ if (some? q2) (&v- q2 q) direction
p-width $ either (&map:get p-raw :width) 1
q-width $ either (&map:get q-raw :width) 1
ratio $ &/ idx size
ratio+1 $ &/ idx+1 size
[]
{} (:position p) (:brush 0) (:direction direction) (:curve_ratio curve-ratio) (:color_index idx) (:width p-width)
{} (:position q) (:brush 0) (:direction direction2) (:curve_ratio curve-ratio) (:color_index idx+1) (:width q-width)
{} (:position p) (:brush 1) (:direction direction) (:curve_ratio curve-ratio) (:color_index idx) (:width p-width)
{} (:position q) (:brush 0) (:direction direction2) (:curve_ratio curve-ratio) (:color_index idx+1) (:width q-width)
{} (:position q) (:brush 1) (:direction direction2) (:curve_ratio curve-ratio) (:color_index idx+1) (:width q-width)
{} (:position p) (:brush 1) (:direction direction) (:curve_ratio curve-ratio) (:color_index idx) (:width p-width)
|comp-segments $ quote
defn comp-segments (options)
let
Expand Down Expand Up @@ -1791,7 +1802,10 @@
:draw-mode $ either (&map:get options :draw-mode) :triangles
:vertex-shader $ either (&map:get options :vertex-shader) (inline-shader "\"segments-curves.vert")
:fragment-shader $ either (&map:get options :fragment-shader) (inline-shader "\"segments-curves.frag")
:packed-attrs $ map curves build-curve-points
:packed-attrs $ let
size $ count curves
map-indexed curves $ fn (idx c)
build-curve-points c $ &/ idx size
:get-uniforms $ &map:get options :get-uniforms
|traverse-lines $ quote
defn traverse-lines (segments f)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "triadica-space",
"version": "0.0.34",
"version": "0.0.35",
"repository": "git@github.com:Quatrefoil-GL/triadica-space.git",
"author": "tiye <jiyinyiyong@gmail.com>",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
"vite": "^4.0.4"
},
"dependencies": {
"@calcit/procs": "^0.6.19",
"@calcit/procs": "^0.6.20",
"@calcit/std": "^0.0.2",
"@quamolit/touch-control": "^0.0.11",
"mobile-detect": "^1.4.5",
Expand Down
3 changes: 2 additions & 1 deletion shaders/segments-curves.frag
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ precision mediump float;

varying float v_s;
varying float v_r;
varying float v_curve_ratio;
varying float v_color_index;

void main() {
gl_FragColor = vec4(hsl2rgb(0.14, 1.0, 0.8), 1.0);
gl_FragColor = vec4(hsl2rgb(fract(0.14 + v_curve_ratio), 1.0, fract(0.8 + v_color_index * 0.1)), 1.0);
}
4 changes: 4 additions & 0 deletions shaders/segments-curves.vert
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ attribute vec3 a_position;
attribute float a_brush;
attribute vec3 a_direction;
attribute float a_width;
attribute float a_curve_ratio;
attribute float a_color_index;

varying float v_r;
varying float v_s;
// optional value for fill different colors
varying float v_curve_ratio;
varying float v_color_index;

void main() {
Expand All @@ -33,6 +35,8 @@ void main() {

v_s = result.s;
v_r = result.r;
v_curve_ratio = a_curve_ratio;
v_color_index = a_color_index;

gl_Position = vec4(pos_next * 0.002, 1.0);
}
Loading

0 comments on commit 2be2fd1

Please sign in to comment.