Browse Source

end to end rendering of a line

Inderjit Gill 7 months ago
parent
commit
667b213684

+ 24
- 2
client/sen-client/src/lib.rs View File

@@ -22,6 +22,8 @@ use wasm_bindgen::prelude::*;
22 22
 
23 23
 // use sen_core::sen_parse;
24 24
 use sen_core::vm::{Vm, Env};
25
+use sen_core::parser::*;
26
+use sen_core::compiler::compile_program;
25 27
 
26 28
 cfg_if! {
27 29
     // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
@@ -115,8 +117,28 @@ impl Bridge {
115 117
     }
116 118
 
117 119
     pub fn compile_to_render_packets(&mut self) -> i32 {
118
-        log("compile_to_render_packets");
119
-        self.vm.test_render().unwrap_or(0) as i32
120
+        // self.vm.test_render().unwrap_or(0) as i32
121
+
122
+        let env = Env::new();
123
+
124
+        let (ast, _word_lut) = if let Ok((ast_, _word_lut_)) = parse(&self.source_buffer) {
125
+            (ast_, _word_lut_)
126
+        } else {
127
+            return 0
128
+        };
129
+
130
+        let program = if let Ok(program_) = compile_program(&ast) {
131
+            program_
132
+        } else {
133
+            return 0
134
+        };
135
+
136
+        self.vm.reset();
137
+        if let Ok(_) = self.vm.interpret(&env, &program) {
138
+            self.vm.geometry.get_num_render_packets() as i32
139
+        } else {
140
+            0
141
+        }
120 142
     }
121 143
 
122 144
     pub fn get_render_packet_geo_len(&self, packet_number: usize) -> usize {

+ 19
- 1
core/sen-core/src/compiler.rs View File

@@ -94,6 +94,7 @@ pub enum BytecodeArg {
94 94
     Name(i32),
95 95
     Native(Native),
96 96
     Mem(Mem),
97
+    Keyword(Keyword),
97 98
     Colour(ColourFormat, f32, f32, f32, f32),
98 99
 }
99 100
 
@@ -105,6 +106,7 @@ impl fmt::Display for BytecodeArg {
105 106
             BytecodeArg::Name(i) => write!(f, "Name({})", i),
106 107
             BytecodeArg::Native(n) => write!(f, "{:?}", n),
107 108
             BytecodeArg::Mem(m) => write!(f, "{}", m),
109
+            BytecodeArg::Keyword(kw) => write!(f, "{}", kw),
108 110
             BytecodeArg::Colour(s, a, b, c, d) => write!(f, "{}({} {} {} {})", s, a, b, c, d),
109 111
         }
110 112
     }
@@ -323,6 +325,19 @@ impl Compilation {
323 325
         Ok(())
324 326
     }
325 327
 
328
+    fn emit_opcode_mem_kw(&mut self, op: Opcode, arg0: Mem, arg1: Keyword) -> Result<()> {
329
+        let b = Bytecode {
330
+            op,
331
+            arg0: BytecodeArg::Mem(arg0),
332
+            arg1: BytecodeArg::Keyword(arg1),
333
+        };
334
+
335
+        self.add_bytecode(b)?;
336
+        self.opcode_offset += opcode_stack_offset(op);
337
+
338
+        Ok(())
339
+    }
340
+
326 341
     fn emit_opcode_mem_name(&mut self, op: Opcode, arg0: Mem, arg1: i32) -> Result<()> {
327 342
         let b = Bytecode {
328 343
             op,
@@ -875,9 +890,12 @@ impl Compiler {
875 890
                 let found_name = self.compile_user_defined_name(compilation, &text, *iname)?;
876 891
                 if found_name {
877 892
                     return Ok(());
893
+                } else if let Some(kw) = self.string_to_keyword.get(text) {
894
+                    compilation.emit_opcode_mem_kw(Opcode::LOAD, Mem::Constant, *kw)?;
895
+                    return Ok(());
878 896
                 } else {
879 897
                     return Err(Error::Compiler(format!(
880
-                        "compile: can't find user defined name: {}",
898
+                        "compile: can't find user defined name or keyword: {}",
881 899
                         text
882 900
                     )));
883 901
                 }

+ 11
- 1
core/sen-core/src/geometry.rs View File

@@ -21,7 +21,7 @@ use crate::colour::Colour;
21 21
 
22 22
 // todo: work out reasonable defaults
23 23
 const RENDER_PACKET_MAX_SIZE: usize = 4096;
24
-const RENDER_PACKET_FLOAT_PER_VERTEX: usize = 8;
24
+pub const RENDER_PACKET_FLOAT_PER_VERTEX: usize = 8;
25 25
 
26 26
 #[derive(Default)]
27 27
 pub struct RenderPacket {
@@ -111,11 +111,17 @@ impl Geometry {
111 111
         }
112 112
     }
113 113
 
114
+    pub fn reset(&mut self) {
115
+        self.render_packets.clear();
116
+        self.render_packets.push(RenderPacket::new())
117
+    }
118
+
114 119
     pub fn test_render(&mut self, mappings: &Mappings) -> Result<(usize)> {
115 120
         let uvm = mappings.get_uv_mapping(BrushType::Flat, 0);
116 121
         self.render_line(&Matrix::identity(), 100.0, 100.0, 600.0, 600.0, 50.0,
117 122
                          &Colour::RGB(1.0, 0.0, 0.0, 1.0), &Colour::RGB(1.0, 1.0, 0.0, 1.0),
118 123
                          &uvm)?;
124
+
119 125
         let uvm2 = mappings.get_uv_mapping(BrushType::A, 0);
120 126
         self.render_line(&Matrix::identity(), 800.0, 700.0, 200.0, 100.0, 10.0,
121 127
                          &Colour::RGB(1.0, 0.0, 0.0, 1.0), &Colour::RGB(1.0, 0.0, 1.0, 1.0),
@@ -139,6 +145,10 @@ impl Geometry {
139 145
         rp.geo.as_ptr() as *const f32
140 146
     }
141 147
 
148
+    pub fn get_num_render_packets(&self) -> usize {
149
+        self.render_packets.len()
150
+    }
151
+
142 152
     fn prepare_to_add_triangle_strip(&mut self, matrix: &Matrix, num_vertices: usize, x: f32, y: f32) {
143 153
         let mut last = self.render_packets.len() - 1;
144 154
         let mut rp = &mut self.render_packets[last];

+ 2
- 2
core/sen-core/src/lib.rs View File

@@ -21,20 +21,20 @@
21 21
 // along with this program.  If not, see <https://www.gnu.org/licenses/>.
22 22
 
23 23
 mod colour;
24
-mod compiler;
25 24
 mod keywords;
26 25
 mod lexer;
27 26
 mod mathutil;
28 27
 mod matrix;
29 28
 mod native;
30 29
 mod opcodes;
31
-mod parser;
32 30
 mod placeholder;
33 31
 mod uvmapper;
34 32
 
33
+pub mod compiler;
35 34
 pub mod error;
36 35
 pub mod geometry;
37 36
 pub mod vm;
37
+pub mod parser;
38 38
 
39 39
 use crate::parser::*;
40 40
 use crate::error::*;

+ 185
- 12
core/sen-core/src/native.rs View File

@@ -13,11 +13,13 @@
13 13
 // You should have received a copy of the GNU General Public License
14 14
 // along with this program.  If not, see <https://www.gnu.org/licenses/>.
15 15
 
16
-use crate::compiler::Program;
16
+use crate::compiler::{Program, ColourFormat};
17 17
 use crate::error::{Error, Result};
18 18
 use crate::keywords::Keyword;
19 19
 use crate::mathutil;
20 20
 use crate::vm::{Var, Vm};
21
+use crate::uvmapper::BrushType;
22
+use crate::colour::Colour;
21 23
 
22 24
 use std::collections::HashMap;
23 25
 
@@ -287,7 +289,7 @@ pub fn build_native_fn_hash() -> HashMap<Native, NativeCallback> {
287 289
     // BIND("col/convert", bind_col_convert);
288 290
     // start of colour constructors
289 291
     // g_colour_constructor_start = word_lut->native_count;
290
-    // BIND("col/rgb", bind_col_rgb);
292
+    native_fns.insert(Native::ColRGB, bind_col_rgb);
291 293
     // BIND("col/hsl", bind_col_hsl);
292 294
     // BIND("col/hsluv", bind_col_hsluv);
293 295
     // BIND("col/hsv", bind_col_hsv);
@@ -471,32 +473,161 @@ pub fn bind_vector_length(vm: &mut Vm, _program: &Program, num_args: usize) -> R
471 473
 }
472 474
 
473 475
 pub fn bind_line(vm: &mut Vm, _program: &Program, num_args: usize) -> Result<Var> {
474
-    let mut vector: Option<&Var> = None;
476
+
477
+    let mut width: f32 = 4.0;
478
+    let mut from: (f32, f32) = (10.0, 10.0);
479
+    let mut to: (f32, f32) = (900.0, 900.0);
480
+    let mut from_colour: Option<(f32, f32, f32, f32)> = None;
481
+    let mut to_colour: Option<(f32, f32, f32, f32)> = None;
482
+    let mut colour: (f32, f32, f32, f32) = (0.0, 1.0, 0.0, 1.0);
483
+    let mut brush = BrushType::Flat;
484
+    let mut brush_subtype: usize = 0;
475 485
 
476 486
     let mut args_pointer = vm.sp - (num_args * 2);
477 487
 
488
+    // let mut s: String = "".to_string();
489
+
478 490
     for _ in 0..num_args {
479 491
         let label = &vm.stack[args_pointer];
480 492
         let value = &vm.stack[args_pointer + 1];
481 493
         args_pointer += 2;
482 494
 
483 495
         if let Var::Int(iname) = label {
484
-            if *iname == Keyword::Vector as i32 {
485
-                vector = Some(value);
496
+            if *iname == Keyword::Width as i32 {
497
+                if let Var::Float(f) = value {
498
+                    width = *f;
499
+                }
500
+            }
501
+            if *iname == Keyword::From as i32 {
502
+                if let Var::V2D(x, y) = value {
503
+                    from = (*x, *y);
504
+                }
505
+            }
506
+            if *iname == Keyword::To as i32 {
507
+                if let Var::V2D(x, y) = value {
508
+                    to = (*x, *y);
509
+                }
510
+            }
511
+            if *iname == Keyword::FromColour as i32 {
512
+                if let Var::Colour(fmt, e0, e1, e2, e3) = value {
513
+                    // hack for now
514
+                    if *fmt == ColourFormat::Rgba {
515
+                        from_colour = Some((*e0, *e1, *e2, *e3));
516
+                    }
517
+                }
518
+            }
519
+            if *iname == Keyword::ToColour as i32 {
520
+                if let Var::Colour(fmt, e0, e1, e2, e3) = value {
521
+                    // hack for now
522
+                    if *fmt == ColourFormat::Rgba {
523
+                        to_colour = Some((*e0, *e1, *e2, *e3));
524
+                    }
525
+                }
526
+            }
527
+            if *iname == Keyword::Colour as i32 {
528
+                if let Var::Colour(fmt, e0, e1, e2, e3) = value {
529
+                    // hack for now
530
+                    if *fmt == ColourFormat::Rgba {
531
+                        colour = (*e0, *e1, *e2, *e3);
532
+                    }
533
+                }
534
+            }
535
+
536
+            if *iname == Keyword::Brush as i32 {
537
+                if let Var::Keyword(n) = value {
538
+                    brush = match *n {
539
+                        Keyword::BrushFlat => BrushType::Flat,
540
+                        Keyword::BrushA  => BrushType::A,
541
+                        Keyword::BrushB  => BrushType::B,
542
+                        Keyword::BrushC  => BrushType::C,
543
+                        Keyword::BrushD  => BrushType::D,
544
+                        Keyword::BrushE  => BrushType::E,
545
+                        Keyword::BrushF  => BrushType::F,
546
+                        Keyword::BrushG  => BrushType::G,
547
+                        _ => BrushType::Flat,
548
+                    };
549
+                }
550
+            }
551
+
552
+            if *iname == Keyword::BrushSubtype as i32 {
553
+                if let Var::Float(f) = value {
554
+                    brush_subtype = *f as usize;
555
+                }
486 556
             }
487 557
         }
488 558
     }
489 559
 
490
-    if let Some(v) = vector {
491
-        if let Var::Vector(vs) = v {
492
-            let len = vs.len();
493
-            return Ok(Var::Int(len as i32));
560
+    let matrix = if let Some(matrix) = vm.matrix_stack.peek() {
561
+        matrix
562
+    } else {
563
+        return Err(Error::Bind(
564
+            "bind_line matrix error".to_string(),
565
+        ))
566
+    };
567
+
568
+    let uvm = vm.mappings.get_uv_mapping(brush, brush_subtype);
569
+
570
+    let col = Colour::RGB(colour.0 as f64, colour.1 as f64, colour.2 as f64, colour.3 as f64);
571
+
572
+    let from_col = if let Some((fr, fg, fb, fa)) = from_colour {
573
+        Colour::RGB(fr as f64, fg as f64, fb as f64, fa as f64)
574
+    } else {
575
+        col
576
+    };
577
+
578
+    let to_col = if let Some((tr, tg, tb, ta)) = to_colour {
579
+        Colour::RGB(tr as f64, tg as f64, tb as f64, ta as f64)
580
+    } else {
581
+        col
582
+    };
583
+
584
+    vm.geometry.render_line(matrix, from.0, from.1, to.0, to.1, width, &from_col, &to_col, uvm)?;
585
+
586
+    Ok(Var::Bool(true))
587
+    // Ok(Var::Debug(format!("counter: {} num_args: {} colour: {:?} width: {}, from: {:?}, to: {:?}, from_col: {:?}, to_col: {:?}", counter, num_args, colour, width, from, to, from_col, to_col).to_string()))
588
+    //Ok(Var::Debug(format!("s: {}", s).to_string()))
589
+}
590
+
591
+pub fn bind_col_rgb(vm: &mut Vm, _program: &Program, num_args: usize) -> Result<Var> {
592
+    // (col/rgb r: 0.627 g: 0.627 b: 0.627 alpha: 0.4)
593
+
594
+    let mut r: f32 = 0.0;
595
+    let mut g: f32 = 0.0;
596
+    let mut b: f32 = 0.0;
597
+    let mut alpha: f32 = 1.0;
598
+
599
+    let mut args_pointer = vm.sp - (num_args * 2);
600
+
601
+    for _ in 0..num_args {
602
+        let label = &vm.stack[args_pointer];
603
+        let value = &vm.stack[args_pointer + 1];
604
+        args_pointer += 2;
605
+
606
+        if let Var::Int(iname) = label {
607
+            if *iname == Keyword::R as i32 {
608
+                if let Var::Float(f) = value {
609
+                    r = *f;
610
+                }
611
+            }
612
+            if *iname == Keyword::G as i32 {
613
+                if let Var::Float(f) = value {
614
+                    g = *f;
615
+                }
616
+            }
617
+            if *iname == Keyword::B as i32 {
618
+                if let Var::Float(f) = value {
619
+                    b = *f;
620
+                }
621
+            }
622
+            if *iname == Keyword::Alpha as i32 {
623
+                if let Var::Float(f) = value {
624
+                    alpha = *f;
625
+                }
626
+            }
494 627
         }
495 628
     }
496 629
 
497
-    Err(Error::Bind(
498
-        "bind_vector_length requires vector argument".to_string(),
499
-    ))
630
+    Ok(Var::Colour(ColourFormat::Rgba, r, g, b, alpha))
500 631
 }
501 632
 
502 633
 pub fn bind_math_distance(vm: &mut Vm, _program: &Program, num_args: usize) -> Result<Var> {
@@ -693,7 +824,49 @@ pub fn bind_math_sin(vm: &mut Vm, _program: &Program, num_args: usize) -> Result
693 824
 
694 825
 #[cfg(test)]
695 826
 mod tests {
827
+    use crate::compiler::ColourFormat;
828
+    use crate::vm::*;
696 829
     use crate::vm::tests::*;
830
+    use crate::geometry::RENDER_PACKET_FLOAT_PER_VERTEX;
831
+
832
+    fn is_col_rgb(s: &str, r: f32, g: f32, b: f32, alpha: f32) {
833
+        if let Var::Colour(fmt, e0, e1, e2, e3) = vm_exec(s) {
834
+            assert_eq!(fmt, ColourFormat::Rgba);
835
+            assert_eq!(e0, r);
836
+            assert_eq!(e1, g);
837
+            assert_eq!(e2, b);
838
+            assert_eq!(e3, alpha);
839
+        }
840
+    }
841
+
842
+    // get render packet 0's geometry length
843
+    fn rp0_num_vertices(vm: &Vm, expected_num_vertices: usize) {
844
+        assert_eq!(vm.get_render_packet_geo_len(0), expected_num_vertices * RENDER_PACKET_FLOAT_PER_VERTEX);
845
+    }
846
+
847
+    #[test]
848
+    fn test_bind_line() {
849
+        let mut vm = Vm::new();
850
+        // vm_run(&mut vm, "(line width: 0 from: [2 3] to: [400 500] colour: (col/rgb r: 0 g: 0.1 b: 0.2 alpha: 0.3))");
851
+
852
+        vm_run(&mut vm, "(line width: 0 from: [2 3] to: [400 500] brush: brush-b colour: (col/rgb r: 0 g: 0.1 b: 0.2 alpha: 0.3))");
853
+
854
+        // vm_run(&mut vm, "(line brush: brush-b)");
855
+
856
+        // let res = vm.top_stack_value().unwrap();
857
+        // if let Var::Debug(s) = res {
858
+        //     assert_eq!(s, "x");
859
+        // } else {
860
+        //     assert_eq!(false, true);
861
+        // }
862
+
863
+        rp0_num_vertices(&vm, 4);
864
+    }
865
+
866
+    #[test]
867
+    fn test_bind_col_rgb() {
868
+        is_col_rgb("(col/rgb r: 0.1 g: 0.2 b: 0.3 alpha: 0.4)", 0.1, 0.2, 0.3, 0.4);
869
+    }
697 870
 
698 871
     #[test]
699 872
     fn test_bind_nth() {

+ 0
- 1
core/sen-core/src/placeholder.rs View File

@@ -1,5 +1,4 @@
1 1
 pub type Placeholder = i32;
2 2
 
3 3
 pub type RenderData = Placeholder;
4
-pub type MatrixStack = Placeholder;
5 4
 pub type PrngState = Placeholder;

+ 42
- 3
core/sen-core/src/vm.rs View File

@@ -21,6 +21,7 @@ use crate::opcodes::Opcode;
21 21
 use crate::placeholder::*;
22 22
 use crate::uvmapper::Mappings;
23 23
 use crate::geometry::Geometry;
24
+use crate::matrix::MatrixStack;
24 25
 
25 26
 use std::collections::HashMap;
26 27
 use std::fmt;
@@ -48,6 +49,7 @@ pub enum Var {
48 49
     Vector(Vec<Var>),
49 50
     Colour(ColourFormat, f32, f32, f32, f32),
50 51
     V2D(f32, f32),
52
+    Debug(String),              // this is temporary REMOVE
51 53
 }
52 54
 
53 55
 impl fmt::Display for Var {
@@ -64,6 +66,7 @@ impl fmt::Display for Var {
64 66
                 write!(f, "Colour({}, {}, {}, {}, {})", format, e0, e1, e2, e3)
65 67
             }
66 68
             Var::V2D(fl1, fl2) => write!(f, "V2D({}, {})", fl1, fl2),
69
+            Var::Debug(s) => write!(f, "DEBUG: {}", s),
67 70
         }
68 71
     }
69 72
 }
@@ -138,7 +141,7 @@ impl Default for Vm {
138 141
         Vm {
139 142
             render_data: 0,
140 143
 
141
-            matrix_stack: 0,
144
+            matrix_stack: MatrixStack::new(),
142 145
 
143 146
             prng_state: 0,
144 147
 
@@ -179,6 +182,7 @@ fn bytecode_arg_to_var(bytecode_arg: &BytecodeArg) -> Result<Var> {
179 182
         BytecodeArg::Int(i) => Ok(Var::Int(*i)),
180 183
         BytecodeArg::Float(f) => Ok(Var::Float(*f)),
181 184
         BytecodeArg::Name(iname) => Ok(Var::Name(*iname)),
185
+        BytecodeArg::Keyword(keyword) => Ok(Var::Keyword(*keyword)),
182 186
         BytecodeArg::Mem(_mem) => Err(Error::VM(
183 187
             "bytecode_arg_to_var not implemented for BytecodeArg::Mem".to_string(),
184 188
         )),
@@ -206,6 +210,33 @@ impl Vm {
206 210
         self.geometry.get_render_packet_geo_ptr(packet_number)
207 211
     }
208 212
 
213
+    pub fn reset(&mut self) {
214
+        let mut base_offset: usize = 0;
215
+        self.global = base_offset;
216
+        base_offset += MEMORY_GLOBAL_SIZE;
217
+
218
+        self.ip = 0;
219
+        self.fp = base_offset;
220
+        self.stack[self.fp] = Var::Int(0);
221
+
222
+        // add some offsets so that the memory after fp matches a standard format
223
+        base_offset += 1; // the caller's frame pointer
224
+        base_offset += 1; // the caller's ip
225
+        base_offset += 1; // the num_args of the called function
226
+        base_offset += 1; // the caller's hop back
227
+
228
+        self.local = base_offset;
229
+        base_offset += MEMORY_LOCAL_SIZE;
230
+        self.sp = base_offset;
231
+
232
+        self.matrix_stack.reset();
233
+        self.geometry.reset();
234
+
235
+        // todo
236
+        // vm->building_with_trait_within_vector = 0;
237
+        // vm->trait_within_vector_index         = 0;
238
+    }
239
+
209 240
     fn sp_inc_by(&self, delta: usize) -> Result<usize> {
210 241
         if self.sp + delta >= self.stack_size {
211 242
             return Err(Error::VMStackOverflow);
@@ -382,6 +413,9 @@ impl Vm {
382 413
             ));
383 414
         };
384 415
 
416
+        // pop all of the arguments off the stack
417
+        self.sp -= num_args * 2;
418
+
385 419
         // push var onto the stack
386 420
         self.sp = self.sp_inc()?;
387 421
         self.stack[self.sp - 1] = var;
@@ -1100,18 +1134,23 @@ pub mod tests {
1100 1134
     use crate::compiler::compile_program;
1101 1135
     use crate::parser::parse;
1102 1136
 
1103
-    fn vm_exec(s: &str) -> Var {
1104
-        let mut vm = Vm::new();
1137
+    pub fn vm_run(vm: &mut Vm, s: &str) {
1105 1138
         let env = Env::new();
1106 1139
 
1107 1140
         let (ast, _word_lut) = parse(s).unwrap();
1108 1141
         let program = compile_program(&ast).unwrap();
1109 1142
 
1143
+        vm.reset();
1110 1144
         vm.interpret(&env, &program).unwrap();
1145
+    }
1111 1146
 
1147
+    pub fn vm_exec(s: &str) -> Var {
1148
+        let mut vm = Vm::new();
1149
+        vm_run(&mut vm, s);
1112 1150
         vm.top_stack_value().unwrap()
1113 1151
     }
1114 1152
 
1153
+
1115 1154
     pub fn is_float(s: &str, val: f32) {
1116 1155
         if let Var::Float(f) = vm_exec(s) {
1117 1156
             assert_eq!(f, val)

+ 2
- 2
native/sen-native/src/main.rs View File

@@ -19,8 +19,8 @@ impl From<IoError> for NativeError {
19 19
     }
20 20
 }
21 21
 
22
-impl From<sen_core::Error> for NativeError {
23
-    fn from(_e: sen_core::Error) -> NativeError {
22
+impl From<sen_core::error::Error> for NativeError {
23
+    fn from(_e: sen_core::error::Error) -> NativeError {
24 24
         NativeError::SenError
25 25
     }
26 26
 }

+ 52
- 46
server/static/seni/1669-zero.seni View File

@@ -1,52 +1,58 @@
1
-(define
2
-  data [])
1
+(line from: [20 500]
2
+      to: [800 200]
3
+      width: 50
4
+      from-colour: (col/rgb r: 1 g: 0 b: 0 alpha: 1)
5
+      )
3 6
 
4
-;; create a bunch of positions around the origin
5
-(define
6
-  random-axis-position (prng/build seed: 42 min: -500 max: 500)
7
-  col-fn (col/build-procedural preset: {mars
8
-                                     (gen/select from: col/procedural-fn-presets)})
9
-  random-radius (prng/build seed: 42 min: 2 max: 30))
7
+;; (define
8
+;;   data [])
10 9
 
11
-(loop (x to: 180)
12
-  (define
13
-    x-pos (prng/value from: random-axis-position)
14
-    y-pos (prng/value from: random-axis-position)
15
-    dist (math/distance vec1: [x-pos y-pos] vec2: [0 0])
16
-    colour (col/value from: col-fn t: (/ dist 500))
17
-    radius (prng/value from: random-radius))
18
-  (++ data [x-pos y-pos colour radius]))
10
+;; ;; create a bunch of positions around the origin
11
+;; (define
12
+;;   random-axis-position (prng/build seed: 42 min: -500 max: 500)
13
+;;   col-fn (col/build-procedural preset: {mars
14
+;;                                      (gen/select from: col/procedural-fn-presets)})
15
+;;   random-radius (prng/build seed: 42 min: 2 max: 30))
19 16
 
20
-(fn (draw-bg obj: [])
21
-  (define
22
-    [x y colour radius] obj)
23
-  (circle position: [x y]
24
-          colour: (col/set-alpha colour: colour
25
-                                 value: {0.0167 (gen/scalar min: 0 max: 0.4)})
26
-          radius: (* radius {6 (gen/int min: 1 max: 8)})
27
-          tessellation: 20))
17
+;; (loop (x to: 180)
18
+;;   (define
19
+;;     x-pos (prng/value from: random-axis-position)
20
+;;     y-pos (prng/value from: random-axis-position)
21
+;;     dist (math/distance vec1: [x-pos y-pos] vec2: [0 0])
22
+;;     colour (col/value from: col-fn t: (/ dist 500))
23
+;;     radius (prng/value from: random-radius))
24
+;;   (++ data [x-pos y-pos colour radius]))
28 25
 
29
-(fn (draw-body obj: [])
30
-  (define
31
-    [x y colour radius] obj)
32
-  (circle position: [x y]
33
-          colour: colour
34
-          radius: radius
35
-          tessellation: 20))
26
+;; (fn (draw-bg obj: [])
27
+;;   (define
28
+;;     [x y colour radius] obj)
29
+;;   (circle position: [x y]
30
+;;           colour: (col/set-alpha colour: colour
31
+;;                                  value: {0.0167 (gen/scalar min: 0 max: 0.4)})
32
+;;           radius: (* radius {6 (gen/int min: 1 max: 8)})
33
+;;           tessellation: 20))
36 34
 
37
-(fn (draw-shadow obj: [])
38
-  (define
39
-    [x y colour radius] obj
40
-    offset {1.03 (gen/scalar min: 1 max: 2)})
41
-  (circle position: [(* x offset) (* y offset)]
42
-          colour: (col/set-alpha colour: (col/darken colour: colour
43
-                                                     value: {27 (gen/int min: 0 max: 100)})
44
-                                 value: {0.236 (gen/scalar max: 0.5)})
45
-          radius: radius
46
-          tessellation: 20))
35
+;; (fn (draw-body obj: [])
36
+;;   (define
37
+;;     [x y colour radius] obj)
38
+;;   (circle position: [x y]
39
+;;           colour: colour
40
+;;           radius: radius
41
+;;           tessellation: 20))
47 42
 
48
-(on-matrix-stack
49
- (translate vector: [500 500])
50
- (each (x from: data) (draw-bg obj: x))
51
- (each (x from: data) (draw-shadow obj: x))
52
- (each (x from: data) (draw-body obj: x)))
43
+;; (fn (draw-shadow obj: [])
44
+;;   (define
45
+;;     [x y colour radius] obj
46
+;;     offset {1.03 (gen/scalar min: 1 max: 2)})
47
+;;   (circle position: [(* x offset) (* y offset)]
48
+;;           colour: (col/set-alpha colour: (col/darken colour: colour
49
+;;                                                      value: {27 (gen/int min: 0 max: 100)})
50
+;;                                  value: {0.236 (gen/scalar max: 0.5)})
51
+;;           radius: radius
52
+;;           tessellation: 20))
53
+
54
+;; (on-matrix-stack
55
+;;  (translate vector: [500 500])
56
+;;  (each (x from: data) (draw-bg obj: x))
57
+;;  (each (x from: data) (draw-shadow obj: x))
58
+;;  (each (x from: data) (draw-body obj: x)))

Loading…
Cancel
Save