Skip to content

Commit

Permalink
Added save functionality, adjusted some variables.
Browse files Browse the repository at this point in the history
+ Save current bitmap when pressing SPACEBAR. Saves at 300% scale.
* Messed with variables a bit
+ Added four more source files. Randomly picked at startup.
  • Loading branch information
mouseas committed Jan 28, 2012
1 parent ad85148 commit e7ebcbc
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 21 deletions.
Binary file modified bin/LineArt.swf
Binary file not shown.
Binary file removed lib/source.jpg
Binary file not shown.
Binary file added lib/source000.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/source001.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/source002.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/source003.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/source004.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions obj/LineArtConfig.old
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<path-element>C:\Users\Martin\LineArt\src\Main.as</path-element>
</file-specs>
<default-background-color>#CCCCCC</default-background-color>
<default-frame-rate>12</default-frame-rate>
<default-frame-rate>30</default-frame-rate>
<default-size>
<width>960</width>
<height>960</height>
<width>860</width>
<height>860</height>
</default-size>
</flex-config>
6 changes: 3 additions & 3 deletions obj/LineArtConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<path-element>C:\Users\Martin\LineArt\src\Main.as</path-element>
</file-specs>
<default-background-color>#CCCCCC</default-background-color>
<default-frame-rate>12</default-frame-rate>
<default-frame-rate>30</default-frame-rate>
<default-size>
<width>960</width>
<height>960</height>
<width>860</width>
<height>860</height>
</default-size>
</flex-config>
8 changes: 4 additions & 4 deletions src/ArtPoint.as
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ package {
public var rInner:Number;
public var offset:Number;

public static const centerX:Number = 480;
public static const centerY:Number = 480;
public static const offsetX:Number = 480;
public static const offsetY:Number = 480;
public static const centerX:Number = 430;
public static const centerY:Number = 430;
public static const offsetX:Number = 430;
public static const offsetY:Number = 430;

public function ArtPoint(_radius:Number, _rOuter:Number, _rInner:Number, _offset:Number) {
radius = _radius;
Expand Down
63 changes: 52 additions & 11 deletions src/Main.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package
{
import flash.display.*;
import flash.events.*;
import flash.ui.Keyboard;
import flash.net.FileReference;
import flash.utils.*;
import flash.geom.*;
import com.adobe.images.PNGEncoder;

/**
* ...
Expand All @@ -12,7 +15,11 @@ package
public class Main extends Sprite
{

[Embed(source = "../lib/source.jpg")]public var sourceImage:Class;
[Embed(source = "../lib/source000.jpg")]public var sourceImage000:Class;
[Embed(source = "../lib/source001.jpg")]public var sourceImage001:Class;
[Embed(source = "../lib/source002.jpg")]public var sourceImage002:Class;
[Embed(source = "../lib/source003.jpg")]public var sourceImage003:Class;
[Embed(source = "../lib/source004.jpg")]public var sourceImage004:Class;

public var colorBitmapData:BitmapData;

Expand All @@ -34,15 +41,30 @@ package

private function init(e:Event = null):void
{
// Pick a random source image.
var whichSource:int = (int)(Math.random() * 5);
var pic:Bitmap;
if (whichSource == 0) {
pic = new sourceImage000;
} else if (whichSource == 1) {
pic = new sourceImage001;
} else if (whichSource == 2) {
pic = new sourceImage002;
} else if (whichSource == 3) {
pic = new sourceImage003;
} else if (whichSource == 4) {
pic = new sourceImage004;
} else {
pic = new sourceImage000;
trace("whichSource out of range: " + whichSource);
}

removeEventListener(Event.ADDED_TO_STAGE, init);
colorBitmapData = new BitmapData(960, 960, true, 0x000000);
var pic:Bitmap = new sourceImage();
var bmd:BitmapData = pic.bitmapData
colorBitmapData.draw(bmd);
colorBitmapData = pic.bitmapData;
pic = null;
bmd = null;
//addChild(new Bitmap(colorBitmapData));

myBitmapData = new BitmapData(960, 960, true, 0x000000);
myBitmapData = new BitmapData(860, 860, true, 0x000000);
myBitmap = new Bitmap(myBitmapData, "auto", true);
addChild(myBitmap);

Expand All @@ -55,27 +77,46 @@ package

points = new Array();
points.push(new ArtPoint(50, 200, 100, 0));
points.push(new ArtPoint(100, 0, 200, 480));
points.push(new ArtPoint(100, 0, 200, 420));
points.push(new ArtPoint(150, 100, 100, 50));

addEventListener(Event.ENTER_FRAME, drawLines);
stage.addEventListener(KeyboardEvent.KEY_DOWN, saveResult);
}

private function drawToBitmapData(event:TimerEvent):void {
myBitmapData.draw(drawLayer);

drawLayer.graphics.clear();

}

private function saveResult(event:KeyboardEvent):void {
trace ("keyboard event");
if (event.keyCode == Keyboard.SPACE) {
var resultBMD:BitmapData = new BitmapData(myBitmapData.width * 3, myBitmapData.height * 3, true, 0x000000);

var transMatrix:Matrix = new Matrix(3, 0, 0, 3, 0, 0);
var rect:Rectangle = new Rectangle(0, 0, myBitmapData.width * 3, myBitmapData.height * 3);
resultBMD.draw(myBitmapData, transMatrix, null, null, rect, true);

var bytes:ByteArray = PNGEncoder.encode(resultBMD);

var fileRef:FileReference = new FileReference();
fileRef.save(bytes, "result.jpg");
} else {
trace ("Key was pressed, but not SPACEBAR.");
}
}

private function drawLines(e:Event):void {
points[0].setPos(time);
points[1].setPos(time);
points[1].setPos(time * 1.2);
points[2].setPos(time);

var color1:Number = colorBitmapData.getPixel((int)(points[1].x), (int)(points[1].y));
var color2:Number = colorBitmapData.getPixel((int)(points[2].x), (int)(points[2].y));

drawLayer.graphics.clear();

drawLayer.graphics.moveTo(points[0].x, points[0].y);
drawLayer.graphics.lineStyle(10, color1, 0.1);
drawLayer.graphics.lineTo(points[1].x, points[1].y);
Expand Down
141 changes: 141 additions & 0 deletions src/com/adobe/images/PNGEncoder.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
Copyright (c) 2008, Adobe Systems Incorporated
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Adobe Systems Incorporated nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.adobe.images
{
import flash.geom.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.utils.ByteArray;

/**
* Class that converts BitmapData into a valid PNG
*/
public class PNGEncoder
{
/**
* Created a PNG image from the specified BitmapData
*
* @param image The BitmapData that will be converted into the PNG format.
* @return a ByteArray representing the PNG encoded image data.
* @langversion ActionScript 3.0
* @playerversion Flash 9.0
* @tiptext
*/
public static function encode(img:BitmapData):ByteArray {
// Create output byte array
var png:ByteArray = new ByteArray();
// Write PNG signature
png.writeUnsignedInt(0x89504e47);
png.writeUnsignedInt(0x0D0A1A0A);
// Build IHDR chunk
var IHDR:ByteArray = new ByteArray();
IHDR.writeInt(img.width);
IHDR.writeInt(img.height);
IHDR.writeUnsignedInt(0x08060000); // 32bit RGBA
IHDR.writeByte(0);
writeChunk(png,0x49484452,IHDR);
// Build IDAT chunk
var IDAT:ByteArray= new ByteArray();
for(var i:int=0;i < img.height;i++) {
// no filter
IDAT.writeByte(0);
var p:uint;
var j:int;
if ( !img.transparent ) {
for(j=0;j < img.width;j++) {
p = img.getPixel(j,i);
IDAT.writeUnsignedInt(
uint(((p&0xFFFFFF) << 8)|0xFF));
}
} else {
for(j=0;j < img.width;j++) {
p = img.getPixel32(j,i);
IDAT.writeUnsignedInt(
uint(((p&0xFFFFFF) << 8)|
(p>>>24)));
}
}
}
IDAT.compress();
writeChunk(png,0x49444154,IDAT);
// Build IEND chunk
writeChunk(png,0x49454E44,null);
// return PNG
return png;
}

private static var crcTable:Array;
private static var crcTableComputed:Boolean = false;

private static function writeChunk(png:ByteArray,
type:uint, data:ByteArray):void {
if (!crcTableComputed) {
crcTableComputed = true;
crcTable = [];
var c:uint;
for (var n:uint = 0; n < 256; n++) {
c = n;
for (var k:uint = 0; k < 8; k++) {
if (c & 1) {
c = uint(uint(0xedb88320) ^
uint(c >>> 1));
} else {
c = uint(c >>> 1);
}
}
crcTable[n] = c;
}
}
var len:uint = 0;
if (data != null) {
len = data.length;
}
png.writeUnsignedInt(len);
var p:uint = png.position;
png.writeUnsignedInt(type);
if ( data != null ) {
png.writeBytes(data);
}
var e:uint = png.position;
png.position = p;
c = 0xffffffff;
for (var i:int = 0; i < (e-p); i++) {
c = uint(crcTable[
(c ^ png.readUnsignedByte()) &
uint(0xff)] ^ uint(c >>> 8));
}
c = uint(c^uint(0xffffffff));
png.position = e;
png.writeUnsignedInt(c);
}
}
}

0 comments on commit e7ebcbc

Please sign in to comment.