像在JavaFX中一样在Rebol VID中绘制一个明星

时间:2009-08-18 00:34:51

标签: rebol

Rebol VID中这个javaFx星代码的等价物是什么(我猜需要AGG同样的效果)? http://www.javafxgame.com/javafx-wish-tree/

javafx

/*
 * Star.fx
 */

package wishtree;

import java.text.SimpleDateFormat;
import java.util.Date;
import javafx.scene.effect.DropShadow;
import javafx.scene.paint.*;
import javafx.scene.shape.Polygon;
import java.lang.Math.*;

/**
 * @author Henry Zhang   http://www.javafxgame.com
 */

public class Star extends Polygon {

  public var name: String = "your name"; 
  public var wish: String = "I want to ..."; 

  public var time: String = getDateString();
  public var email: String = "" ;   
  public var whichColor : Integer ;

  def r1 : Double = 15;
  def r2 : Double = r1 / 1.6;

  var r = [r1, r2];

  var strokeColor =
    [ Color.PINK, Color.YELLOW, Color.GOLDENROD, Color.CYAN,
      Color.PURPLE, Color.BLUEVIOLET, Color.CORAL, Color.CRIMSON ];
  var fillColor =
    [ Color.GOLD, Color.BLUE, Color.RED, Color.DARKSLATEBLUE,
      Color.DARKORANGE, Color.MAGENTA, Color.BROWN, Color.CHOCOLATE ];

  init {
    // compute the coordinates of the star polygon
    points = for ( i in [0..9] ) [
      r[i mod 2] * cos( toRadians(i*36) ),
      r[i mod 2] * sin( toRadians(i*36) )
    ];

    blocksMouse = true;
    strokeWidth = 1;
    whichColor = random() * sizeof(strokeColor) as Integer;
    effect = DropShadow { color: Color.WHITE };

    changeStatus();
  }

  function getDateString() : String {
    var formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    var date = new Date();
    return formatter.format(date);
  }

  public function changeStatus() {
    stroke = strokeColor[whichColor];

    fill = LinearGradient {
             startX: 0 startY: 0 endX: 0 endY: 1.0
             proportional: true
             stops: [
                     Stop { offset: 0.1 color: Color.WHITE }
                     Stop { offset: 1.0 color: fillColor[whichColor]}
                    ]
           };
  }
}

1 个答案:

答案 0 :(得分:1)

在REBOL / View中绘制类似的星形需要使用Draw方言(它是DSL)记录here。 FILL-PEN和POLYGON绘制命令应该可以很好地完成工作。