<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: circle code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 08 Sep 2008 07:56:48 GMT</pubDate>
    <description>DZone Snippets: circle code</description>
    <item>
      <title>Create and drag circles in SVG</title>
      <link>http://snippets.dzone.com/posts/show/5268</link>
      <description>Demonstrates creating creating and dragging circles using SVG and ECMAScript.&lt;br /&gt;&lt;br /&gt;Tested on Firefox 3 beta 4.&lt;br /&gt;&lt;br /&gt;file: makeDragDrop.svg&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;svg	xmlns="http://www.w3.org/2000/svg" width="100%"&lt;br /&gt;		xmlns:xlink="http://www.w3.org/1999/xlink" &gt;&lt;br /&gt;&lt;script&gt;&lt;![CDATA[&lt;br /&gt;var	xmlns="http://www.w3.org/2000/svg"&lt;br /&gt;	xlink="http://www.w3.org/1999/xlink" &lt;br /&gt;	Root=document.documentElement&lt;br /&gt;standardize(Root)&lt;br /&gt;&lt;br /&gt;function standardize(R){&lt;br /&gt;	var Attr={&lt;br /&gt;		"onmouseup":"add(evt)",&lt;br /&gt;		"onmousedown":"grab(evt)",&lt;br /&gt;		"onmousemove":null,&lt;br /&gt;		"onmouseover":"hilight(evt)",&lt;br /&gt;		"onmouseout":"hilight(evt)"&lt;br /&gt;	}&lt;br /&gt;	assignAttr(R,Attr)&lt;br /&gt;}&lt;br /&gt;function hilight(evt){&lt;br /&gt;	var T=evt.target&lt;br /&gt;	if (T.nodeName=="rect") return&lt;br /&gt;	if (evt.type=="mouseover") T.setAttributeNS(null,"stroke-opacity",1)&lt;br /&gt;	else T.setAttributeNS(null,"stroke-opacity",.5)&lt;br /&gt;}&lt;br /&gt;function add(evt){&lt;br /&gt;	if (evt.target.nodeName!="rect") return&lt;br /&gt;	var C=document.createElementNS(xmlns,"circle") &lt;br /&gt;	var stroke=Color()&lt;br /&gt;	var rad=10+Math.random()*50&lt;br /&gt;	var Attr={&lt;br /&gt;		r:rad,&lt;br /&gt;		cx:evt.clientX,&lt;br /&gt;		cy:evt.clientY,&lt;br /&gt;		"fill": Color(),&lt;br /&gt;		"fill-opacity":.75,&lt;br /&gt;		"stroke": stroke,&lt;br /&gt;		"stroke-opacity":.5,&lt;br /&gt;		"id":stroke,&lt;br /&gt;		"stroke-width":10+Math.random()*(55-rad)&lt;br /&gt;	}&lt;br /&gt;	assignAttr(C,Attr)&lt;br /&gt;	Root.appendChild(C)&lt;br /&gt;}&lt;br /&gt;function grab(evt){&lt;br /&gt;	var O=evt.target&lt;br /&gt;	if (evt.target.nodeName=="rect") return&lt;br /&gt;	var Attr={&lt;br /&gt;		"onmousemove":"slide(evt,'"+O.id+"')",&lt;br /&gt;		"onmouseup":"standardize(Root)"&lt;br /&gt;	}&lt;br /&gt;	assignAttr(Root,Attr)&lt;br /&gt;}&lt;br /&gt;function slide(evt,id){&lt;br /&gt;	var o=document.getElementById(id)&lt;br /&gt;	var c=""; if (o.nodeName=="circle") c="c"&lt;br /&gt;	o.setAttributeNS(null, c+"x", evt.clientX)&lt;br /&gt;	o.setAttributeNS(null, c+"y", evt.clientY)&lt;br /&gt;}&lt;br /&gt;function assignAttr(O,A){&lt;br /&gt;	for (i in A) O.setAttributeNS(null,i, A[i])&lt;br /&gt;}&lt;br /&gt;function Color(){&lt;br /&gt;	return "rgb("+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+")"&lt;br /&gt;}&lt;br /&gt;]]&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;rect width="100%" height="100%" fill="white"/&gt;&lt;br /&gt;&lt;text font-size="12pt" x="50" y="20" id="t1"&gt;Click something to move it&lt;/text&gt;&lt;br /&gt;&lt;text font-size="12pt" x="80" y="40" id="t2"&gt;Click nothing to add something&lt;/text&gt;&lt;br /&gt;&lt;/svg&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Source file copied from &lt;a href="http://srufaculty.sru.edu/david.dailey/svg/makeDragDrop.svg"&gt;http://srufaculty.sru.edu/david.dailey/svg/makeDragDrop.svg&lt;/a&gt;&lt;br /&gt;</description>
      <pubDate>Sat, 22 Mar 2008 00:30:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5268</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Circulos en Allegro</title>
      <link>http://snippets.dzone.com/posts/show/2656</link>
      <description>Un codigo para dibujar un circulo en allegro con degradado&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &lt;allegro.h&gt;&lt;br /&gt;&lt;br /&gt;void init();&lt;br /&gt;void deinit();&lt;br /&gt;&lt;br /&gt;int main() {&lt;br /&gt;	int cont;&lt;br /&gt;    &lt;br /&gt;    init();&lt;br /&gt;	&lt;br /&gt;	&lt;br /&gt;	for (cont=0;cont&lt;255;cont++){&lt;br /&gt;        circlefill(screen,320,240,255-cont,makecol(cont,0,0));&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;	while (!key[KEY_ESC]) {&lt;br /&gt;		/* put your code here */&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	deinit();&lt;br /&gt;	return 0;&lt;br /&gt;}&lt;br /&gt;END_OF_MAIN();&lt;br /&gt;&lt;br /&gt;void init() {&lt;br /&gt;	int depth, res;&lt;br /&gt;	allegro_init();&lt;br /&gt;	depth = desktop_color_depth();&lt;br /&gt;	if (depth == 0) depth = 32;&lt;br /&gt;	set_color_depth(depth);&lt;br /&gt;	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);&lt;br /&gt;	if (res != 0) {&lt;br /&gt;		allegro_message(allegro_error);&lt;br /&gt;		exit(-1);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	install_timer();&lt;br /&gt;	install_keyboard();&lt;br /&gt;	install_mouse();&lt;br /&gt;	/* add other initializations here */&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void deinit() {&lt;br /&gt;	clear_keybuf();&lt;br /&gt;	/* add other deinitializations here */&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 22 Sep 2006 20:06:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2656</guid>
      <author>jcongote (John Edgar Congote Calle)</author>
    </item>
    <item>
      <title>Closest Circle Point //JavaScript Function</title>
      <link>http://snippets.dzone.com/posts/show/669</link>
      <description>&lt;a href="http://jsfromhell.com/math/closest-circle-point"&gt;&lt;br /&gt;Given a dot and a circle, it returns the nearest dot over the circle.&lt;br /&gt;&lt;br /&gt;[UPDATED CODE AND HELP CAN BE FOUND HERE]&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com/math/closest-circle-point [v1.0]&lt;br /&gt;&lt;br /&gt;closestCirclePoint = function( px, py, x, y, ray ){&lt;br /&gt;	var tg = ( x += ray, y += ray, 0 );&lt;br /&gt;	return function( x, y, x0, y0 ){ return Math.sqrt( ( x -= x0 ) * x + ( y -= y0 ) * y );	}( px, py, x, y ) &gt; ray ?&lt;br /&gt;		{ x: Math.cos( tg = Math.atan2( py - y, px - x ) ) * ray + x, y: Math.sin( tg ) * ray + y }&lt;br /&gt;		//{ x: ( px - x ) / ( length / ray ) + x, y: ( py - y ) / ( length / ray ) + y }&lt;br /&gt;		: { x: px, y: py };&lt;br /&gt;};&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 09 Sep 2005 04:36:55 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/669</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
    <item>
      <title>drawing circle function</title>
      <link>http://snippets.dzone.com/posts/show/410</link>
      <description>Just to make drawing a circle easier.&lt;br /&gt;Here is a function that will draw yellow circle with black outline.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# from appuifw import *&lt;br /&gt;# c = Canvas()&lt;br /&gt;# app.body = c&lt;br /&gt;&lt;br /&gt;def circle(x,y,radius=5, outline=0, fill=0xffff00, width=1):&lt;br /&gt;  c.ellipse((x-radius, y-radius, x+radius, y+radius), outline, fill, width)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;You may use other default values.&lt;br /&gt;&lt;br /&gt;Then I create a function to show circles randomly&lt;br /&gt;&lt;code&gt;import e32&lt;br /&gt;from random import randint, choice&lt;br /&gt;&lt;br /&gt;sleep = e32.ao_sleep&lt;br /&gt;colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xffffff]&lt;br /&gt;&lt;br /&gt;def rand_circle(n):&lt;br /&gt;  c.clear()&lt;br /&gt;  for i in range(n):&lt;br /&gt;    circle(randint(0,176), randint(0,144), randint(5,20), fill=choice(colors))&lt;br /&gt;    sleep(0.1)&lt;br /&gt;&lt;br /&gt;# now show it&lt;br /&gt;rand_circle(30)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 22 Jun 2005 17:56:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/410</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
