Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6243807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:12:35+00:00 2026-05-24T12:12:35+00:00

What do you recommend for writing a 2D array of pixels to the screen?

  • 0

What do you recommend for writing a 2D array of pixels to the screen?

My first thought is some SWT binding, but are there any others? Processing perhaps?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:12:36+00:00Added an answer on May 24, 2026 at 12:12 pm

    It’s not too hard in Swing – you can cut and paste the below. You could simplify it a bit if you don’t want colours or the ability to draw to any size window, or if it’s always the same size.

    Define a Panel class:

    class DataPanel(data: Array[Array[Color]]) extends Panel {
    
      override def paintComponent(g: Graphics2D) {
        val dx = g.getClipBounds.width.toFloat  / data.length
        val dy = g.getClipBounds.height.toFloat / data.map(_.length).max
        for {
          x <- 0 until data.length
          y <- 0 until data(x).length
          x1 = (x * dx).toInt
          y1 = (y * dy).toInt
          x2 = ((x + 1) * dx).toInt
          y2 = ((y + 1) * dy).toInt
        } {
          data(x)(y) match {
            case c: Color => g.setColor(c)
            case _ => g.setColor(Color.WHITE)
          }
          g.fillRect(x1, y1, x2 - x1, y2 - y1)
        }
      }
    }
    

    Then make a Swing app:

    import swing.{Panel, MainFrame, SimpleSwingApplication}
    import java.awt.{Color, Graphics2D, Dimension}
    
    object Draw extends SimpleSwingApplication {
    
      val data = // put data here
    
      def top = new MainFrame {
        contents = new DataPanel(data) {
          preferredSize = new Dimension(300, 300)
        }
      }
    }
    

    Your data could be something like

      val data = Array.ofDim[Color](25, 25)
    
      // plot some points
      data(0)(0) = Color.BLACK
      data(4)(4) = Color.RED
      data(0)(4) = Color.GREEN
      data(4)(0) = Color.BLUE
    
      // draw a circle 
      import math._
      {
        for {
          t <- Range.Double(0, 2 * Pi, Pi / 60)
          x = 12.5 + 10 * cos(t)
          y = 12.5 + 10 * sin(t)
          c = new Color(0.5f, 0f, (t / 2 / Pi).toFloat)
        } data(x.toInt)(y.toInt) = c
      }
    

    Which would give you:

    enter image description here

    You can easily use a map function on your existing array to map it to colours.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please recommend some websites with a quick guide. MSDN is good but it's hard
Can any one recommend a good resource to refer on writing C++ custom template
I'm writing a custom tunnel (first there's a custom hello and then the connection
I am writing a program that need to store some configuration information. I thought
They recommend using JTA transaction support in Java EE environment. But how to configure
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Could someone recommend any good resources for creating Graphics User Interfaces, preferably in C/C++?
I'm writing some DB routines and I'm using prepared statements. My environment is PDO
I have been playing around with writing some simple card games in Python for
Programming is learned by writing programs. But code reading is said to be another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.