google+javascriptbanktwitter@js_bankfacebook@jsbankrss@jsbank






JavaScript với HTML5 vs ActionScript 3 với Flash trong đồ họa - Ai sẽ thắng? Có lẽ không cần phải giới thiệu nhiều thì mọi người cũng biết khá nhiều thông tin về HTML5 và Flash - hai công nghệ này đang này càng được phát triển và hoàn thiện để giành lấy sự ủng hộ của các nhà phát triển web.

Trong bài viết hôm nay, jsB@nk xin giới thiệu với bạn cuộc so găng của hai công nghệ web này trong một trận thi đấu vẽ vời đơn giản: tạo ảnh một biểu tượng cảnh báo với các dòng mã lệnh. Trang bị vũ khí của hai bên: HTML5 dùng tập lênh canvas với sự hỗ trợ của JavaScript, Flash với sự hỗ trợ của ActionScript 3.

Mặc dù tác giả không cho biết công nghệ nào thắng cuộc so găng này, nhưng riêng jsB@nk, dựa trên kết quả cuối cùng, cảm nhận rằng hình ảnh do HTML5 tạo ra có màu sắc trông thực hơn; nhưng đây cũng chỉ là một phép thử đơn giản và hai công nghệ này vẫn còn đang trong quá trình hoàn thiện. Bạn vui lòng vào trang trong để xem chi tiết cuộc so găng này.


Miễn phí web hosting 1 năm đầu tại iPage



Nếu bạn vẫn còn đang tìm kiếm một nhà cung cấp hosting đáng tin cậy, tại sao không dành chút thời gian để thử với iPage, chỉ với không quá 40.000 VNĐ/tháng, nhưng bạn sẽ được khuyến mãi kèm với quà tặng trị giá trên 10.000.0000 VNĐ nếu thanh toán cho 24 tháng ~ 900.000 VNĐ?

Có trên 1 triệu khách hàng hiện tại của iPage đã & đang hài lòng với dịch vụ, tuyệt đối chắc chắn bạn cũng sẽ hài lòng giống họ! Quan trọng hơn, khi đăng ký sử dụng web hosting tại iPage thông qua sự giới thiệu của chúng tôi, bạn sẽ được hoàn trả lại toàn bộ số tiền bạn đã sử dụng để mua web hosting tại iPage. Wow, thật tuyệt vời! Bạn không phải tốn bất kì chi phí nào mà vẫn có thể sử dụng miễn phí web hosting chất lượng cao tại iPage trong 12 tháng đầu tiên. Chỉ cần nói chúng tôi biết tài khoản của bạn sau khi đăng ký.

Nếu muốn tìm hiểu thêm về ưu / nhược điểm của iPage, bạn hãy đọc đánh giá của ChọnHostViệt.com nhé!
Thử iPage miễn phí cho năm đầu tiên NGAY

Create the Inner Stroke Path


Next we create a smaller triangle within our first triangle. Later we will stroke it and utilize standard properties to curve the border of our stroke for us.

Triangular Inner Path to Stroke

// Create the inner border path
context.beginPath();
context.moveTo(canvasWidth/2, this.padding + this.lineWidth);
context.lineTo((canvasWidth + this.width)/2 - this.lineWidth, this.padding + this.height - this.lineWidth/2);
context.lineTo((canvasWidth - this.width)/2 + this.lineWidth, this.padding + this.height - this.lineWidth/2);
context.lineTo(canvasWidth/2, this.padding + this.lineWidth);
context.closePath();
// Create the inner border path
var strokePath:GraphicsPath = new GraphicsPath(new Vector.(), new Vector.());
strokePath.moveTo(canvasWidth/2, padding + innerBorder);
strokePath.lineTo((canvasWidth + iconWidth)/2 - innerBorder, padding + iconHeight - innerBorder/2);
strokePath.lineTo((canvasWidth - iconWidth)/2 + innerBorder, padding + iconHeight - innerBorder/2);
strokePath.lineTo(canvasWidth/2, padding + innerBorder);

Bang!


With any icon, we have a message. The warning standard is an exclamation point (aka a "bang" character) which we add in the center of our icon. We could use a text representation but we will not do that for a various reasons (the user might not have that font, the size cost for embedding an entire typeface just for one character is not worth it, etc.)

exclamation point path

// Create the text (aka bang) path
context.beginPath();	
// Top
context.moveTo(canvasWidth/2 - 8, this.padding + 45);			
context.quadraticCurveTo(canvasWidth/2, this.padding + 35,  canvasWidth/2 + 8, this.padding + 45);
// Bottom
context.lineTo(canvasWidth/2 + 3, this.padding + 66);
context.quadraticCurveTo(canvasWidth/2, this.padding + 78, canvasWidth/2 - 3, this.padding + 66);
// Close path
context.lineTo(canvasWidth/2 - 8, this.padding + 44);
// Create the text (aka bang) path
var bangPath:GraphicsPath = new GraphicsPath(new Vector.(), new Vector.());
// Top
bangPath.moveTo(canvasWidth/2 - 8, padding + 45);			
bangPath.curveTo(canvasWidth/2, padding + 35, canvasWidth/2 + 8, padding + 45);
// Bottom
bangPath.lineTo(canvasWidth/2 + 3, padding + 66);
bangPath.curveTo(canvasWidth/2, padding + 78, canvasWidth/2 - 3, padding + 66);
// Close path
bangPath.lineTo(canvasWidth/2 - 8, padding + 44);

Again the major difference between the two approaches are the methods quadraticCurveTo versus curveTo.

Exclamation 'Point'


To finish our bang character, we add a circle:

// Draw dot
var radius = 5;
var centerX = canvasWidth/2;
var centerY = this.padding + 84;
context.moveTo(centerX, centerY - radius);
context.quadraticCurveTo(centerX + radius, centerY - radius, centerX + radius, centerY);
context.quadraticCurveTo(centerX + radius, centerY + radius, centerX, centerY + radius);
context.quadraticCurveTo(centerX - radius, centerY + radius, centerX - radius, centerY);
context.quadraticCurveTo(centerX - radius, centerY - radius, centerX, centerY - radius);
context.closePath();
// Draw Dot
var radius:Number = 5;
var centerX:Number = canvasWidth/2;
var centerY:Number = padding + 84;
bangPath.moveTo(centerX, centerY - radius);
bangPath.curveTo(centerX + radius, centerY - radius, centerX + radius, centerY);
bangPath.curveTo(centerX + radius, centerY + radius, centerX, centerY + radius);
bangPath.curveTo(centerX - radius, centerY + radius, centerX - radius, centerY);
bangPath.curveTo(centerX - radius, centerY - radius, centerX, centerY - radius);

JavaScript and ActionScript have more efficient ways to create circles including the methods arc and drawCircle respectively.

Draw Inside the Lines


The paths are complete:

Warning Icon Path

In JavaScript and ActionScript and you won't actually see the path until assign a fill or stroke to them. The following code defines what the fills and strokes will look like:

// Background Gradient Fill
var backFill = context.createLinearGradient(0, this.padding, 0, this.padding + this.height);
backFill.addColorStop(0.55, this.primaryColor);
backFill.addColorStop(0.55, this.tertiaryColor);
backFill.addColorStop(1, this.secondaryColor + " transparent");

// Text and Stroke Fill 
bangFill = context.createLinearGradient(0, this.padding, 0, this.padding + this.height);
bangFill.addColorStop(0, "#555");
bangFill.addColorStop(1, "#333");

// Stroke
context.lineWidth = this.lineWidth;
context.lineJoin = "round";	
context.strokeStyle = bangFill;
// Background Gradient Fill 
var backFill:GraphicsGradientFill = new GraphicsGradientFill(); 
backFill.colors = [secondaryColor, tertiaryColor, primaryColor]; 
backFill.ratios = [iconHeight/2, iconHeight, iconHeight];
backFill.matrix = new Matrix();
backFill.matrix.createGradientBox(iconWidth, iconHeight, 3*Math.PI/2, 0,  padding); 

// Text and Stroke Fill 
var bangFill:GraphicsGradientFill = new GraphicsGradientFill(); 
bangFill.colors = [0x555555, 0x333333];  
bangFill.matrix = new Matrix(); 
bangFill.matrix.createGradientBox(iconWidth, iconHeight, Math.PI/2, 0, padding);
			
// Transparent Fill
var transparentFill:GraphicsSolidFill = new GraphicsSolidFill(); 
transparentFill.alpha = 0;
			
// Stroke
var stroke:GraphicsStroke = new GraphicsStroke(lineWidth); 
stroke.joints = JointStyle.ROUND;
stroke.fill = bangFill;

Draw


// Fill the background path
context.fillStyle = backFill;
context.fill();                    

// Stroke the inner border path
context.stroke();                    

// Fill the bang path
context.fillStyle = bangFill;
context.fill();	
// Fill and stroke all paths
var iconGraphics:Vector. = new Vector.(); 
iconGraphics.push(backFill, trianglePath, bangFill, bangPath, transparentFill, stroke, strokePath); 
graphics.drawGraphicsData(iconGraphics);

JavaScript applies the path fills on the HTML5 Canvas as each one is completed. ActionScript 3 can apply all path fills and strokes all at one time using the method drawGraphicsData.


We see the results below:

Warning Icon with no border

A Subtle Shadow


We are almost there, but there is something missing. Let's add a subtle shadow.

// Add a subtle shadow
context.shadowOffsetX = 0;
context.shadowOffsetY = 0;
context.shadowBlur = 10;
context.shadowColor = "#000000";
// Add a subtle shadow
filters = new Array(new DropShadowFilter(0, 0, 0x000000, 1, 10, 10));

Final Images


Warning Icon in JavaScript and ActionScript Compared

Download Source


References


iPhoneKer.com
Save up to 630$ when buy new iPhone 15

GateIO.gomymobi.com
Free Airdrops to Claim, Share Up to $150,000 per Project

https://tooly.win
Open tool hub for free to use by any one for every one with hundreds of tools

chatGPTaz.com, chatGPT4.win, chatGPT2.fun, re-chatGPT.com
Talk to ChatGPT by your mother language

Dall-E-OpenAI.com
Generate creative images automatically with AI

AIVideo-App.com
Render creative video automatically with AI

JavaScript theo ngày


Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web