graphics.setcolor - what parameter? - java-me

im using the Graphics.setColor() to set the color of an arc im drawing. what im tring to figure out is what color format do i stick into the brackets. its not RGB because i cant use letters

You need to pass in a Color object.
The documentation is quite clear - didn't you check it?
You can do the following:
g.setColor(new Color(255, 255, 0);
Where g is an object of type Graphics.

Related

How do I tint an svg in processing and preserve brightness?

I've been trying to figure this out for 2 days now, so I hope somebody can help.
I need to load in svg files that have multiple values of gray within them and tint them with colors. So for example, say the svg file is an image of a rock and has 4 values of gray. I need to be able to display the rock as red and keep the differences between values in the different child shapes. In other words, I would like it to work just like PImage.tint().
I see there are tint() and setTint() methods to PShape but I can't seem to get them to work. I also though about recursing through the child shapes and reading each color individually and recoloring appropriately, but I couldn't even figure out how to read the color out in a way I understand.
Help, anyone?
If you have it as an <img> you can use the CSS filter property with hue-rotate https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/hue-rotate
Or you add the svg directly to the html and add classes to your elements. Then you could change the colors in your script.
If this is a flat colour then you could use the alpha value in RGB colour value. See 'color transparency' in the following link: https://processing.org/tutorials/color/
The fill value is fill(red, green, blue, transparency)
I hope this helps. If you want to share code and have a reason for using PImage I'd be happy to have a look.

MeshBasicMaterial color tints texture map three.js

I'm working with a MeshBasicMaterial to which I have applied a color.
var material = new THREE.MeshBasicMaterial({color: myColor});
at some point I need to add a texture to the material
material.map = new THREE.ImageUtils.loadTexture(...);
this works fine but the color of the material is tinting the texture.
I realise I can change the color of the material to white to remove this tinting but cannot find a a way of deleting the material's color or changing the way the color and texture blend - is this possible ? I'm trying to avoid creating a new material and replacing if possible.
demonstrated in Lee Stemkoski's examples - change map to 'grass' and then change the material color
http://threejs.org/docs/scenes/material-browser.html#MeshBasicMaterial
By the fact you can set the material's .map after the fact, you should be able to set the material's .color after the fact.
material.color = myColor;
Of course, this new color should be white for your texture to be visible and not black.

convert basic RGB to alpha in pygame

light_green = (0,200,0,100)
pygame.draw.rect(game_display,light_green,(50,200,60,110))
I know that this has the alpha property in the 4th section(100). But it is not transparent when applied on top of a background. It is simply just a solid square block. I want to be able to see the background through the square. Any help always appreciated. Thanks :)
The draw module's functions do not draw transparent. See the documentation for draw
Most of the arguments accept a color argument that is an RGB triplet.
These can also accept an RGBA quadruplet. The alpha value will be
written directly into the Surface if it contains pixel alphas, but the
draw function will not draw transparently.
A workaround is to use the respective functions from the pygame.gfxdraw module instead, they add transparency, for your case the box function.
import pygame.gfxdraw
light_green = (0,200,0,100)
pygame.gfxdraw.box(game_display, pygame.Rect(50,200,60,110), light_green)
If you only want to draw rectangles you can as an alternate way directly fill a Surface and blit it to the screen.
light_green = (0,200,0,100)
s = pygame.Surface((60, 110), pygame.SRCALPHA)
s.fill(light_green)
game_display.blit(s, (50, 200))

Can an SVG object have both a fill colour and a fill pattern?

I'm working with SVG using the Raphael library. I can apply a fill colour to an object like so:
circle.attr({fill: "#ff0000"});
And this also works (though the Raphael documentation doesn't mention it):
circle.attr({fill: "url(pattern.png)"});
I am able to use transparent PNGs as fill patterns, and transparency works as expected. The svg object is completely transparent where the fill pattern image is transparent. But what I would like to do is specify both a fill pattern image and a fill colour, so that the colour would show through where the pattern image is transparent - similar to the 'background' property using CSS, for example. Is this possible with SVG?
You can define a pattern that has a rect with a fill, and an image that is your png on top of that rect. Then use the pattern as fill for the circle (or whatever element you want).
This means stepping outside of Raphaël, or extending it to do what you want. Note that what ({fill: "url(pattern.png)"}) does is to create a pattern element and and append an image element pointing to the given url. It's quite possible to hack Raphaël to allow you to pass a color too, and then you deal with that in the code that creates the pattern by creating a rect of the same dimensions as the image with the given fill color.
I should say that if you want it to work with IE<9 then you probably need to implement it in VML too.
Other options include drawing two shapes, one with color fill and the other with the raster image fill. Yet another is to make the png include the background color so that it's not transparent.

OpenGL ES2 GLubyte colors in vertex array not working

Apple suggests using the GLubyte data type for color data on iOS, so I am trying to get this to work. The result I get is that all color components <255 are completely black, and only components of colors set to 255 really are that color.
What I am doing:
-Save the color of a single object in my own Color class in GLubytes (range 0-255)
-Pass the colors to the shader in a vertex attribute array with type GLubyte (still range 0-255)
-In the fragment shader, use the color directly or divide components by 255, both do not work.
EDIT: this does work, the problem was somewhere else in my code.
Where does Apple recommend using GLubyte for vertex attributes? I think you have misinterpreted that hint. What you actually want to do is store those values in a 256x1 grayscale (GL_LUMINANCE) texture and pass it as a uniform to the shader. This would be indeed faster than using arrays.
This does just work fine, the problem was somewhere else in my code.

Resources