Skip to content

Commit

Permalink
Merge pull request #20 from Triadica/axis
Browse files Browse the repository at this point in the history
better axis with xyz
  • Loading branch information
NoEgAm authored Oct 19, 2023
2 parents 986978b + 1979559 commit cac039a
Show file tree
Hide file tree
Showing 9 changed files with 532 additions and 130 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:

- uses: supplypike/setup-bin@v3
with:
uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.8/cr"
uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.9/cr"
name: 'cr'
version: "0.8.8"
version: "0.8.9"

- uses: supplypike/setup-bin@v3
with:
uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.8/caps"
uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.9/caps"
name: 'caps'
version: "0.8.8"
version: "0.8.9"

- name: "compiles to js"
run: >
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ comp-polylines $ {} (; :topology :line-strip)
, break-mark
```

also if you want an extra mark for controlling colors:

```cirru
comp-polylines-marked $ {} (; :topology :line-strip)
:writer $ fn (write!)
write! $ []
: vertex ([] 0 0 0) width 0
: vertex ([] 100 100 0) width 0
, break-mark
: vertex ([] 0 0 10) width 2
: vertex ([] 200 0 10) width 2
: vertex ([] 200 20 0) width 2
: vertex ([] 100 40 0) width 2
: vertex ([] 100 20 200) width 2
, break-mark
```

Spots

```cirru
Expand Down
514 changes: 428 additions & 86 deletions calcit.cirru

Large diffs are not rendered by default.

81 changes: 58 additions & 23 deletions compact.cirru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{} (:package |lagopus)
:configs $ {} (:init-fn |lagopus.main/main!) (:reload-fn |lagopus.main/reload!) (:version |0.3.0)
:configs $ {} (:init-fn |lagopus.main/main!) (:reload-fn |lagopus.main/reload!) (:version |0.3.1)
:modules $ [] |memof/ |quaternion/
:entries $ {}
:files $ {}
Expand Down Expand Up @@ -258,7 +258,7 @@
let
cursor $ []
states $ :states store
group nil (memof1-call comp-tabs)
group nil (; memof1-call comp-tabs)
case-default (:tab store) (group nil)
:axis $ comp-axis
{} (:n 20) (:unit 20)
Expand Down Expand Up @@ -643,29 +643,56 @@
write! $ [] (:: :vertex q 0 direction p-width prev-mark) (:: :vertex q2 0 direction q-width mark) (:: :vertex q 1 direction p-width prev-mark) (:: :vertex q2 0 direction p-width mark) (:: :vertex q2 1 direction q-width mark) (:: :vertex q 1 direction p-width prev-mark)
do $ reset! *prev
{} (:position position) (:older nil) (:mark mark) (:width width)
|char-x $ %{} :CodeEntry (:doc |)
:code $ quote
def char-x $ count-hex
reverse $ concat ([] true false true false false false false true) ([] false false true false true true false false) ([] false false false true true false true false) ([] false true false false false false true false)
|char-y $ %{} :CodeEntry (:doc |)
:code $ quote
def char-y $ count-hex
reverse $ concat ([] true false true false false false false true) ([] false false true false true true false false) ([] false false false false true true false false) ([] false false false false true true false false)
|char-z $ %{} :CodeEntry (:doc |)
:code $ quote
def char-z $ count-hex
reverse $ concat ([] true false true false true true false true) ([] false false false false false true false false) ([] false false false true false false false false) ([] false true true true true true true true true)
|comp-axis $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-axis (? options)
let
n $ either (get options :n) 20
unit $ either (get options :unit) 20
comp-curves $ {} (; :topology :line-strip)
:curves $ []
-> (range-bothway n)
map $ fn (n)
:: :vertex
[] (* n unit) 0 0
, 2
-> (range-bothway n)
map $ fn (n)
:: :vertex
[] 0 (* n unit) 0
, 2
-> (range-bothway n)
map $ fn (n)
:: :vertex
[] 0 0 $ * n unit
, 2
w $ either (get options :width) 1
group nil
comp-polylines-marked $ {} (; :topology :line-strip)
:shader $ inline-shader "\"axis"
:writer $ fn (write!)
&doseq
idx $ range-bothway n
write! $ :: :vertex
[] (* idx unit) 0 0
, w 0
write! break-mark
&doseq
idx $ range-bothway n
write! $ :: :vertex
[] 0 (* idx unit) 0
, w 1
write! break-mark
&doseq
idx $ range-bothway n
write! $ :: :vertex
[] 0 0 $ * idx unit
, w 2
write! break-mark
comp-stitch $ {} (:size 16)
:position $ [] 400 0 0
:chars $ [] char-x
comp-stitch $ {} (:size 16)
:position $ [] 0 400 0
:chars $ [] char-y
comp-stitch $ {} (:size 16)
:position $ [] 0 0 400
:chars $ [] char-z
|comp-curves $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-curves (options)
Expand Down Expand Up @@ -715,6 +742,13 @@
&doseq (x p) (build-polyline-points-marked *prev x write!)
build-polyline-points-marked *prev p write!
chunk-writer! collect!
|count-hex $ %{} :CodeEntry (:doc |)
:code $ quote
defn count-hex (xs)
-> xs
map-indexed $ fn (idx v)
* (if v 1 0) (pow 2 idx)
reduce 0 &+
|wgsl-curves $ %{} :CodeEntry (:doc |)
:code $ quote
def wgsl-curves $ inline-shader "\"curves"
Expand All @@ -728,8 +762,9 @@
:code $ quote
ns lagopus.comp.curves $ :require
lagopus.config :refer $ inline-shader
lagopus.alias :refer $ object object-writer
lagopus.alias :refer $ object group object-writer
quaternion.core :refer $ &v+ v-cross v-scale v-dot &v-
lagopus.comp.stitch :refer $ comp-stitch
|lagopus.comp.plate $ %{} :FileEntry
:defs $ {}
|calc-ratio $ %{} :CodeEntry (:doc |)
Expand Down Expand Up @@ -976,7 +1011,7 @@
let
chars $ either (:chars props) ([] 0x1111)
position $ either (:position props) ([] 0 0 0)
size 24
size $ either (:size props) 24
gap 4
s0 $ * 0.1 size
group ({})
Expand Down Expand Up @@ -1143,7 +1178,7 @@
let
dir $ if (.ends-with? calcit-dirname "\"/") calcit-dirname (str calcit-dirname "\"/")
str dir "\"shaders/" name "\".wgsl"
println "\"reading shader file:" shader
println "\"inline:" shader
read-file shader
|mobile-info $ %{} :CodeEntry (:doc |)
:code $ quote
Expand Down Expand Up @@ -1177,7 +1212,7 @@
:code $ quote
defatom *store $ {}
:states $ {}
:tab :bubbles
:tab :axis
|canvas $ %{} :CodeEntry (:doc |)
:code $ quote
def canvas $ js/document.querySelector "\"canvas"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"version": "0.3.0",
"version": "0.3.1",
"dependencies": {
"@calcit/procs": "^0.8.8",
"@calcit/procs": "^0.8.9",
"@calcit/std": "^0.0.3",
"@triadica/lagopus": "^0.0.18",
"@triadica/touch-control": "^0.0.3",
"@triadica/touch-control": "^0.0.4-a1",
"ismobilejs": "^1.1.1"
},
"devDependencies": {
Expand Down
19 changes: 11 additions & 8 deletions shaders/axis.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@ var<uniform> uniforms: UBO;

{{colors}}

{{hsluv}}

// main

struct VertexOut {
@builtin(position) position: vec4f,
@location(0) original: vec3f,
@location(1) ratio: f32,
@location(2) color: vec3f,
@location(1) color: vec3f,
@location(2) mark: f32,
};

@vertex
fn vertex_main(
@location(0) position: vec3f,
@location(1) brush: u32,
@location(2) direction: vec3f,
@location(3) curve_ratio: f32,
@location(4) color_index: u32,
@location(5) width: f32,
@location(3) width: f32,
@location(4) mark: f32,
) -> VertexOut {
var output: VertexOut;

Expand All @@ -55,8 +56,8 @@ fn vertex_main(
let scale: f32 = 0.002;
output.position = vec4(p[0]*scale, p[1]*scale, p[2]*scale, 1.0);
output.original = position;
output.ratio = curve_ratio;
output.color = hsl(fract(0.14 + curve_ratio), 1.0, 0.2 + 0.8 * fract(0.8 + f32(color_index) * 0.01));
output.color = hsl(0.14, 1.0, 0.2);
output.mark = mark;

return output;
}
Expand All @@ -66,5 +67,7 @@ const limit: f32 = 48.0;

@fragment
fn fragment_main(vtx_out: VertexOut) -> @location(0) vec4f {
return vec4f(vtx_out.color, 1.0);
// let color = hsl(fract(0.14 + vtx_out.mark * 0.2), 0.8, 0.4);
let color = hsluvToRgb(vec3(fract(0.0 + vtx_out.mark * 0.3333) * 360.0, 100.0, 50.0));
return vec4f(color, 1.0);
}
2 changes: 1 addition & 1 deletion shaders/stitch-bg.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ fn vertex_main(

@fragment
fn fragment_main(vtx_out: VertexOut) -> @location(0) vec4f {
return vec4(hsl(0.04, 1.0, 0.6), 0.7);
return vec4(hsl(0.04, 1.0, 0.3), 0.7);
}
2 changes: 1 addition & 1 deletion shaders/stitch-line.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ fn fragment_main(vtx_out: VertexOut) -> @location(0) vec4f {
if (vtx_out.value > 0.5) {
return vec4(1.0, 1.0, 1.0, 1.0);
} else {
return vec4(1.0, 0.0, 0.0, 1.0);
return vec4(1.0, 0.0, 0.0, 0.0);
}
}
13 changes: 9 additions & 4 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cac039a

Please sign in to comment.