<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Silveira Neto &#187; roda da fortuna</title>
	<atom:link href="http://silveiraneto.net/tag/roda-da-fortuna/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description></description>
	<lastBuildDate>Fri, 09 Mar 2012 04:13:27 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>JavaFX Wheel of Fortune</title>
		<link>http://silveiraneto.net/2008/02/09/javafx-wheel-of-fortune/</link>
		<comments>http://silveiraneto.net/2008/02/09/javafx-wheel-of-fortune/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 00:38:29 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[fortune wheel]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfxbest]]></category>
		<category><![CDATA[roda da fortuna]]></category>
		<category><![CDATA[wheel of fortune]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/2008/02/09/javafx-wheel-of-fortune/</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2008/02/09/javafx-wheel-of-fortune/" title="JavaFX Wheel of Fortune"></a>Disclaimer: from now on I will occasionally post in English too. A first release of an Wheel of Fortune made with JavaFX. There&#8217;s still has a lot of bugs but is already usable. Let&#8217;s say that version is 0.8. :) &#8230;<p class="read-more"><a href="http://silveiraneto.net/2008/02/09/javafx-wheel-of-fortune/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2008/02/09/javafx-wheel-of-fortune/" title="JavaFX Wheel of Fortune"></a><p><small><strong>Disclaimer:</strong> from now on I will occasionally post in English too.</small></p>
<p>A first release of an <em>Wheel of Fortune </em> made with <a href="http://www.sun.com/software/javafx/index.jsp">JavaFX</a>. There&#8217;s still has a lot of bugs but is already usable. Let&#8217;s say that version is 0.8. :)</p>
<p><center><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/_wnk666SRF4&#038;rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/_wnk666SRF4&#038;rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object></center></p>
<p><span id="more-651"></span></p>
<pre name="code" class="java">
import javafx.ui.*;
import javafx.ui.canvas.*;
import javafx.ui.filter.*;

import java.util.Random;
import java.lang.System;

class Wheel extends CompositeNode{
    attribute n: Integer;
    attribute radius: Integer;
    attribute cx: Integer;
    attribute cy: Integer;
    attribute colors: Color*;

    private attribute angle: Number;
    private attribute rotAngle: Number;
    private attribute extraTurns: Integer;

    operation run();
}

attribute Wheel.n = 32;
attribute Wheel.radius = 100;
attribute Wheel.cx = radius;
attribute Wheel.cy = radius;
attribute Wheel.rotAngle = 0;
attribute Wheel.angle = bind 360/n;
attribute Wheel.extraTurns = 2;
attribute Wheel.colors = [
    red:Color,
    lime:Color,
    blue:Color,
    yellow:Color,
    orange:Color,
    cyan:Color
];

function Wheel.composeNode(){
    var selector = Rect {
        x: radius*2 - 10
        y: radius
        width: 30
        height: 10
        fill:black
    };

    var disc = foreach(j in [1..n]) Arc{
        transform: translate(-radius, -radius)
        width: radius * 2
        height: radius * 2
        startAngle: j*angle
        length: angle
        fill:colors[j%(sizeof colors)]
        closure: PIE
    };

    var border = Circle{
        radius:radius
        stroke:gray
        strokeWidth: 2
    };

    var glass = Circle{
        radius:radius - 25
        fill: white
        opacity: 0.3
    };

    var star = Star {
        rin: radius/4
        rout: radius/2
        points: 5

        startAngle: 18
        fill: yellow
    };

    var numbers = foreach(i in [1..n]) Text {
        transform: [rotate(i*angle, 0, 0), translate(radius - 20,0)]
        content: i.toString()
    };

    var base = Group{
        transform: bind [rotate(rotAngle,cx,cy),translate(cx,cy),]
        content: [disc, border, glass, numbers, star]
    };

    return Group {
        content: [selector, base]
    };
}

operation Wheel.run() {
    var fortune = new Random(System.currentTimeMillis());
    var chosen = fortune.nextInt(n);
    System.out.println(chosen);
    rotAngle = [1.. extraTurns*360+ chosen*angle] dur 200 * n;
}

var wheel = Wheel{};

Frame{
    visible: true
    content: Canvas {
        content: [
            wheel,
            View {
                content:Button {
                    text: "Go"
                    action: operation() {
                        wheel.run();
                    }
                }
            }
        ]
    }
}
</pre>
<p>The JavaFX Wheel of Fortune in use:<br />
<center><img src='http://farm4.static.flickr.com/3119/2342580970_cebc832144.jpg' alt='Fortune Wheel'/></center></p>
<ul>
<li><strong>ps:</strong> this code was actualized. Now it&#8217;s using colors constants and time as random seed.</li>
<li><strong>ps2:</strong> this code and video has figured out in the front page of the <a href="https://openjfx.dev.java.net/">Project OpenJFX</a>! Thank you guys.</li>
<li><strong>ps3: </strong> In 03/15/2008 I modified this code. Now you can put an arbitrary number for Wheel.n and the wheel should render good.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/02/09/javafx-wheel-of-fortune/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

