To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.off-topic.funOpen lugnet.off-topic.fun in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Off-Topic / Fun / 971
970  |  972
Subject: 
Re: Java LDraw/LDLite
Newsgroups: 
lugnet.off-topic.fun
Date: 
Fri, 26 Feb 1999 19:15:11 GMT
Viewed: 
1254 times
  
I guess I'll be learning Java RSN.  Anyone have a preference on what
development tools to use?  More important, any pointers to good learning
tools (ie, books)?

Thanks,
Steve

On Thu, 25 Feb 1999 22:13:44 GMT, lehman@javanet.com (Todd Lehman)
wrote:

In lugnet.cad.dev, blisses@worldnet.att.net (Steve Bliss) writes:
How do you draw (pixels) in Java?  Are there built-in functions, or
would it require platform-specific code, or what?  Or graphics library,
perhaps?

It's surprisingly easy.  Java actually doesn't suck!  :)

You just allocate a buffer, designate it as being a graphics buffer, and call
functions to do graphics primitives.  Here's an example -- not probably a
great example because it's 3 years old and not documented worth a darn -- but
it was quick to dig up and does give an example of raster blasting at a low
but completely portable level.

I'm sure the standard libraries have faster code than this for filling
rectangles, but I needed bilinear-interpolated shaded rectangles, so I had to
do it by hand.

BTW, one of the BEST things about it is that you can work entirely in 24-bit
(or 32-bit) color and the built-in graphics subsystem takes care of color
quantization totally transparently!  (no pun intended :)

--Todd

_____________________________________________________________________________

// Basic raw (low-level) image class for Mandelbrot fractal explorer.
//
// Todd Lehman, May 28, 1996

import java.awt.*;
import java.applet.*;
import java.awt.image.ColorModel;
import java.awt.image.MemoryImageSource;

public class RawImage
{
  protected int dx, dy;
  private int pixels[];
  private Image img;
  private MemoryImageSource mis;
  private boolean isdirty;

  public RawImage(int dx, int dy)
  {
     this.dx = dx;
     this.dy = dy;
     this.pixels = new int[dx * dy];
     this.mis = new MemoryImageSource(dx, dy, ColorModel.getRGBdefault(),
                                      pixels, 0, dx);
     this.isdirty = true;

     for (int p = dx*dy-1; p >= 0; p--)  pixels[p] = 0xFF000000;
  }

  public int GetWidth()  { return dx; }
  public int GetHeight() { return dy; }

  public synchronized Image GetImage()
  {
     if (this.isdirty)
     {
        this.isdirty = false;
     }

     return this.img;
  }

  public MemoryImageSource GetMemoryImageSource()
  {
     return mis;
  }

  public int GetPixelColor(int x, int y)
  {
          if  (x < 0)         x = 0;
     else if  (x >= this.dx)  x = this.dx-1;

          if  (y < 0)         y = 0;
     else if  (y >= this.dy)  y = this.dy-1;

     return pixels[(y * this.dx) + x];
  }

  public void SolidFillRect(int x0, int y0, int dx, int dy, int color)
  {
     for (int y = y0+dy-1; y >= y0; y--)
     {
        int p = (y * this.dx) + x0 + dx - 1;

        for (int x = x0+dx-1; x >= x0; x--)
        {
           pixels[p--] = color;
        }
     }

     this.isdirty = true;
  }

  public void SmoothFillRect(int x0, int y0, int dx, int dy,
                             int c00, int c10, int c01, int c11)
  {
     if ((x0 < 0) || (x0+dx >= this.dx) ||
         (y0 < 0) || (y0+dy >= this.dy))
     {
        return;
     }

     int A = 0xFF000000;
     int R = 0x00FF0000;
     int G = 0x0000FF00;
     int B = 0x000000FF;
     int X = 0x00FF0000;

     int r00=(c00 & R)<<0,  r01=(c01 & R)<<0,  r0=r00, r0inc=(r01-r00)/dy;
     int g00=(c00 & G)<<8,  g01=(c01 & G)<<8,  g0=g00, g0inc=(g01-g00)/dy;
     int b00=(c00 & B)<<16, b01=(c01 & B)<<16, b0=b00, b0inc=(b01-b00)/dy;

     int r10=(c10 & R)<<0,  r11=(c11 & R)<<0,  r1=r10, r1inc=(r11-r10)/dy;
     int g10=(c10 & G)<<8,  g11=(c11 & G)<<8,  g1=g10, g1inc=(g11-g10)/dy;
     int b10=(c10 & B)<<16, b11=(c11 & B)<<16, b1=b10, b1inc=(b11-b10)/dy;

     int p = (y0 * this.dx) + x0;

     for (int y = 0; y < dy; y++)
     {
        int r = r0, rinc = (r1 - r0) / dx;
        int g = g0, ginc = (g1 - g0) / dx;
        int b = b0, binc = (b1 - b0) / dx;

        for (int x = 0; x < dx; x++)
        {
           pixels[p++] = A |
                         ((r & X) >>> 0) |
                         ((g & X) >>> 8) |
                         ((b & X) >>> 16);
           r += rinc;
           g += ginc;
           b += binc;
        }

        r0 += r0inc; r1 += r1inc;
        g0 += g0inc; g1 += g1inc;
        b0 += b0inc; b1 += b1inc;

        p += this.dx - dx;
     }

     this.isdirty = true;
  }
}




Message has 1 Reply:
  Re: Java LDraw/LDLite
 
(...) Books: I would recommend Peter van der Linden's "Just Java", and / or (forget the author) "Core Java", as these are excellent tutorials with good code. (1) The O'Reilly book "Java Swing" is a very good introduction to the GUI libraries, but (...) (26 years ago, 26-Feb-99, to lugnet.off-topic.fun)

Message is in Reply To:
  Re: Java LDraw/LDLite
 
(...) It's surprisingly easy. Java actually doesn't suck! :) You just allocate a buffer, designate it as being a graphics buffer, and call functions to do graphics primitives. Here's an example -- not probably a great example because it's 3 years (...) (26 years ago, 25-Feb-99, to lugnet.cad.dev)

51 Messages in This Thread:

















Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR