correct and run eclipse code: Tiles1===========================================
ID: 3912941 • Letter: C
Question
correct and run eclipse code: Tiles1=========================================== import processing.core.PApplet; public class Tiles1 extends PApplet { DogPics dogs ; RandomSpotter spots ; public static void main(String[] args) { PApplet.main("Tiles1"); } public void settings() { size(900, 900); } public void setup ( ) { background ( 0 ) ; dogs = new DogPics ( this, 300, 300, 300 ) ; spots = new RandomSpotter ( this, 0, 0, 300 ) ; } public void draw ( ) { dogs.animate ( 1 ) ; spots.animate( 1 ) ; } } \\\\\\\\\\\\\\\\\\\\\\\\\ Tile1A//////////////////////////////////// public class Tiles1A { protected int xloc ; protected int yloc ; protected int size ; protected PApplet theSketch ; ; void Tile1A( PApplet parentSketch, int pX, int pY, int pSize ) { xloc = pX ; yloc = pY ; size = pSize ; theSketch = parentSketch ; } void Tile1A ( ) { } void animate ( int nRepeats ) { } void blank ( ) { } void killTime ( int millis ) { int startTime = theSketch.millis ( ) ; int endTime = startTime + millis ; while( theSketch.millis( ) < endTime ) ; } void clipGraphics( ) { theSketch.clip(xloc, yloc, size, size); } } ; /////////////////////////////////////////////////// Tiles1B \\\\\\\\\\\\ import java.util.ArrayList; import processing.core.PApplet; class RandomSpotter extends Tiles1 { class Spot { public int x ; public int y ; public int theColor ; public int diameter ; public Spot( int pX, int pY, int pColor, int pDiameter ) { x = pX ; y = pY ; diameter = pDiameter ; theColor = pColor ; } } ; ArrayList spots = new ArrayList ( ) ; int nSpots = 0 ; final static int maxSpots = 10 ; RandomSpotter ( PApplet pSketch, int pX, int pY, int pSize ) { super( ) ; } @SuppressWarnings("null") void animate ( int nReps ) { getGraphics ( ) ; PApplet theSketch = null; float size = 0; int x = ( int ) theSketch.random( ( float ) size ) ; int y = ( int ) theSketch.random( ( float ) size ) ; int theColor = theSketch.color( 120, 50, 240 ) ; Spot spot = new Spot ( x, y, theColor, (int)( theSketch.random ( 30 ) ) ) ; spots.add( spot ) ; nSpots ++ ; if(nSpots > maxSpots ) { Spot tmp = spots.remove(0) ; theSketch.fill ( 0 ) ; theSketch.ellipse( tmp.x, tmp.y, tmp.diameter, tmp.diameter ); nSpots -- ; } for( Spot s : spots ) { theSketch.fill( s.theColor ) ; theSketch.ellipse( s.x, s.y, s.diameter, s.diameter ) ; } } }
Explanation / Answer
In order to correct the errors in the above code. Make these changes respectively.
1. Add the below dependency in your pom.xml file:
<dependency>
<groupId>org.processing</groupId>
<artifactId>core</artifactId>
<version>2.2.1</version>
</dependency>
2. Create a file as below:
public class DogPics {
public DogPics(Tiles1 tiles1, int i, int j, int k) {
// TODO Auto-generated constructor stub
}
public void animate(int i) {
// TODO Auto-generated method stub
}
}
3. Create a separate file tiles1A.java. This is because one file can have only one public class at one time
package com.lightbend.akka.sample;
import processing.core.PApplet;
public class Tiles1A {
protected int xloc ;
protected int yloc ;
protected int size ;
protected PApplet theSketch ;
void Tile1A( PApplet parentSketch, int pX, int pY, int pSize ) {
xloc = pX ; yloc = pY ;
size = pSize ;
theSketch = parentSketch ;
}
void Tile1A ( ) {
}
void animate ( int nRepeats ) {
}
void blank ( ) {
}
void killTime ( int millis ) {
int startTime = theSketch.millis ( ) ;
int endTime = startTime + millis ;
while( theSketch.millis( ) < endTime ) ;
}
void clipGraphics( ) {
theSketch.clip(xloc, yloc, size, size);
}
} ;
4. Make these Changes in RandomSpotter.java:
a. Change the declaration of Arraylist as below: ArrayList<Spot> spots = new ArrayList<Spot> ( ) ;
b. Add cast inside animate() method in If block as below: Spot tmp = (Spot) spots.remove(0) ;
After making the changes file will look like:
import java.util.ArrayList;
import processing.core.PApplet;
@SuppressWarnings("serial")
class RandomSpotter extends Tiles1 {
class Spot {
public int x ;
public int y ;
public int theColor ;
public int diameter ;
public Spot( int pX, int pY, int pColor, int pDiameter ) {
x = pX ;
y = pY ;
diameter = pDiameter ;
theColor = pColor ;
}
} ;
ArrayList<Spot> spots = new ArrayList<Spot> ( ) ;
int nSpots = 0 ;
final static int maxSpots = 10 ;
RandomSpotter ( PApplet pSketch, int pX, int pY, int pSize ) {
super( ) ;
}
@SuppressWarnings("null") void animate ( int nReps ) {
getGraphics ( ) ;
PApplet theSketch = null;
float size = 0;
int x = ( int ) theSketch.random( ( float ) size ) ;
int y = ( int ) theSketch.random( ( float ) size ) ;
int theColor = theSketch.color( 120, 50, 240 ) ;
Spot spot = new Spot ( x, y, theColor, (int)( theSketch.random ( 30 ) ) ) ;
spots.add( spot ) ;
nSpots ++ ;
if(nSpots > maxSpots ) {
Spot tmp = (Spot) spots.remove(0) ;
theSketch.fill ( 0 ) ;
theSketch.ellipse( tmp.x, tmp.y, tmp.diameter, tmp.diameter );
nSpots -- ;
}
for( Spot s : spots) {
theSketch.fill( s.theColor ) ;
theSketch.ellipse( s.x, s.y, s.diameter, s.diameter ) ;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.