gradientsgradients • gradient: vary color from one to another interpolating in between • current...

28
CS324e - Elements of Graphics and Visualization Gradients

Upload: others

Post on 25-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

CS324e - Elements of Graphics

and Visualization

Gradients

Page 2: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

GUIs

2

Mac 1984

Windows 3 1990

Page 3: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

GUIs

3

Page 4: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

Gradients

• Gradient: vary color from one to another

interpolating in between

• Current trend (~2010) is to use gradients

everywhere in interfaces and graphic design

• Java provides some built in classes to create

and apply gradients

– GradientPaint

– LinearGradientPaint

– RadialGradientPaint

4

Page 5: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

GradientPaint

• Define two end points and two colors

• color varies along a line drawn between

two points

– same colors along lines drawn

perpendicular to line connecting points

• Set Graphics2D object paint to the

GradientPaint

• Anything drawn or filled uses gradient

5

Page 6: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

GradientPaint Example

6

Page 7: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

GradientPaint

7

Page 8: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

GradientPaint

• By default gradient is acyclic

– beyond endpoints color is same as color at

endpoint

8

Page 9: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

GradientPaint

• Set GradientPaint to cyclical

– another constructor

9

Page 10: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

LinearGradientPaint

• Until Java 6.0 in 2006 GradientPaint was

only gradient

• LinearGradientPaint added in version 6.0

• GradientPaint only allowed 2 paints

• LinearGradientPaint allows 2 or more

colors

• Can alter "distance" between two paints

• More options

10

Page 11: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

LinearGradientPaint

• 4 Colors

11

Page 12: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

LinearGradientPaint

• Define 2

endpoints

• array of fractions

and array of

colors must be

equal in length

• fractions defines

portion to use

that color12

Page 13: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

LinearGradientPaint

13

Page 14: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

LinearGradientPaint

• Change Fractions

• {0, 0.1f, 0.9f, 1} // f for float

• fractions must be in strictly increasing

order

14

Page 15: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

LinearGradientPaint - REFLECT

• Previous examples were acyclic

• Cycle can be set to reflect or repeat

15

Page 16: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

LinearGradientPaint - REPEAT

16

Page 17: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

LinearGradientPaint

• or REPEAT

17

Page 18: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

RadialGradientPaint

• Specify two or more colors, a center

point, and a radius

• can also set the focal point to a spot

other than the center

• May be acyclic (NO_CYCLE), REFLECT, or

REPEAT similar to LinearGradientPaint

18

Page 19: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

RadialGradientPaint

19

Page 20: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

RadialGradientPaint

20

Page 21: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

RadialGradientPaint Constructor

• Not only one!21

Page 22: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

RadialGradientPaint

• Example with ellipse

not centered

• Can either move

ellipse or change focal

point of gradient

paint.

• Slightly different

effects

22

Page 23: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

RadialGradientPaint - Altered Focal Point

23

Page 24: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

Putting Gradients to Use

• Create a reflection of an image using

gradients and alpha composite

• Draw an image

• Draw the same image below it, reflected

• Create a paint that varies alpha from half

to 0

• Use Alpha Composite to combine alpha

paint and upside down image

24

Page 25: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

Image

25

Page 26: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

Reflection

26

Page 27: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

Gradient

(alpha mask)

27

Page 28: GradientsGradients • Gradient: vary color from one to another interpolating in between • Current trend (~2010) is to use gradients everywhere in interfaces and graphic design LinearGradientPaint

Final result using

AlphaComposite

DstIn

28