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

Scala Graphics类代码示例

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

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



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

示例1: 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


示例2: 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


示例3: Sierpinski

//设置package包名称以及导入依赖的类
import java.awt.image.BufferedImage
import java.awt.{Color, Graphics}
import scalaview.SwingImageViewer

object Sierpinski {

  def drawSierpinski(g: Graphics, x: Double, y: Double, w: Double, h: Double, l: Int): Unit = {
    if (l == 0)
      g.fillRect(x.round.toInt, y.round.toInt, w.round.toInt, h.round.toInt)
    else {
      drawSierpinski(g, x, y, w / 3, h / 3, l - 1)
      drawSierpinski(g, x + w / 3, y, w / 3, h / 3, l - 1)
      drawSierpinski(g, x + (2 * w) / 3, y, w / 3, h / 3, l - 1)
      drawSierpinski(g, x, y + h / 3, w / 3, h / 3, l - 1)
      drawSierpinski(g, x + (2 * w) / 3, y + h / 3, w / 3, h / 3, l - 1)
      drawSierpinski(g, x, y + (2 * h) / 3, w / 3, h / 3, l - 1)
      drawSierpinski(g, x + w / 3, y + (2 * h) / 3, w / 3, h / 3, l - 1)
      drawSierpinski(g, x + (2 * w) / 3, y + (2 * h) / 3, w / 3, h / 3, l - 1)
    }
  }

  def makeSierpinski(width: Int = 500, height: Int = 500, level: Int = 3): BufferedImage = {
    val canvas = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY)
    val g = canvas.getGraphics
    g.setColor(Color.white)
    g.fillRect(0, 0, width, height)
    g.setColor(Color.black)
    drawSierpinski(g, 0.0, 0.0, width.toDouble, height.toDouble, level)
    canvas
  }

  def main(args: Array[String]): Unit = {
    println("Hi")
    val is = (0 to 6).toStream.map(i => makeSierpinski(729, 729, i))
    SwingImageViewer(is, 2000, autoStart = true)
    println("Bye")
  }

}

// eof 
开发者ID:darrenjw,项目名称:scala-view-examples,代码行数:42,代码来源:sierpinski.scala


示例4: updateBounds

//设置package包名称以及导入依赖的类
package ch.santosalves.neurosimulator.ui

import javax.swing.JComponent
import java.awt.Graphics
import javax.swing.BorderFactory
import java.awt.Color
import java.awt.event.ComponentAdapter
import java.awt.event.ComponentEvent
import org.apache.logging.log4j.LogManager
import javax.swing.JPanel
import java.awt.Graphics2D
import java.util.Observable
import ch.santosalves.neurosimulator.api.ObservableObject
import ch.santosalves.neurosimulator.api.OutputTrigged
import ch.santosalves.neurosimulator.api.NerveCell
import java.util.Observer
import java.awt.BasicStroke


  def updateBounds = {
    val _b = (n1.getX <= n2.getX) match {
      case true => (n1.getY <= n2.getY) match {
        case true  => new BoundingBox(n1.getX, n1.getY, n2.getX, n2.getY, 1)
        case false => new BoundingBox(n1.getX, n2.getY, n2.getX, n1.getY, 4)
      }
      case false => (n1.getY <= n2.getY) match {
        case true  => new BoundingBox(n2.getX, n1.getY, n1.getX, n2.getY, 2)
        case false => new BoundingBox(n2.getX, n2.getY, n1.getX, n1.getY, 3)
      }
    }
    
    bbox = _b.reMap(16, 16)
    setBounds(bbox.minX, bbox.minY, bbox.getWidth, bbox.getHeight)
    //logger.info("[" + name + "](x1,y1)->(x2,y2) => (" + bbox.minX + "," + bbox.minY + ")->(" + bbox.maxX + ", " + bbox.maxY + ")")
  }

  override def paint(g: Graphics) = {
    val c = g.getColor
    g.setXORMode(Color.WHITE)    
    
    g.setColor(wireColor)      
    g.asInstanceOf[Graphics2D].setStroke(new BasicStroke(2))
    bbox.quadrant match {
      case 1 => g.drawLine(0, 0, bbox.getWidth, bbox.getHeight)
      case 3 => g.drawLine(0, 0, bbox.getWidth, bbox.getHeight)
      case 2 => g.drawLine(0, bbox.getHeight, bbox.getWidth, 0)
      case 4 => g.drawLine(0, bbox.getHeight, bbox.getWidth, 0)
    }    
    
    g.setColor(c)
    
    super.paint(g)
    
  }
} 
开发者ID:sergio-alves,项目名称:NeuroSimulator,代码行数:56,代码来源:NeuronLink.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala NeuralNetConfiguration类代码示例发布时间:2022-05-23
下一篇:
Scala app类代码示例发布时间: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