add airbrush size (last tool option "gotten in")

They're ugly and incorrect and some are completely non-functioning, but
they're in there. Hmm, I think my standards have lowered since starting
this project. At least in the "mimicking mspaint to pixel-perfection"
area.
main
Isaiah Odhner 2014-05-23 03:55:19 -04:00
parent bfd8e5aa8c
commit 9f9122465b
5 changed files with 38 additions and 14 deletions

2
app.js
View File

@ -439,7 +439,7 @@ $canvas.on("mousedown", function(e){
if(selected_tool.continuous === "time"){ if(selected_tool.continuous === "time"){
var iid = setInterval(function(){ var iid = setInterval(function(){
tool_go(); tool_go();
}, 10); }, 5);
} }
$G.one("mouseup", function(e, canceling){ $G.one("mouseup", function(e, canceling){
button = undefined; button = undefined;

View File

@ -30,10 +30,10 @@ function draw_ellipse(ctx, x, y, w, h){
var rx = Math.cos(r) * w/2; var rx = Math.cos(r) * w/2;
var ry = Math.sin(r) * h/2; var ry = Math.sin(r) * h/2;
ctx.fillRect( ctx.fillRect(
r1(cx-rx), r1(cx+rx),
r1(cy-ry), r1(cy+ry),
r2(rx*2), r2(-rx*2),
r2(ry*2) r2(-ry*2)
); );
} }
}else{ }else{

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

View File

@ -18,7 +18,8 @@ html, body, .jspaint {
align-items: center; align-items: center;
justify-content: space-around; justify-content: space-around;
} }
.jspaint-choose-brush { .jspaint-choose-brush,
.jspaint-choose-airbrush-size {
flex-flow: row wrap; flex-flow: row wrap;
justify-content: space-around; justify-content: space-around;
align-content: space-around; align-content: space-around;

View File

@ -2,7 +2,7 @@
var brush_canvas = E("canvas"); var brush_canvas = E("canvas");
var brush_ctx = brush_canvas.getContext("2d"); var brush_ctx = brush_canvas.getContext("2d");
var brush_shape = "circle"; var brush_shape = "circle";
var brush_size = 3; var brush_size = 5;
var eraser_size = 8; var eraser_size = 8;
var airbrush_size = 9; var airbrush_size = 9;
var pencil_size = 1; var pencil_size = 1;
@ -228,9 +228,31 @@ var $choose_magnification = $Choose(
} }
).addClass("jspaint-choose-magnification"); ).addClass("jspaint-choose-magnification");
var _ = "<i style='font-family:monospace;font-size:8px;text-align:center'></i>"; var airbrush_sizes = [9, 16, 24];
var $choose_airbrush_size = $Choose(
var $choose_airbrush_size = $(_).text("choose airbrush size"); airbrush_sizes,
function(size, is_chosen){
var e = E("div");
var sprite_width = 72;
var pos = airbrush_sizes.indexOf(size) / airbrush_sizes.length * -sprite_width;
var is_bottom = size === 24;
var _ = 4 * !is_bottom;
$(e).css({
backgroundImage: "url(images/options-airbrush-size.png)",
backgroundPosition: pos - _ + "px 0px",
width: (72 / 3 - _*2) + "px",
height: "23px",
webkitFilter: is_chosen ? "invert()" : "" // @todo: invert and upscale with canvas
});
return e;
},
function(size){
airbrush_size = size;
},
function(size){
return size === airbrush_size;
}
).addClass("jspaint-choose-airbrush-size");
var $choose_transparency = $Choose( var $choose_transparency = $Choose(
["opaque", "transparent"], ["opaque", "transparent"],
@ -496,11 +518,12 @@ tools = [{
cursor: ["airbrush", [7, 22], "crosshair"], cursor: ["airbrush", [7, 22], "crosshair"],
continuous: "time", continuous: "time",
paint: function(ctx, x, y){ paint: function(ctx, x, y){
for(var i=0; i<25; i++){ var r = airbrush_size / 2;
var rx = (Math.random()*2-1) * airbrush_size; for(var i = 0; i < 6 + r/5; i++){
var ry = (Math.random()*2-1) * airbrush_size; var rx = (Math.random()*2-1) * r;
var ry = (Math.random()*2-1) * r;
var d = rx*rx + ry*ry; var d = rx*rx + ry*ry;
if(d <= airbrush_size * airbrush_size){ if(d <= r * r){
ctx.fillRect(x + ~~rx, y + ~~ry, 1, 1); ctx.fillRect(x + ~~rx, y + ~~ry, 1, 1);
} }
} }