Added new Bang() cmd and began building filters.

This commit is contained in:
Devine Lu Linvega 2016-11-14 21:11:48 -08:00
parent d8b4559f8a
commit 7dbfbd748f
12 changed files with 96 additions and 51 deletions

View File

@ -4,13 +4,14 @@
```
@ 600x400 ; New canvas of size 600w and 400h
@ 100x100 #ff0000 ; New canvas of size 100w and 100h with red background
@ ? ; Clear canvas
@ ! ; Clear canvas
```
##Save File
```
$ new_name ; Create a new file with name
$ 3 ; Save to temporary storage, accessible with Load
$ ! ; Clear temporary storage
```
##Load File
@ -27,32 +28,41 @@ $ 3 ; Save to temporary storage, accessible with L
> 10,0 ; Add pointer at pos
> 400x0 ; Add mirror pointer, at 400x
> 4 #ff0000 ; Red brush, Size 4
> ? ; Remove last pointer
> ! ; Remove all pointers
```
##Guides
```
| 10,10 100x100 ; Draw a guide
| -100,0 ; Draw a grid at every 100px
| ? ; Remove guides
| ! ; Remove all guides
```
##Filters*
```
: saturation 0.5 ; Set image saturation to 0.5
: balance red 0.9 0.4 0.7 ; Set color balance red to 0.9 0.4 0.7
: balance white 0.7 0.7 0.7 ; Set color balance white to 0.7 0.7 0.7
: sharpen 0.5 ; Sharpen image to 50%
```
##Translate*
```
^ 0,10 ; Translate 10px vertically
^ 20,20 100x100 40,40 ; Translate a specific portion to a specific location
^ -1280x800 ; Flip image horizontally
```
##Zoom*
```
= 75 ; Zoom factor
= ? ; Zoom 100%
= 75 ; Zoom factor of 75%
= ! ; Zoom 100%
```
##Layers*
```
# 3 ; Layer 3
# ? ; Layer 1
# ! ; Layer 1
```
#Units*
@ -61,9 +71,6 @@ $ 3 ; Save to temporary storage, accessible with L
5,7 ; position: 5x 7y
7x9 ; rect: 7w 9h
#ff0000 ; color: red
?5 ; random: 0..5
45' ; degree: 45/365
```
- Mirror
- Filter
- Noise
-

View File

@ -9,6 +9,7 @@
<script type="text/javascript" src="scripts/ronin.module.js"></script>
<script type="text/javascript" src="scripts/ronin.canvas.js"></script>
<script type="text/javascript" src="scripts/ronin.filter.js"></script>
<script type="text/javascript" src="scripts/ronin.overlay.js"></script>
<script type="text/javascript" src="scripts/ronin.file.js"></script>
<script type="text/javascript" src="scripts/ronin.hint.js"></script>

View File

@ -26,9 +26,6 @@ function Commander(element,element_input)
case "@":
ronin.canvas.active(cmd);
break;
case "~": // TODO
ronin.memory.active(cmd);
break;
case "$":
ronin.file.save(cmd);
break;
@ -69,10 +66,6 @@ function Commander(element,element_input)
ronin.canvas.passive(this.cmd);
ronin.module = ronin.canvas;
break;
case "~":
ronin.memory.passive(this.cmd);
ronin.module = ronin.memory;
break;
case "/":
ronin.file.passive(this.cmd);
ronin.module = ronin.file;

View File

@ -2,6 +2,8 @@ function Brush()
{
Module.call(this);
this.pointers = [new Pointer(new Position())];
this.position = new Position();
this.is_drawing = false;
this.size = 1;
@ -12,6 +14,8 @@ function Brush()
this.active = function(cmd)
{
if(cmd.bang()){ this.pointers = []; }
var pointer = new Pointer();
if(cmd.position()){
@ -20,7 +24,10 @@ function Brush()
if(cmd.rect()){
pointer.mirror = cmd.rect();
}
if(cmd.rect() || cmd.position()){
if(cmd.noise()){
pointer.noise = cmd.noise();
}
if(cmd.rect() || cmd.position() || cmd.noise()){
this.add_pointer(pointer);
}
if(cmd.color()){
@ -37,16 +44,17 @@ function Brush()
this.hint = function(cmd)
{
if(cmd.bang()){ return "Brush: Erase all pointers"; }
var hint_value = (cmd.value() ? "Size "+cmd.value()+" " : "");
var hint_position = (cmd.position() ? "Position "+cmd.position().x+","+cmd.position().y+" " : "");
var hint_color = (cmd.color() ? "Color "+cmd.color().hex+" " : "");
var hint_rect = (cmd.rect() ? "Mirror "+cmd.rect().width+"/"+cmd.rect().height+" " : "");
var hint_noise = (cmd.noise() ? "Noise 0.."+cmd.noise()+" " : "");
return "Brush: "+hint_value+hint_position+hint_color+hint_rect;
return "Brush: "+hint_value+hint_position+hint_color+hint_rect+hint_noise;
}
this.pointers = [new Pointer(new Position())];
this.add_pointer = function(pointer)
{
this.pointers.push(pointer);

View File

@ -2,6 +2,7 @@ function Pointer(offset = new Position(), color = new Color('000000'))
{
this.offset = offset;
this.mirror = null;
this.noise = null;
this.position_prev = null;
this.draw = function()
@ -9,16 +10,23 @@ function Pointer(offset = new Position(), color = new Color('000000'))
if(!this.position_prev){this.position_prev = this.position(); }
if(ronin.brush.size < 0){ this.erase(); return; }
var position = this.position();
if(this.noise){
position.x += (Math.random() * this.noise) - (this.noise/2);
position.y += (Math.random() * this.noise) - (this.noise/2);
}
context.beginPath();
context.moveTo(this.position_prev.x,this.position_prev.y);
context.lineTo(this.position().x,this.position().y);
context.lineTo(position.x,position.y);
context.lineCap="round";
context.lineWidth = this.thickness();
context.strokeStyle = ronin.brush.color.rgba();
context.stroke();
context.closePath();
this.position_prev = this.position();
this.position_prev = position;
}
this.erase = function()

View File

@ -6,16 +6,18 @@ function Canvas(element)
this.active = function(cmd)
{
if(cmd.bang()){ this.context().clearRect(0, 0, canvas.width, canvas.height); }
if(cmd.rect()){
this.resize(cmd.rect());
ronin.overlay.resize(cmd.rect());
}
if(cmd.color()){
this.element.getContext('2d').beginPath();
this.element.getContext('2d').rect(0, 0, canvas.width, canvas.height);
this.element.getContext('2d').fillStyle = cmd.color().hex;
this.element.getContext('2d').fill();
this.context().beginPath();
this.context().rect(0, 0, canvas.width, canvas.height);
this.context().fillStyle = cmd.color().hex;
this.context().fill();
}
}
@ -28,6 +30,8 @@ function Canvas(element)
this.hint = function(cmd)
{
if(cmd.bang()){ return "Canvas: Clear"; }
var hint_rect = (cmd.rect() ? "Resize to "+cmd.rect().width+"px by "+cmd.rect().height+"px " : "");
var hint_color = (cmd.color() ? "Fill with color "+cmd.color().hex+" " : "");
@ -41,4 +45,9 @@ function Canvas(element)
this.element.setAttribute('width',rect.width+"px");
this.element.setAttribute('height',rect.height+"px");
}
this.context = function()
{
return this.element.getContext('2d');
}
}

View File

@ -6,6 +6,8 @@ function File()
this.active = function(cmd)
{
if(cmd.bang()){ this.storage = []; }
ronin.overlay.clear();
if(!cmd.position()){ return; }

19
scripts/ronin.filter.js Normal file
View File

@ -0,0 +1,19 @@
function Filter(element)
{
Module.call(this);
this.active = function(cmd)
{
console.log("Nothing to do.");
}
this.passive = function(cmd)
{
console.log("Nothing to do.");
}
this.hint = function(cmd)
{
return "Filter: ";
}
}

View File

@ -6,19 +6,5 @@ function Ronin()
this.brush = new Brush();
this.file = new File();
this.hint = new Hint();
this.fill = function(p)
{
cvSave = canvas.toDataURL("image/png");
context.beginPath();
context.rect(0, 0, canvas.width, canvas.height);
context.fillStyle = "#"+p[0];
context.fill();
var imgObj = new Image();
imgObj.src = cvSave;
context.drawImage(imgObj,0,0);
}
this.filter = new Filter();
}

View File

@ -13,11 +13,13 @@ function Overlay(element)
this.active = function(cmd)
{
if(cmd.bang()){ this.guides = []; }
}
this.hint = function(cmd)
{
if(cmd.bang()){ return "Overlay: Erase all guides"; }
var hint_position = (cmd.position() ? "Position "+cmd.position().x+","+cmd.position().y+" " : "");
var hint_rect = (cmd.rect() ? "Size "+cmd.rect().width+"px by "+cmd.rect().height+"px " : "");

View File

@ -42,4 +42,20 @@ function Command(cmd_array)
}
return null;
}
this.noise = function()
{
for (i = 0; i < this.cmd_array.length; i++) {
if(this.cmd_array[i].indexOf("?") >= 0){ return parseInt(this.cmd_array[i][1]); }
}
return null;
}
this.bang = function()
{
for (i = 0; i < this.cmd_array.length; i++) {
if(this.cmd_array[i].indexOf("!") >= 0){ return true; }
}
return null;
}
}

View File

@ -5,12 +5,6 @@ function Position(position_str = "0,0",y = null)
this.x = y ? position_str : parseFloat(this.position_str.split(",")[0]);
this.y = y ? y : parseFloat(this.position_str.split(",")[1]);
this.update = function(x,y)
{
this.x = x;
this.y = y;
}
this.is_equal = function(target)
{
if(target.x == this.x && target.y == this.y){ return true; }