当前位置: 首页>>代码示例>>Scala>>正文


Scala Graphics2D类代码示例

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


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


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