Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] color gradients

Started by nap410 Aug 18, 2000 at 3:10 PM 0 replies 550+ views
Original Post
nap410
nap410
Hi, i''m new to java. I know that java 1.2 has a builtin method in graphics2d to create a gradient given two colors, but I was wondering how it could be done in 1.0, thanks.
loserkid
loserkid
Hi;

Unfortunately, their is no built method for gradient filling in the Java 1.0 graphics classes (none that I've come across anyway), so you will have to do it manually. Say you want to go from black to blue.

        
//assuming the applet width is at least 255

for(int i = 0; i < 256; i++) {
g.setColor(new Color(0,0,i));
g.drawLine(i,0,i,getSize().height);
}


From this code you could apply different colors and such. Of course this is not the only way to do it,but it's all i've ever needed.

Hope this helped (a little ).

=============================
silly programmer vb is for kids.
============================
www.thejpsystem.com

Edited by - loserkid on August 18, 2000 6:13:33 PM
==============================================I feel like a kid in some kind of store... ============================================== www.thejpsystem.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.