Cover
 This is the archive Discourse for the Processing (ALPHA) software. Please visit the new Processing forum for current information.
 Processing 1.0 _ALPHA_    Programming Questions & Help    Programs (Moderators: fry, REAS)    rotate BImage « Previous topic | Next topic »

 Pages: 1
 Author Topic: rotate BImage  (Read 525 times)
eskimoblood

 rotate BImage « on: Feb 28th, 2005, 1:49pm »

Is there a way to rotate a BImage object like:
BImage a=get (0,0,20,20);
rotate(180);
set(0,0,a);
fjen

 Re: rotate BImage « Reply #1 on: Feb 28th, 2005, 2:31pm »

Code:
 // freely rotate a BImage   // fjenett, feb 2005, offenbach-main, germany // www.florianjenett.de   BImage img;   void setup() {   size(200,200);   img = loadImage("house.jpg"); }   float rotation = 0.0;   void loop(){   background(0);   image(rotateImage(img, rotation), 0, 0);   rotation += 0.02; }   BImage rotateImage (BImage _img, float _rad) {   if (_rad == 0) return _img;     int xm = _img.width;   int ym = _img.height;       BGraphics _bimg = new BGraphics(xm, ym); _bimg.format = RGB;   _bimg.background(255);   _bimg.noStroke();       _bimg.translate(xm/2.0, ym/2.0);   _bimg.rotateZ(_rad);     _bimg.beginShape(QUADS);    _bimg.texture(img);      _bimg.vertex( -(xm/2),  -(ym/2),0,  0,0);      _bimg.vertex(  (xm/2),  -(ym/2),0,  xm,0);      _bimg.vertex(  (xm/2),   (ym/2),0,  xm,ym);      _bimg.vertex( -(xm/2),   (ym/2),0,  0,ym);   _bimg.endShape();       return (BImage) _bimg; }

if you rotate exactly 90, 180 or 270 degree, then you can just mirror the pixels array ... i think that's faster.

/F
eskimoblood

 Re: rotate BImage « Reply #2 on: Mar 1st, 2005, 12:37pm »

Here is the code to mirror an image horizontal and vertical:

Code:
 void setup(){   size(702,482);   BImage b1=loadImage("pic1.jpg");   BImage b2=new BImage(b1.width,b1.height );   BImage b3=new BImage(b1.width,b1.height );   BImage b4=new BImage(b1.width,b1.height );   for(int j=0;j
JohnG

 Re: rotate BImage « Reply #3 on: Mar 1st, 2005, 5:11pm »

you can actually use the rotateZ command to rotate an image:
Code:
 BImage MyImage=loadImage("whatever"); float angle=0;   void loop() {   angle+=0.01;   background(0);   translate(width/2,height/2);   rotateZ(angle);   image(MyImage, -MyImage.width/2, -MyImage.height/2, MyImage.width, MyImage.height); }

Much easier than trying to work out the maths for yourself.
 « Last Edit: Mar 1st, 2005, 5:13pm by JohnG »
 Pages: 1

 Forum Jump: ----------------------------- Discussion -----------------------------  - Community, Collaboration, Status   - Events, Publications, Propaganda   - General Processing Discussion ----------------------------- Programming Questions & Help -----------------------------  - Syntax => Programs   - Integration ----------------------------- Topics & Contributions -----------------------------  - Tools   - Responsive Form, Games   - Information Visualization   - Simulation, Artificial Life   - Tangible Computing   - Automated Systems   - Sound   - Video, Camera   - Beyond Categories ----------------------------- Suggestions -----------------------------  - Software Suggestions   - Website, Reference, Example Suggestions ----------------------------- Bugs -----------------------------  - Software Bugs   - Website, Reference, Example Bugs   - Bug Fixes, Implemented Suggestions ----------------------------- Teaching -----------------------------  - Course Blueprints   - Theory and Practice « Previous topic | Next topic »