• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Graphics2D类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中java.awt.Graphics2D的典型用法代码示例。如果您正苦于以下问题:Scala Graphics2D类的具体用法?Scala Graphics2D怎么用?Scala Graphics2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Graphics2D类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: GraphicMatrix

//设置package包名称以及导入依赖的类
package swayvil.langtonant.gui

import java.awt.{ Graphics2D, BasicStroke }
import java.awt.geom._ // Rectangle2D
import swayvil.langtonant.Matrix
import swayvil.langtonant.Square
import scala.swing.Panel
import java.awt.Color
import java.awt.Dimension

class GraphicMatrix(private var m: Matrix) extends Panel with GUI {
  preferredSize = new Dimension(m.size * squareSize, m.size * squareSize)

  override def paintComponent(g: Graphics2D) {
    m.matrix.foreach { (row: Array[Square]) => row.foreach { (square: Square) => drawSquare(g, square.x, square.y) } }
  }

  override def repaint() {
    super.repaint()
  }

  private def drawSquare(g: Graphics2D, x: Int, y: Int) {
    var rec = new Rectangle2D.Double(squareSize * x, squareSize * y, squareSize, squareSize)
    if (m.matrix(x)(y).isWhite)
      g.setColor(white)
    else
      g.setColor(black)
    if (m.matrix(x)(y).isAnt)
      g.setColor(red)
    g.fill(new Rectangle2D.Double(squareSize * x, squareSize * y, squareSize, squareSize))
    g.setColor(black)
    g.draw(new Rectangle2D.Double(squareSize * x, squareSize * y, squareSize, squareSize))
  }
} 
开发者ID:swayvil,项目名称:langton-ant,代码行数:35,代码来源:GraphicMatrix.scala


示例2: GraphicTurn

//设置package包名称以及导入依赖的类
package swayvil.langtonant.gui

import java.awt.{ Graphics2D }
import main.scala.swayvil.langtonant.Game
import scala.swing.Panel
import java.awt.Dimension

class GraphicTurn(var game: Game) extends Panel with GUI {
  preferredSize = new Dimension(10, 10)

  override def paintComponent(g: Graphics2D) {
    // draw some text
    g.setColor(black)
    g.setFont(font)
    g.drawString(game.turn.toString(), 10, 10)
  }

  override def repaint() {
    super.repaint()
  }
} 
开发者ID:swayvil,项目名称:langton-ant,代码行数:22,代码来源:GraphicTurn.scala


示例3: Bubble

//设置package包名称以及导入依赖的类
package com.alvinalexander.bubbles

import java.awt.Color
import java.awt.Graphics
import java.awt.Graphics2D
import java.awt.image.BufferedImage
import java.awt.GraphicsConfiguration
import java.awt.Transparency

case class Bubble (
    var x: Int, 
    var y: Int, 
    var lastX: Int, 
    var lastY: Int,
    circleDiameter: Int,
    fgColor: Color,
    bgColor: Color,
    char: Char
)
{
  
  private var image: BufferedImage = null
  
  def drawBubbleFast(g: Graphics, gc: GraphicsConfiguration) {
    val g2 = g.asInstanceOf[Graphics2D]
    if (image == null) {
      println("image was null")
      // build the image on the first call
      image = gc.createCompatibleImage(circleDiameter+1, circleDiameter+1, Transparency.BITMASK)
      val gImg = image.getGraphics.asInstanceOf[Graphics2D]
      renderBubble(gImg)
      gImg.dispose
    }
    g2.drawImage(image, x, y, null)
  }
  
  // given a Graphics object, render the bubble
  def renderBubble(g: Graphics) {
    val g2 = g.create.asInstanceOf[Graphics2D]
    // draw the circle
    g2.setColor(bgColor)
    g2.fillOval(0, 0, circleDiameter, circleDiameter)
    // draw the character
    g2.setFont(CIRCLE_FONT)
    g2.setColor(fgColor)
    g2.drawString(char.toString, CIRCLE_FONT_PADDING_X, CIRCLE_FONT_PADDING_Y)
    g2.dispose
  }
  
  
} 
开发者ID:arunhprasadbh,项目名称:AkkaKillTheCharactersGame,代码行数:52,代码来源:Bubble.scala


示例4: Desenho

//设置package包名称以及导入依赖的类
package jerimum

import java.awt.{ Graphics2D, RenderingHints }

import scala.collection.SortedMap

import br.edu.ifrn.potigol.Potigolutil.Inteiro

object Desenho {
  private[this] val vazia = SortedMap[Inteiro, List[Graphics2D => Unit]]()
  private[this] var camadas = vazia
  private[this] def todos = camadas.values.flatten

  private[this] val rh = new RenderingHints(
    RenderingHints.KEY_TEXT_ANTIALIASING,
    RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB)

  def desenhe(g: Graphics2D): Unit = {
    g match {
      case g: Graphics2D =>
        g.setRenderingHints(rh)
    }
    todos.foreach(f => f(g))
    camadas = vazia
  }

  def incluir(z: Inteiro, funcao: Graphics2D => Unit) = {
    camadas += z -> (funcao :: camadas.getOrElse(z, Nil))
  }
} 
开发者ID:potigol,项目名称:Jerimum,代码行数:31,代码来源:Desenho.scala


示例5: PointPanel

//设置package包名称以及导入依赖的类
package com.ganchurin.view

import java.awt.geom.Rectangle2D
import java.awt.{Color, Graphics2D}
import javax.swing.JPanel

class PointPanel(width: Int, height: Int, cellSize: Int, gridSize: Int) extends JPanel {

  def initRectangles(): Unit = {
    val rectangles = for {
      i <- 0 until width by (cellSize + gridSize)
      j <- 0 until height by (cellSize + gridSize)
    } yield new Rectangle2D.Double(i, j, cellSize, cellSize)
    clearRectangles(rectangles)
  }

  def paintRectangles(rectangles: Seq[Rectangle2D.Double]): Unit = {
    fillRectangles(rectangles, Color.BLACK)
  }

  def clearRectangles(rectangles: Seq[Rectangle2D.Double]): Unit = {
    fillRectangles(rectangles, Color.WHITE)
  }

  private def fillRectangles(rectangles: Seq[Rectangle2D.Double], color: Color) {
    val g = getGraphics
    val g2d = g.asInstanceOf[Graphics2D]
    g2d setColor color
    rectangles foreach g2d.fill
  }
} 
开发者ID:ganchurin,项目名称:scalife,代码行数:32,代码来源:PointPanel.scala


示例6: SnowAnimation

//设置package包名称以及导入依赖的类
package gui.animations

import java.awt.Graphics2D
import java.awt.AlphaComposite

import collection.mutable.ListBuffer
import util.Random

import game_mechanics.path.{Waypoint,CellPos}
import gui._



object SnowAnimation
{
    val rng = new Random()
}

class SnowAnimation( pos : CellPos, radius : Double ) extends Animatable
{
    
    import SnowAnimation._
    val size            = MapPanel.cellsize.toDouble
    val origin          = (pos.toDouble + new Waypoint(0.5,0.5)) * size
    val duration        = 7.0
    timer               = duration
    val particle_amount = 30
    val particles       = new ListBuffer[Waypoint]()
    val fall_distance   = 20

    for( i <- 0 until particle_amount )
    {
        // Uniform disk distribution
        val r      = rng.nextDouble
        val theta  = rng.nextDouble * 2 * Math.PI
        val x      = Math.sqrt( r ) * Math.cos( theta ) * radius * size
        val y      = Math.sqrt( r ) * Math.sin( theta ) * radius * size
        particles += new Waypoint( x + origin.x, y + origin.y - fall_distance )
    }

    override def draw(g: Graphics2D): Unit = {
        g.setColor( Colors.white )
        val alpha = (timer / duration).toFloat
        g.setComposite(
            AlphaComposite.getInstance( AlphaComposite.SRC_OVER, alpha ) )
        val movement = (1.0 - timer / duration) * fall_distance
        for( particle <- particles ) {
            g.drawRect( particle.x.toInt, particle.y.toInt + movement.toInt,
                1, 1 )
        }
    }
} 
开发者ID:bunny-defense,项目名称:bunny_defense,代码行数:53,代码来源:snowanimation.scala


示例7: ThunderflashAnimation

//设置package包名称以及导入依赖的类
package gui.animations

import java.awt.Graphics2D
import java.awt.AlphaComposite

import runtime.TowerDefense
import gui._



class ThunderflashAnimation extends Animatable
{
    val duration = 0.5
    timer = duration

    override def draw(g : Graphics2D): Unit = {
        g.setColor( Colors.white )
        val alpha = Math.pow( timer / duration, 4 ).toFloat
        g.setComposite(
            AlphaComposite.getInstance( AlphaComposite.SRC_OVER, alpha ) )
        g.fillRect( 0, 0,
            TowerDefense.map_panel.map.width  * MapPanel.cellsize,
            TowerDefense.map_panel.map.height * MapPanel.cellsize )
    }
} 
开发者ID:bunny-defense,项目名称:bunny_defense,代码行数:26,代码来源:thunderflashanimation.scala


示例8: MuzzleflashAnimation

//设置package包名称以及导入依赖的类
package gui.animations

import java.awt.Graphics2D

import game_mechanics.path.Waypoint
import gui._


class MuzzleflashAnimation(origin : Waypoint) extends Animatable
{
    val duration = 0.1
    timer        = duration
    val cellsize = MapPanel.cellsize
    val size     = cellsize / 2
    val pos      = origin * cellsize

    override def draw(g: Graphics2D): Unit = {
        g.setColor( Colors.white )
        g.fillOval(
            pos.x.toInt + cellsize / 2 - size / 2,
            pos.y.toInt + cellsize / 2 - size / 2,
            size, size )
    }
} 
开发者ID:bunny-defense,项目名称:bunny_defense,代码行数:25,代码来源:muzzleflashanimation.scala


示例9: DamageAnimation

//设置package包名称以及导入依赖的类
package gui.animations

import java.awt.AlphaComposite
import java.awt.Graphics2D

import game_mechanics.path.Waypoint
import gui._
import runtime.{TowerDefense,Controller}
import utils.Continuable

class DamageAnimation(amount: Double, origin: Waypoint) extends Animatable
{
    var pos    = origin
    val target = origin + new Waypoint(0,-1)

    override def draw(g: Graphics2D): Unit = {
    
        pos = origin * timer + target * (1 - timer)
        g.setColor( Colors.red )
        g.drawString( amount.toString + " dmg",
            pos.x.toFloat * MapPanel.cellsize,
            pos.y.toFloat * MapPanel.cellsize )
    }
} 
开发者ID:bunny-defense,项目名称:bunny_defense,代码行数:25,代码来源:damageanimation.scala


示例10: SmokeAnimation

//设置package包名称以及导入依赖的类
package gui.animations

import collection.mutable.ListBuffer
import util.Random

import java.awt.Graphics2D

import game_mechanics.path.Waypoint
import gui._

class SmokeAnimation(origin: Waypoint) extends Animatable
{
    

    val duration = 2.0
    val rng      = new Random
    timer        = duration

    val particles = new ListBuffer[Waypoint]

    for( i <- 0 until 30 )
    {
        val theta = rng.nextDouble * 2 * Math.PI
        particles += new Waypoint( Math.cos( theta ), Math.sin( theta ) )
    }

    override def draw(g: Graphics2D) : Unit = {
        val interp = 1 - timer / duration
        g.setColor( Colors.lightGrey )
        for( particle <- particles )
        {
            val pos = (origin + particle * interp * 1.5) * MapPanel.cellsize
            g.fillOval(
                pos.x.toInt, pos.y.toInt,
                (MapPanel.cellsize * (1-interp)).toInt,
                (MapPanel.cellsize * (1-interp)).toInt )
        }
    }
} 
开发者ID:bunny-defense,项目名称:bunny_defense,代码行数:40,代码来源:smokeanimation.scala


示例11: BuffAnimation

//设置package包名称以及导入依赖的类
package gui.animations

import java.awt.Graphics2D
import java.awt.AlphaComposite

import collection.mutable.ListBuffer
import gui._
import util.Random

import game_mechanics.path.{Waypoint,CellPos}



object BuffAnimation
{
    val rng = new Random()
}

class BuffAnimation( pos : CellPos, radius : Double ) extends Animatable
{
    import BuffAnimation._
    val size            = MapPanel.cellsize.toDouble
    val origin          = (pos.toDouble + new Waypoint(0.5,0.5)) * size
    val duration        = 7.0
    timer               = duration
    val particle_amount = 30
    val particles       = new ListBuffer[Waypoint]()
    val fall_distance   = 20

    for( i <- 0 until particle_amount )
    {
        // Uniform disk distribution
        val r      = rng.nextDouble
        val theta  = rng.nextDouble * 2 * Math.PI
        val x      = Math.sqrt( r ) * Math.cos( theta ) * radius * size
        val y      = Math.sqrt( r ) * Math.sin( theta ) * radius * size
        particles += new Waypoint( x + origin.x, y + origin.y - fall_distance )
    }

    override def draw(g: Graphics2D): Unit = {
        g.setColor( Colors.blue )
        val alpha = (timer / duration).toFloat
        g.setComposite(
            AlphaComposite.getInstance( AlphaComposite.SRC_OVER, alpha ) )
        val movement = timer / duration * fall_distance
        for( particle <- particles ) {
            g.drawString( "+",
                particle.x.toInt, particle.y.toInt + movement.toInt )
        }
    }
} 
开发者ID:bunny-defense,项目名称:bunny_defense,代码行数:52,代码来源:buffanimation.scala


示例12: RaygunShootAnimation

//设置package包名称以及导入依赖的类
package gui.animations

import collection.mutable.ListBuffer
import util.Random

import java.awt.Graphics2D
import java.awt.AlphaComposite

import runtime.TowerDefense
import gui._
import game_mechanics.path.{Waypoint,CellPos}



object RaygunShootAnimation
{
    val rng            = new Random
    val duration       = 10.0
}

class RaygunShootAnimation(tower_pos: CellPos, direction : Waypoint) extends Animatable
{
    import RaygunShootAnimation._
    val origin         = tower_pos.toDouble
    timer = duration
    val size           = MapPanel.cellsize.toDouble
    val laser_length   = (TowerDefense.map_panel.map.width * size).toInt

    override def draw(g: Graphics2D): Unit = {
        val prev_transform = g.getTransform()
        g.rotate( Math.atan2( direction.y, direction.x ), tower_pos.x, tower_pos.y )
        val alpha = Math.min( timer, 1.0 ).toFloat
        g.setComposite(
            AlphaComposite.getInstance( AlphaComposite.SRC_OVER, alpha ) )
        g.setColor( Colors.white )
        g.fillRect(
            tower_pos.x * MapPanel.cellsize + MapPanel.cellsize / 2,
            tower_pos.y * MapPanel.cellsize - MapPanel.cellsize / 2,
            laser_length,
            MapPanel.cellsize * 2 )
        g.setColor( Colors.lightblue )
        g.fillRect(
            tower_pos.x * MapPanel.cellsize + MapPanel.cellsize / 2,
            tower_pos.y * MapPanel.cellsize,
            laser_length,
            MapPanel.cellsize )
        TowerDefense.map_panel.darkness = (alpha * RaygunAnimation.max_darkness).toFloat
        g.setTransform( prev_transform )
    }
} 
开发者ID:bunny-defense,项目名称:bunny_defense,代码行数:51,代码来源:raygunshootanimation.scala


示例13: GoldAnimation

//设置package包名称以及导入依赖的类
package gui.animations

import java.awt.AlphaComposite
import java.awt.Graphics2D

import game_mechanics.path.Waypoint
import gui._
import utils.Continuable



class GoldAnimation(amount: Int,origin: Waypoint) extends Animatable
{
    
    timer = 2.0
    var pos    = origin
    val target = origin + new Waypoint(0,-1)

    override def draw(g: Graphics2D): Unit = {
        pos = origin * timer + target * (1 - timer)
        val string = "+" + amount.toString + " Gold"
        val alpha  = if(timer < 1.0) { Math.max(0,timer).toFloat } else { 1.0f }
        g.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, alpha ) )
        g.setColor( Colors.black )
        g.drawString( string,
            pos.x.toFloat * MapPanel.cellsize + 1,
            pos.y.toFloat * MapPanel.cellsize + 1 )
        g.setColor( Colors.yellow )
        g.drawString( string,
            pos.x.toFloat * MapPanel.cellsize,
            pos.y.toFloat * MapPanel.cellsize )
    }
} 
开发者ID:bunny-defense,项目名称:bunny_defense,代码行数:34,代码来源:goldanimation.scala


示例14: TransparentTest

//设置package包名称以及导入依赖的类
package de.sciss.schwaermen

import java.awt.{BasicStroke, Color, Graphics, Graphics2D}

import scala.swing.Swing

object TransparentTest {
  def main(args: Array[String]): Unit = {
    Swing.onEDT(run())
  }

  def run(): Unit = {
    val frame = new javax.swing.JFrame("Test")
    frame.setUndecorated(true)
    frame.setBackground (new Color(0,0,0,0))
    frame.setContentPane(new TestComponent())
    frame.pack()
    frame.setSize(500, 500)
    frame.setLocationRelativeTo(null)
    frame.setVisible(true)
  }

  final class TestComponent extends javax.swing.JComponent {
    override def paintComponent(g: Graphics): Unit = {
      super.paintComponent(g)
      g.setColor(Color.red)
      val g2 = g.asInstanceOf[Graphics2D]
      g2.setStroke(new BasicStroke(3f))
      g.drawLine(0, 0, getWidth, getHeight)
      g.drawLine(0, getHeight, getWidth, 0)
    }
  }
} 
开发者ID:Sciss,项目名称:Schwaermen,代码行数:34,代码来源:TransparentTest.scala


示例15: timeTo

//设置package包名称以及导入依赖的类
package things

import java.awt.{BasicStroke, Color, Graphics2D}

trait Wall extends Thing {
  val p: Double
  val dir: Int

  def timeTo(mov: Movable) = {
    val v = mov.vel(dir)
    val dist = if (p < 0) p - mov.pos(dir) + mov.r else p - mov.pos(dir) - mov.r
    val timeToHit = if (v == 0) Double.PositiveInfinity else dist / v
    if (timeToHit <= 0) Double.PositiveInfinity else timeToHit
  }
}

case class VWall(p: Double) extends Wall {
  val id = Int.MaxValue
  val dir = 0

  def draw(g: Graphics2D) {
    g.setColor(new Color(255, 0, 255))
    g.setStroke(new BasicStroke(3f))
    line(g)(p, -3000, p, 3000)
  }
}

case class HWall(p: Double) extends Wall {
  val id = Int.MaxValue
  val dir = 1

  def draw(g:Graphics2D) {
    g.setColor(new Color(255, 0, 255))
    g.setStroke(new BasicStroke(3f))
    line(g)(-3000, p, 3000, p)
  }
} 
开发者ID:davips,项目名称:mucel-scala,代码行数:38,代码来源:Wall.scala


示例16: line

//设置package包名称以及导入依赖的类
package view

import java.awt.Graphics2D
import java.awt.geom.{Ellipse2D, Line2D}

import data.Cfg

trait Paint {
  val (sizex, sizey) = Cfg.frameWidth -> Cfg.frameHeight

  def line(g: Graphics2D)(x1: Double, y1: Double, x2: Double, y2: Double) = {
    line2(g)(lineObj(x1, y1, x2, y2))
  }

  def line2(g: Graphics2D)(l: Line2D) {
    g.draw(l)
  }

  def lineObj(x1: Double, y1: Double, x2: Double, y2: Double) = new Line2D.Double(x1 + sizex / 2, y1 + sizey / 2, x2 + sizex / 2, y2 + sizey / 2)

  def ball(g: Graphics2D)(x: Double, y: Double, r: Double) {
    g.fill(new Ellipse2D.Double(x + sizex / 2 - r, y + sizey / 2 - r, 2 * r, 2 * r))
  }

  def bubble(g: Graphics2D)(x: Double, y: Double, r: Double) {
    g.draw(new Ellipse2D.Double(x + sizex / 2 - r, y + sizey / 2 - r, 2 * r, 2 * r))
  }
} 
开发者ID:davips,项目名称:mucel-scala,代码行数:29,代码来源:Paint.scala


示例17: Rectangle

//设置package包名称以及导入依赖的类
package SPL_Analysed_Examples.ArcadeGameMakerSPL.gamedefinitions

import java.awt.Color
import java.awt.geom.Rectangle2D
import java.awt.geom.Ellipse2D
import java.awt.Graphics2D

sealed trait Shape
case object Rectangle extends Shape
case object Ellipse extends Shape

case class Dimensions(var x: Int, var y: Int, var w: Int, var h: Int)

abstract class Sprite(val dim: Dimensions, val shape: Shape, val isMovable: Boolean = false) {

  def draw(g: Graphics2D, color: Color): Unit = {
    g setColor color
    shape match {
      case Rectangle => g fillRect (dim.x, dim.y, dim.w, dim.h)
      case Ellipse => g fillOval (dim.x, dim.y, dim.w, dim.h)
    }
  }

  def getCollisionBox: Rectangle2D = new Rectangle2D.Double(dim.x, dim.y, dim.w, dim.h)
  def getCollisionOval: Ellipse2D = new Ellipse2D.Double(dim.x, dim.y, dim.w, dim.h)

  def isOverlapping(other: Sprite): Boolean = {
    val oBox = other.shape match {
      case Rectangle => other.getCollisionBox
      case Ellipse => other.getCollisionOval
    }
    val tBox = this.shape match {
      case Rectangle => this.getCollisionBox
      case Ellipse => this.getCollisionOval
    }

    if (tBox.getX > oBox.getX + oBox.getWidth) false
    else if (tBox.getX + tBox.getWidth < oBox.getX) false
    else if (tBox.getY > oBox.getY + oBox.getHeight) false
    else if (tBox.getY + tBox.getHeight < oBox.getY) false
    else true
  }
  
  def disappearSprite(sprite: Sprite) {
    sprite.dim.x = 0
    sprite.dim.y = 0
    sprite.dim.w= 0
    sprite.dim.h = 0
  }
  
} 
开发者ID:ternava,项目名称:Variability-CChecking,代码行数:52,代码来源:Sprite.scala


示例18: CheckerBackground

//设置package包名称以及导入依赖的类
package de.sciss.unlike

import java.awt.image.BufferedImage
import java.awt.{Dimension, Graphics2D, Paint, Rectangle, TexturePaint}

import scala.swing.Component

class CheckerBackground(sizeH: Int = 32)
  extends Component
  with Zoomable {

  private[this] val pntBg: Paint = {
    val img = new BufferedImage(sizeH << 1, sizeH << 1, BufferedImage.TYPE_INT_ARGB)

    for (x <- 0 until img.getWidth) {
      for (y <- 0 until img.getHeight) {
        img.setRGB(x, y, if (((x / sizeH) ^ (y / sizeH)) == 0) 0xFF9F9F9F else 0xFF7F7F7F)
      }
    }

    new TexturePaint(img, new Rectangle(0, 0, img.getWidth, img.getHeight))
  }

  opaque = false

  def screenSizeUpdated(d: Dimension): Unit = {
    preferredSize = d
    peer.setSize(d)
    revalidate()
  }

  override protected def paintComponent(g2: Graphics2D): Unit = {
    val atOrig  = g2.getTransform
    g2.scale(_zoom, _zoom)
    g2.translate(-clipLeftPx, -clipTopPx)
    g2.setPaint(pntBg)
    g2.fillRect(0, 0, virtualRect.width, virtualRect.height)
    g2.setTransform(atOrig)
  }
} 
开发者ID:Sciss,项目名称:Unlike,代码行数:41,代码来源:CheckerBackground.scala


示例19: Point

//设置package包名称以及导入依赖的类
// val data = "0.441884,-0.545419,14.0524 0.485816,-0.653404,64.0524 0.608093,-0.761465,114.052 0.722919,-0.869561,164.052 0.821384,-0.977654,214.052 0.88199,-1.08574,264.052 0.854082,-1.19381,314.052 0.675696,-1.30187,364.052 0.335115,-1.4099,414.052 -0.130356,-1.51792,464.052 -0.66671,-1.62592,514.052 -1.23466,-1.73391,564.052 -1.81571,-1.8419,614.052 -2.40243,-1.9499,664.052 -2.99186,-2.05789,714.052 -3.58266,-2.16588,764.052 -4.17421,-2.27387,814.052 -4.76604,-2.38186,864.052 -5.35792,-2.48985,914.052 -5.94976,-2.59784,964.052 -6.54159,-2.70583,1014.05 -7.13343,-2.81383,1064.05 -7.72527,-2.92182,1114.05 -8.3171,-3.02981,1164.05 -8.90894,-3.1378,1214.05 -9.50078,-3.24579,1264.05 -10.0926,-3.35378,1314.05 -10.6845,-3.46177,1364.05 -11.2763,-3.56976,1414.05 -11.8681,-3.67776,1464.05 -12.4603,-3.78575,1514.05 -13.0536,-3.89375,1564.05 -13.6583,-4.00181,1614.05 -14.354,-4.11007,1664.05 -15.3592,-4.21858,1714.05 -16.8558,-4.32719,1764.05 -18.8909,-4.43582,1814.05 -21.4677,-4.54441,1864.05 -24.5613,-4.65256,1914.05 -28.0342,-4.75918,1964.05 -31.6499,-4.86453,2014.05 -35.2871,-4.96969,2064.05 -38.9265,-5.07486,2114.05 -42.5662,-5.18003,2164.05 -46.206,-5.2852,2214.05 -49.8457,-5.39037,2264.05 -53.4855,-5.49554,2314.05 -57.1252,-5.60071,2364.05 -60.765,-5.70588,2414.05 -64.4047,-5.81105,2464.05 -68.0445,-5.91622,2514.05 -71.6842,-6.02139,2564.05 -75.324,-6.12656,2614.05 -78.9638,-6.23173,2664.05 -82.6035,-6.3369,2714.05 -86.2433,-6.44207,2764.05 -89.883,-6.54725,2814.05 -93.5228,-6.65242,2864.05 -97.1625,-6.75759,2914.05 -100.802,-6.86276,2964.05 -104.442,-6.96793,3014.05 -108.082,-7.0731,3064.05 -111.722,-7.17827,3114.05 -115.361,-7.28344,3164.05 -119.001,-7.38861,3214.05 -122.641,-7.49378,3264.05 -126.281,-7.59895,3314.05 -129.92,-7.70412,3364.05 -133.56,-7.80929,3414.05 -137.2,-7.91446,3464.05 -140.84,-8.01963,3514.05 -144.479,-8.1248,3564.05 -148.119,-8.22997,3614.05 -151.759,-8.33514,3664.05 -155.399,-8.44032,3714.05 -159.038,-8.54549,3764.05 -162.678,-8.65066,3814.05 -166.318,-8.75583,3864.05 -169.958,-8.861,3914.05 -173.597,-8.96617,3964.05 -177.237,-9.07134,4014.05 -180.877,-9.17651,4064.05 -184.517,-9.28168,4114.05 -188.156,-9.38685,4164.05 -191.796,-9.49202,4214.05 -195.436,-9.59719,4264.05 -199.076,-9.70236,4314.05 -202.715,-9.80753,4364.05 -206.355,-9.9127,4414.05 -209.995,-10.0179,4464.05 -213.635,-10.123,4514.05 -217.274,-10.2282,4564.05 -220.914,-10.3334,4614.05 -224.554,-10.4386,4664.05 -228.194,-10.5437,4714.05 -231.833,-10.6489,4764.05 -235.473,-10.7541,4814.05 -239.113,-10.8592,4864.05 -242.753,-10.9644,4914.05 -246.392,-11.0696,4964.05"
val data = "1.35435,1.31681,-22.3183 1.4126,1.322,27.6817 1.45113,1.32718,77.6817 1.4834,1.33236,127.682 1.51727,1.33754,177.682 1.55395,1.34273,227.682 1.59753,1.34791,277.682 1.65634,1.35309,327.682 1.73769,1.35828,377.682 1.84107,1.36348,427.682 1.96012,1.36868,477.682 2.08733,1.37388,527.682 2.21805,1.37908,577.682 2.35023,1.38428,627.682 2.48306,1.38948,677.682 2.61621,1.39468,727.682 2.74952,1.39989,777.682 2.88292,1.40509,827.682 3.01635,1.41029,877.682 3.14978,1.41549,927.682 3.2832,1.42069,977.682 3.41663,1.4259,1027.68 3.55005,1.4311,1077.68 3.68348,1.4363,1127.68 3.8169,1.4415,1177.68 3.95033,1.4467,1227.68 4.08375,1.4519,1277.68 4.21718,1.45711,1327.68 4.3506,1.46231,1377.68 4.48403,1.46751,1427.68 4.61745,1.47271,1477.68 4.75095,1.47791,1527.68 4.88472,1.48312,1577.68 5.02159,1.48832,1627.68 5.1783,1.49352,1677.68 5.38758,1.49873,1727.68 5.66913,1.50394,1777.68 6.02685,1.50914,1827.68 6.4604,1.51435,1877.68 6.96332,1.51955,1927.68 7.51024,1.52473,1977.68 8.07034,1.52991,2027.68 8.63214,1.53509,2077.68 9.19411,1.54027,2127.68 9.75613,1.54545,2177.68 10.3181,1.55062,2227.68 10.8801,1.5558,2277.68 11.4421,1.56098,2327.68 12.0041,1.56616,2377.68 12.566,1.57134,2427.68 13.128,1.57652,2477.68 13.69,1.58169,2527.68 14.252,1.58687,2577.68 14.814,1.59205,2627.68 15.376,1.59723,2677.68 15.938,1.60241,2727.68 16.4999,1.60758,2777.68 17.0619,1.61276,2827.68 17.6239,1.61794,2877.68 18.1859,1.62312,2927.68 18.7479,1.6283,2977.68 19.3099,1.63348,3027.68 19.8719,1.63865,3077.68 20.4339,1.64383,3127.68 20.9958,1.64901,3177.68 21.5578,1.65419,3227.68 22.1198,1.65937,3277.68 22.6818,1.66455,3327.68 23.2438,1.66972,3377.68 23.8058,1.6749,3427.68 24.3678,1.68008,3477.68 24.9298,1.68526,3527.68 25.4917,1.69044,3577.68 26.0537,1.69561,3627.68 26.6157,1.70079,3677.68 27.1777,1.70597,3727.68 27.7397,1.71115,3777.68 28.3017,1.71633,3827.68 28.8637,1.72151,3877.68 29.4256,1.72668,3927.68 29.9876,1.73186,3977.68 30.5496,1.73704,4027.68 31.1116,1.74222,4077.68 31.6736,1.7474,4127.68 32.2356,1.75258,4177.68 32.7976,1.75775,4227.68 33.3596,1.76293,4277.68 33.9215,1.76811,4327.68 34.4835,1.77329,4377.68 35.0455,1.77847,4427.68 35.6075,1.78365,4477.68 36.1695,1.78882,4527.68 36.7315,1.794,4577.68 37.2935,1.79918,4627.68 37.8554,1.80436,4677.68 38.4174,1.80954,4727.68 38.9794,1.81471,4777.68 39.5414,1.81989,4827.68 40.1034,1.82507,4877.68 40.6654,1.83025,4927.68 41.2274,1.83543,4977.68"

case class Point(x: Double, y: Double, z: Double)

val pts = data.split(" ").map { x =>
  val Seq(xs, ys, zs) = x.split(",").map(_.trim).toSeq
  Point(xs.toDouble, ys.toDouble, zs.toDouble)
}

pts.size

import java.awt.geom._

val p = new Path2D.Double
p.reset()
pts.zipWithIndex.foreach { case (Point(x, y, _), i) =>
  if (i == 0) p.moveTo(x, y) else p.lineTo(x, y)
}
p.getBounds

import java.awt.{Color, Graphics2D}

val at = new AffineTransform
val c = new scala.swing.Component {
  opaque = true
  
  override def paint(g: Graphics2D): Unit = {
    g.setColor(Color.white)
    g.fillRect(0, 0, peer.getWidth, peer.getHeight)
    val shp = at.createTransformedShape(p)
    g.setColor(Color.black)
    g.draw(shp)
  }
}

val f = new scala.swing.Frame {
  contents = new scala.swing.BorderPanel {
    add(c, scala.swing.BorderPanel.Position.Center)
  }
  size = new java.awt.Dimension(400, 400)
  centerOnScreen()
  open()
}

p.getBounds
at.setToTranslation(320, 280)
at.scale(1.2, 24.0)
c.repaint()

at.setToScale(8.0, 600.0)
at.translate(0, -1.3)
// at.createTransformedShape(p).getBounds
c.repaint() 
开发者ID:Sciss,项目名称:ImperfectReconstruction,代码行数:55,代码来源:polyline.scala



注:本文中的java.awt.Graphics2D类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Assertion类代码示例发布时间:2022-05-23
下一篇:
Scala MediaTypes类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap