java - Is JAVA2D the only rendering mode to display transparent PGraphics objects in Processing? -
is java2d
rendering mode in processing in pgraphics
objects can displayed transparent background (as opposed p2d
, p3d
)? have tried rewriting code in other 2 modes (p3d
, p2d
) backgrounds of pgraphics
turn out opaque (black default)---perhaps i'm missing method turn them transparent? png
s i'm displaying in pgraphics
objects turning out transparent expected; it's backgrounds of pgraphics
opaque. working on project , have selected java2d
in order keep pgraphics
transparent, wonder if can alternately use p3d
, features instead.
from looking around online believe java2d
mode render pgraphics transparent in earlier versions of processing (1.*), , i'm wondering if has changed version 2?
thanks in advance clarification , help!
update:
below sample of code (written in eclipse in java processing component). v.k.'s reply works great (with png
s) in processing pde, i've been unsuccessful getting work in project in eclipse. thoughts? :
main class:
package tester; import java.util.arraylist; import processing.core.*; public class graphicsmain extends papplet{ int screenwidth = 800; int screenheight = 500; pgraphicsmaker pgm = new pgraphicsmaker(this); arraylist<pgraphics> motifarray = new arraylist<pgraphics>(); public void setup() { size(screenwidth,screenheight,p3d); background(0); motifarray = pgm.makemotifarray(); if (motifarray.get(0) == null) { system.out.println("the motif array unfilled!"); } } public void draw() { (int = 0; < motifarray.size(); ++) { image(motifarray.get(i),200+(10*i),100); } } static public void main(string[] passedargs) { string[] appletargs = new string[] { "graphicsmain" }; if (passedargs != null) { papplet.main(concat(appletargs, passedargs)); } else { papplet.main(appletargs); } }
second class:
package tester; import java.util.arraylist; import processing.core.*; public class pgraphicsmaker { string filepath = "/a/filepath/here/"; papplet parent; int populationsamplesize = 16; int stagewidth = 100; int stageheight = 400; arraylist<pgraphics> motifarray; pimage pic; pimage pic2; public pgraphicsmaker(papplet pa) { parent = pa; pic = parent.loadimage(filepath + "small_jones6.png"); pic2 = parent.loadimage(filepath + "small_dresser10.png"); } public arraylist makemotifarray() { string filepathtemppngs = "/a/filepath/here/temppngs/"; arraylist<pgraphics> motifarray = new arraylist<pgraphics>(); (int = 0; < populationsamplesize; i++) { motifarray.add(parent.creategraphics(stagewidth,stageheight,parent.p3d)); motifarray.get(i).begindraw(); motifarray.get(i).background(255, 255, 255, 0); motifarray.get(i).image(pic,10,10,100,90); motifarray.get(i).image(pic2,10,50,50,50); motifarray.get(i).enddraw(); motifarray.get(i).save(filepathtemppngs + "motif" + + ".png"); } return motifarray; } }
note: i'm not last save()
function necessary in makemotifarray()
in second class (just attempt preserve transparency).
the code below worked me in 1.5.1 , 2.0b8... if got right doing need... check out:
pgraphics p; void setup(){ size(400,400,p3d); p = creategraphics(400,400,p3d); smooth(); stroke(180,90,210); } void draw(){ background(180,90,210); p.begindraw(); p.background(220, 180, 40,0); p.nofill(); p.stroke(220, 180, 40); p.translate(width/2 - (width/2 - mousex), height/2, 400-mousey*5); p.sphere(100); p.enddraw(); pushmatrix(); translate(width/2, height/2, -200); rotatey(radians(framecount)); rotatex(radians(framecount/2)); box(100); popmatrix(); image(p,0,0); }
Comments
Post a Comment