Changed the line syntax to (line x1 y1 x2 y2)

This commit is contained in:
Devine Lu Linvega 2019-07-24 20:29:03 +09:00
parent 33574979cd
commit 1c7b74d582
13 changed files with 71 additions and 140 deletions

View File

@ -42,7 +42,7 @@ Additional functions can be found in the [includes](https://github.com/hundredra
- `(size w h)` Returns a size shape.
- `(rect x y w h)` Returns a rect shape.
- `(circle cx cy r)` Returns a circle shape.
- `(line a b)` Returns a line shape.
- `(line ax ay bx by)` Returns a line shape.
- `(text x y p t ~f)` Returns a text shape.
- `(svg x y d)` Returns a svg shape.
- `(stroke ~shape)` Strokes a shape.
@ -55,7 +55,7 @@ Additional functions can be found in the [includes](https://github.com/hundredra
- `(crop rect)` Crop canvas to rect.
- `(clone a b)`
- `(theme variable ~el)`
- `(gradient [x1 y1 x2 y2] ~colors 'black'])`
- `(gradient line ~colors 'black'])`
- `(pixels rect fn q)`
- `(saturation pixel ~q)`
- `(contrast pixel ~q)`
@ -67,10 +67,10 @@ Additional functions can be found in the [includes](https://github.com/hundredra
- `(mod a b)` Returns the modulo of a and b.
- `(clamp val min max)` Clamps a value between min and max.
- `(step val step)`
- `(floor)`
- `(min)`
- `(max)`
- `(ceil)`
- `(floor)` round down to the nearest integer.
- `(sin)`
- `(cos)`
- `(log)` caclulates on the base of e.

View File

@ -70,8 +70,8 @@ function Library (ronin) {
return { cx, cy, r }
}
this.line = (a, b) => { // Returns a line shape.
return { a, b }
this.line = (ax, ay, bx, by) => { // Returns a line shape.
return { a: this.pos(ax, ay), b: this.pos(bx, by) }
}
this.text = (x, y, p, t, f = 'Arial') => { // Returns a text shape.
@ -146,8 +146,8 @@ function Library (ronin) {
// Gradients
this.gradient = ([x1, y1, x2, y2], colors = ['white', 'black']) => {
return ronin.surface.linearGradient(x1, y1, x2, y2, colors)
this.gradient = (line, colors = ['white', 'black']) => {
return ronin.surface.linearGradient(line.a.x, line.a.y, line.b.x, line.b.y, colors)
}
// Pixels

View File

@ -1,56 +0,0 @@
; guides
(clear)
(stroke
(frame) 1 "red")
(stroke
(line
(pos 0 0)
(pos
(of
(frame) "w")
(of
(frame) "h"))) 1 "red")
(stroke
(line
(pos
(of
(frame) "w") 0)
(pos 0
(of
(frame) "h"))) 1 "red")
(stroke
(line
(pos
(div
(of
(frame) "w") 2) 0)
(pos
(div
(of
(frame) "w") 2)
(of
(frame) "h"))) 1 "red")
(stroke
(line
(pos 0
(div
(of
(frame) "h") 2))
(pos
(div
(of
(frame) "w") 2)
(of
(frame) "h"))) 1 "#72dec2")
(stroke
(line
(pos
(div
(of
(frame) "w") 2) 0)
(pos
(of
(frame) "w")
(div
(of
(frame) "h") 2))) 1 "#72dec2")

View File

@ -0,0 +1,31 @@
; gradients
(clear)
;
(def radius (of (frame) :m))
;
(def gradient-line
(line
(of (frame) :c) 0
(of (frame) :c)
(of (frame) :h)))
;
(fill
(circle
(of (frame) :c)
(of (frame) :m)
radius)
(gradient gradient-line ("#72dec2" "white")))
;
(fill
(circle
(of (frame) :c)
(of (frame) :m)
(mul radius 0.75))
(gradient gradient-line ("white" "#72dec2")))
;
(fill
(circle
(of (frame) :c)
(of (frame) :m)
(mul radius 0.5))
(gradient gradient-line ("#72dec2" "white")))

View File

@ -18,7 +18,5 @@
; draw line
(stroke
(line
(pos (sub center-w rad) center-h)
(pos (add center-w rad) center-h)))
(line (sub center-w rad) center-h (add center-w rad) center-h))
(stroke (text 10 170 200 "HELL") 2 "pink")

View File

@ -1,12 +0,0 @@
; gradients
(clear)
(fill
(svg 0 0 "M405,15 L405,15 L150,150 L195,90 L240,135 L120,195 L75,90 L135,165 L120,225 L90,240 L60,210 L90,150 L255,180 L285,180 L285,165 ")
(gradient
(0 -50 600 175)
("red" "orange" "blue" "green")))
(stroke
(svg 0 0 "M255,60 L255,60 L135,180 L75,60 L195,210 L120,225 L105,225 L165,255 L225,195 L255,135 L285,150") 1
(gradient
(50 0 180 0)
("black" "white" "blue" "green")))

View File

@ -1,20 +0,0 @@
; welcome to ronin - v2.1
(clear)
; ronin path
(def align {:x
(sub
(of
(frame) :center) 500) :y
(sub
(of
(frame) :middle) 150)})
; outline
(fill
(svg
(of align :x)
(of align :y) "M15,15 L15,15 L285,15 L285,285 L15,285 Z") "#fff")
; stroke
(stroke
(svg
(of align :x)
(of align :y) "M60,60 L195,60 A45,45 0 0,1 240,105 A45,45 0 0,1 195,150 L60,150 M195,150 A45,45 0 0,1 240,195 L240,240 ") 5 "#000")

View File

@ -1,25 +1,24 @@
(resetTransform)
(clear)
(defn branch
(v)
(if
(gt v 0)
(defn branch
(v)
(if
(gt v 0)
(
(scale 0.95)
(stroke
(line (pos 0 0) (pos 100 100))
10 "white")
(move 100 100)
(pushTransform)
(rotate (div v 50))
(branch (sub v 1))
(popTransform)
(pushTransform)
(rotate (div v -50))
(branch (sub v 1))
(popTransform)
)
)
)
(scale 0.95)
(stroke
(line 0 0 100 100) 2 "white")
(move 100 100)
(pushTransform)
(rotate
(div v 50))
(branch
(sub v 1))
(popTransform)
(pushTransform)
(rotate
(div v -50))
(branch
(sub v 1))
(popTransform)) ))
(branch 10)

View File

@ -13,7 +13,7 @@
))
;
(defn when-animate () (
(stroke (line prev-pos mouse-pos) 4 "#72dec2")
(stroke (line (of prev-pos :x) (of prev-pos :y) (of mouse-pos :x) (of mouse-pos :y)) 4 "#72dec2")
(move w h)
(rotate 0.002)
(scale 0.998)

View File

@ -5,9 +5,8 @@
(cx cy r a)
(
(stroke
(line
(pos cx cy)
(circle-pos cx cy r a)) 2 "white")))
(line cx cy (of (circle-pos cx cy r a) :x) (of (circle-pos cx cy r a) :y)
) 2 "white")))
;
(defn draw-star
(cx cy r c)

View File

@ -33,15 +33,13 @@
(def y
(elevation i))
(stroke
(line
(pos x
(elevation
(sub i 1)))
(pos
(add x seg-width)
(elevation i))) 4
(line x
(elevation
(sub i 1))
(add x seg-width)
(elevation i)) 4
(gradient
(50 0
(line 50 0
(of
(frame) :w) 0)
("#ffb545" "#72dec2")))))

View File

@ -1,19 +1,13 @@
; this demo shows how to use the mouse events.
;
(defn redraw
(e)
(
(clear)
; vertical line
(stroke
(line
(pos
(of e :x) 0) e) 2 "#ff0000")
(stroke (line (of e :x) 0 (of e :x) (of e :y)) 2 "#ff0000")
; horizontal line
(stroke
(line
(pos 0
(of e :y)) e) 2 "#72dec2")
(line 0 (of e :y) (of e :x) (of e :y)) 2 "#72dec2")
; circle
(stroke
(circle

View File

@ -16,7 +16,7 @@
(of e :is-down)
(
(stroke
(line prev-pos e) 2 "white")
(line (of prev-pos :x) (of prev-pos :y) (of e :x) (of e :y)) 2 "white")
(set prev-pos :x
(of e :x) :y
(of e :y))))))