惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
LangChain Blog
月光博客
月光博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
博客园_首页
T
Tailwind CSS Blog
P
Proofpoint News Feed
雷峰网
雷峰网
D
Darknet – Hacking Tools, Hacker News & Cyber Security
IT之家
IT之家
V
Vulnerabilities – Threatpost
阮一峰的网络日志
阮一峰的网络日志
C
CERT Recently Published Vulnerability Notes
Attack and Defense Labs
Attack and Defense Labs
S
Schneier on Security
Security Archives - TechRepublic
Security Archives - TechRepublic
L
Lohrmann on Cybersecurity
V
Visual Studio Blog
云风的 BLOG
云风的 BLOG
WordPress大学
WordPress大学
The Register - Security
The Register - Security
N
Netflix TechBlog - Medium
Hugging Face - Blog
Hugging Face - Blog
Project Zero
Project Zero
博客园 - 叶小钗
F
Full Disclosure
大猫的无限游戏
大猫的无限游戏
Latest news
Latest news
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
L
LINUX DO - 最新话题
Google DeepMind News
Google DeepMind News
P
Privacy International News Feed
I
InfoQ
F
Fortinet All Blogs
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Threatpost
T
Tenable Blog
B
Blog RSS Feed

MarcySutton.com RSS Feed

On Joining Khan Academy Developing anti-SLAPP policies for A11y Slack with Harvard Cyberlaw Clinic Focus on What Matters Celebrating One Year of Independence as Modern Sole Design, LLC Evinced is Pushing the Limits of Automated Accessibility Testing Content-visibility and Accessible Semantics Finding accessibility jobs in specialized companies and the mainstream Outsider Leverage and Accessibility Encouraging Open Source Contributions with Docs: a Self-Fulfilling Prophecy Remote Work and Van Life Salary and Career Growth Prototype Testing for Accessible Client-Side Routing On Great Leadership, Gatsby & Girl Develop It The Deal with Developer Advocacy Live Coding Accessibility Chapter Two at Deque 2017, in Music Writing winning abstracts Accessibility is a Civil Right 2016, a Year of Milestones Best of 2016 Music Links vs. Buttons in Modern Web Applications Accessibility and Performance I won an O Web Accessibility Resources This is what a developer looks like. What Wally On writing better captions for images What I’ve Learned Working on a Large Open-Source Framework Speak at your local elementary school. Button Focus Hell Page Scrolling in Mobile Safari & VoiceOver Accessibility Wins Notes from CSUN 2015 Protractor Accessibility Plugin Riding a bicycle to an accessibility conference 2014: One to Remember AngularJS Material Design & ngAria Summing Up JSConf EU 2014 How I Audit a Website for Accessibility Accessibility and the Shadow DOM: JSConf Australia 2014 CSUN 2014 Conference Recap Accessibility and the Shadow DOM Favorite Music 2013 Girl Develop It Web Accessibility Mobile Web Accessibility with VoiceOver Webstock & NZ 2013 Favorite Music 2012 Target Corporate Site Redesign: Accessible & Responsive Web Development Decibel Festival Recap 2012 Favorite Music 2011 Spiceboard: Wordpress Recipes for iPad POP Clock Favorite Music 2010 CSS + JS + Accessibility Zend Framework. NACCC Urban Type Sutton RV Simplexml in php 5 AS3 Load Workflow AS3 Mouse Events Holiday 2009 Why Outlook Sucks
Christmas JS1k
2010-12-29 · via MarcySutton.com RSS Feed

December 29, 2010

Gifted the benefit of R&D time at work, at the end of 2010 I submitted an entry to the Christmas JS1k contest along with my fellow POPsters. I got to geek out and spend work time creating something cutting-edge that I’m pretty proud of: a canvas drawing app!

My goals were to:

  • Learn enough native JS to complete an entry(!)
  • Use canvas
  • Keep usability in mind since it tends to go out the window when shaving off bytes: cursors, tip text, etc.

To see what I ended up with (as well as a super fancy jQuery version that was my starting point), you can play with a demo here.

What is JS1k, you ask? From the source: “the object of this competition is to create a cool JavaScript “application” no larger than 1k. Starting out as a joke, the first version ended with a serious amount of submissions, prizes and quality.”

View my uncompressed JS1k entry


<script type="text/javascript">
	var c = document.getElementsByTagName('canvas')[0];
	var b = document.body;
	var a = c.getContext('2d');
	</script> 
	<script type="text/javascript">
	d=document;
	
	h=d.createElement('h1');
	h.innerHTML='Draw.';
	b.insertBefore(h, c);
	
	// context abbreviation loop
	for($ in a){
		a[$[0]+($[6]||$[2])]=a[$];
	}
	
	// commonly used integers
	x=150;
	y=120;
	
	c.width=c.height=x*2;
	k='background:#';
	z=c.style;
	z.cssText=k+"416012";
	
	// pen color array
	A=['000','0e943a','C0C0C0','C5B358'];
	co = '#'+A[0];
	
	//create color squares
	for(i=0;i<4;i++){
	  sqr(A[i]);
	}
	// not overlapping circle
	oLp = 0;
	// not drawing
	drw = 0;
	
	onmousemove=function(e){
	
		// get mouse/canvas properties
		gTs(e,c)
		
		// mouse intersects circle
		if(dI(eX-oL, eY-oT)){
			
			z.cursor='crosshair';
			oLp = 1;
			// if the mouse is down, leave a mark
			if (drw == 1) {
			with(a){
	                ln(eX-oL, eY-oT); // lineTo
	                strokeStyle = co;
	                sr() // stroke
	            }
            }
		}
		// mouse off circle
		else {
			z.cursor='default';
			oLp = 0;
			drw = 0
		}
	};
    onmouseup=function(){ drw = 0}
    onmousedown=function(e){
    	// if overlapping
		if(oLp) {
			gTs(e,e.target)
			drw = 1;
			with(a){
				ba(); // beginPath
				lineWidth=3;
				mv(eX-oL, eY-oT) // moveTo
			}
        }
	}
	// get target values
	function gTs(e,t){
		eX=e.pageX;
		eY=e.pageY;
		oL=t.offsetLeft;
		oT=t.offsetTop;
	}
	// create square: k='background:#', v=color from array
	function sqr(v){
		n=d.createElement('a');
		n.id=v;
		n.style.cssText=k + v +';cursor:pointer;height:15px;float:left;margin:0 8px 0 0;width:15px';
		n.onclick=function(e){co='#'+e.target.id}
		b.appendChild(n)
	}
	// does intersect: a=pageX, b=pageY, x=circleX/circleY, y=circleRadius
	function dI(a,b) {
	    f = a-x;
	    g = b-x;
	    return f*f+g*g <= y*y
	}
	// create sphere
	with(a){
		g=cR(x,y,0,x,y,200); // createRadialGradient
		g.addColorStop(0,'#f00');
		g.addColorStop(1,'#600');
		ba(); // beginPath
		fillStyle=g;
		ac(x, x, y, 0, Math.PI*2,false); // arc
		ca(); // closePath
		fl() // fill
	}
	</script>