Adding element to arrayList - Eclipse
in
Integration and Hardware
•
3 months ago
Hi,
I have another small issue with the code in eclipse. I just want to add 25 shapes in arrayList. This works also in processing but not in eclipse.
I marked the line in red. According to eclipse I get error and nothing works...
Could you help me please?
Thank you.
- package tutorialpshapeoop2;
- import java.awt.Polygon;
- import java.util.ArrayList;
- import processing.core.PShape;
- import processing.core.PApplet;
- public class TutorialPShapeOOP2 extends PApplet {
- ArrayList<Polygon> polygons;
- public void setup() {
- size(640,360,OPENGL);
- smooth();
- polygons = new ArrayList<Polygon>();
- PShape star = createShape();
- star.fill(0,127);
- star.stroke(0);
- star.vertex(0, -50);
- star.vertex(14, -20);
- star.vertex(47, -15);
- star.vertex(23, 7);
- star.vertex(29, 40);
- star.vertex(0, 25);
- star.vertex(-29, 40);
- star.vertex(-23, 7);
- star.vertex(-47, -15);
- star.vertex(-14, -20);
- star.end(CLOSE);
- for(int i = 0; i < 25; i++){
- polygons.add(new Polygon(star));
- //polygons.add(new Polygon(this,star)); //do not work either
- }
- }
- public void draw() {
- background(255);
- for(Polygon poly : polygons){
- poly.display();
- poly.move();
- }
- }
- }
- package tutorialpshapeoop2;
- import processing.core.PApplet;
- import processing.core.PShape;
- public class Polygon {
- PApplet parent;
- PShape s;
- float x,y;
- float speed;
- Polygon(PApplet p, PShape s_){
- parent = p;
- x = parent.random(parent.width);
- y = parent.random(-500,-100);
- s = s_;
- speed = parent.random(2,6);
- }
- void move(){
- y += speed;
- if(y > parent.height+100){
- y = -100;
- }
- }
- void display(){
- parent.pushMatrix();
- parent.translate(x,y);
- parent.shape(s);
- parent.popMatrix();
- }
- }
1