help with figuring out this code

int topr = 0; // top red int topg = 0; int topb = 0; int botr = 12; // bottom green int botg = 244; int botb = 12; // DO NOT CHANGE THE ABOVE CODE ! void setup() { // open setup size(600, 600); smooth(); background(255); } // close setup void draw() { // open draw // The following code draws the traffic light // DO NOT CHANGE THE CODE BETWEEN THE BROKEN LINES ! //------------------------------------------------------ // ----------------------------------------------------- strokeWeight(1); fill(140); rect(width/2 -30, 10, 60, 120 ); fill(topr, topg, topb); // top light ellipse(width/2, height/2- 260, 30, 30 ); fill(botr, botg, botb); // bottom light ellipse(width/2, height/2- 200, 30, 30 ); strokeWeight(3); fill(250, 187, 187); rect(0, 200, 600, 200); //----------------------------------------------------- //----------------------------------------------------- if (mouseY >=200 && mouseY >= 400) { topr = 0; topg = 0; topb = 0; // change light colors botr = 12; botg = 244; botb = 12; } else if ( mouseX<=200 && mouseX <=400) { topr = 12; topg = 244; topb = 12; // keep lights the same color botr = 0; botg = 0; botb = 0; } // close } // close draw 

it runs well but the lights are mixed up pretty much the 2 lights that must change are top and bottom one. if the mouse pointer enters the gray area, turn the top circle red and the bottom circle black otherwise, the top circle is black and the bottom circle is green

submitted by /u/TouchedByYasuo
[link] [comments]

[PWC6] a simple clock

nothing fancy going on here, and perhaps a little messy, but I made something so I figured I might as well submit it!

import java.util.*; int dayOfWeek, ms, offset; float y, d, h, m, s; String[] months = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; String[] days = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; color[] cmonths = { #FF0000, #0000FF, #00FF00, #FF00FF, #00FF80, #FF0080, #80FF00, #8000FF, #FFFF00, #FF8000, #00FFFF, #0080FF }; color[] cdays = {#800000, #F4F574, #F096DF, #98EA5F, #E8AC34, #58C0F2, #A71BCE}; void setup() { size(1000, 350); smooth(8); textAlign(CENTER, CENTER); noStroke(); Calendar c = Calendar.getInstance(); dayOfWeek = c.get(Calendar.DAY_OF_WEEK); offset = height/8; } void draw() { background(0); y = (width/12)*month(); d = (width/31)*day(); h = ((hour() == 12) || (hour() == 0)) ? (width/12)*(hour()) : (width/12)*(hour() % 12); h = (h == 0) ? 12 : h; m = (width/60)*minute(); s = (width/60)*second(); ms = millis() % 1000; fill(30); for (int i=1; i <= 12; i++) ellipse((width/12)*i - (width/24), height/6+offset, width/12, width/12); for (int i=1; i < 31; i++) ellipse((width/31)*i, height/6*2+offset, width/31, width/31); for (int i=1; i <= 12; i++) ellipse((width/12)*i - (width/24), height/6*3+offset, width/12, width/12); for (int i=0; i <= 59; i++) ellipse((width/59)*i + (width/100), height/6*4+offset, width/59, width/59); for (int i=0; i <= 59; i++) ellipse((width/59)*i + (width/100), height/6*5, width/59, width/59); for (int i=0; i <= 6; i++) ellipse((width/7)*i + width/14, offset/1.5, width/20, width/20); fill(255, 25); textSize(280); text(year(), width/2, height/2); stroke(30); line(10, height/6*5.5, width-10, height/6*5.5); stroke(255); int x = (ms > 50) ? ms - 50 : 10; line(x, height/6*5.5, ms, height/6*5.5); noStroke(); fill(cmonths[month() - 1]); ellipse(y - (width/24), height/6+offset, width/12, width/12); if (hour() > 18 || hour() < 6) fill(120); else fill(200, 200, 0); ellipse(h - (width/24), height/6*3+offset, width/12, width/12); fill(cdays[dayOfWeek - 1]); ellipse((width/7)*(dayOfWeek-1) + (width/14), offset/1.5, width/20, width/20); fill(250); ellipse(d, height/6*2+offset, width/31, width/31); ellipse(m + (width/100), height/6*4+offset, width/59, width/59); ellipse(s + (width/100), height/6*5, width/59, width/59); fill(50); textSize(28); text(months[month()-1], y - (width/24), height/6+offset); text(days[dayOfWeek-1], (width/7)*(dayOfWeek-1)+ (width/14), offset/1.5); text(nf(hour(), 2), h - (width/24), height/6*3+offset); textSize(18); text(day(), d, height/6*2+offset); textSize(14); text(nf(minute(), 2), m + (width/100), height/6*4+offset); text(nf(second(), 2), s + (width/100), height/6*5); text(nf(ms, 3), width/2, height/6*5.5); } 
submitted by /u/davebrown57
[link] [comments]

is it inherently slow to take screenshots? not able to get processing to run faster than 10fps when doing it in the draw loop

i've tried running on a friend's computer (i7 3.5ghz / 32gb ram or something like that) and it was the same story. i've tried manually telling processing to run at a higher frame rate. even with the basic code pasted below, it runs at 7-10fps.

import java.awt.image.BufferedImage; import java.awt.*; PImage screenShot; void setup() { size(500, 500); screenShot = getScreen(); } void draw () { screenShot = getScreen(); image(screenShot,0,0, width, height); surface.setTitle(int(frameRate) + " fps"); } PImage getScreen() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); DisplayMode mode = gs[0].getDisplayMode(); Rectangle bounds = new Rectangle(0, 0, mode.getWidth(), mode.getHeight()); BufferedImage desktop = new BufferedImage(mode.getWidth(), mode.getHeight(), BufferedImage.TYPE_INT_RGB); try { desktop = new Robot(gs[0]).createScreenCapture(bounds); } catch(AWTException e) { System.err.println("Screen capture failed."); } return (new PImage(desktop)); } 
submitted by /u/inthepixelforest
[link] [comments]

Unfolding maps w/Processing 3 (or some other map library if it exists)

Hi, I'm having some problems using Unfolding maps with Processing 3.0.2... I solve the java.lang.NoSuchFieldError: quality error problem as explained here, but I am having problems with drawing markers (or anything else for that matter) on the map. The testing sketch is this, with a bunch of imports at the top:

UnfoldingMap map; void setup () { size (1600,800, JAVA2D); AbstractMapProvider p1 = new Google.GoogleTerrainProvider(); settings(); map = new UnfoldingMap(this, 50, 50, 1600, 800, p1); map.zoomLevel(10); map.panTo(new Location(46.048941, 14.508402)); MapUtils.createDefaultEventDispatcher(this,map); } void draw () { map.draw(); Location location = map.getLocation(46.048941, 14.508402); location = new Location(46.048941, 14.508402); Marker berlinMarker = new SimplePointMarker(location); map.addMarker(berlinMarker); ellipse(50,50,5,5); } 

I have tried adding the marker in setup, before and after map.draw(), gotten location with new Location(lat,long) and map.getLocation(lat,long) as it can be seen, as well as I have tried just drawing on screen, but nothing shows.

I have to use Processing 3 (school assignment) and I would like to use a library of some kind. At the moment, I'm drawing stuff on a world image, but there are problems with zooming (when I zoom the map/background world image moves related to its origin) and stuff like that.

Any help would be appreciated. I can try other libraries as well, I just havent found any...MapThing seems poorly documented and unmaintaned.

submitted by /u/fishribafish
[link] [comments]

Space invaders game – Shooting help

Hey guys, so I'm making a space invaders game, and the only part I'm struggling with is the shooting part. I don't know where to begin, I know I need to make an object spawn from the x,y of the defender by pressing space bar but don't even know how to go about it. I've got a defender that moves so am familiar(kinda) with keypressed. I've tried looking online but the help is all very advanced and complicated. Any help or links to basic tutorials will be very much appreciated.

 Boolean keyLftPressed = false, keyRghtPressed = false; Defender Defender; void setup() { Defender = new Defender(); size(500,500); } void draw() { background(0); Defender.display(); Defender.moveDefender(); } class Defender { int defx = 185; int defy = 400; Defender(){} void display() { rect(defx,defy,100,25); stroke(255,255,255); //outline of bat fill(255,255,255); // colour of bat } void moveDefender() { if (keyLftPressed) { defx -= 10; } if (keyRghtPressed) { defx += 10; } } } void keyPressed() { // code to control defender - TO IMPROVE DONT LET IT LEAVE SCREEN if (key == CODED) { if (keyCode == LEFT) { keyLftPressed = true; } else if (keyCode == RIGHT) { keyRghtPressed = true; } } } void keyReleased() { if (keyCode == LEFT) { keyLftPressed = false; } else { if (keyCode == RIGHT) { keyRghtPressed = false; } } } 
submitted by /u/peterpan020
[link] [comments]

trying to make enemies in a game randomly shoot, but it isnt working? Can anyone tell me why?

I've initialized the array and have working classes for everything etc, it just seems to not be producing anything at all. I have around 24 aliens of the same class moving side to side, just want to have a random alien shoot a shot at a random time.

//Alien Shot Array //Create a shot and add to array. for (int as = 0 ; as< AShotArray.size(); as++){ for (int b = 0; b< 6; b++){ ClassAShot ashot = (ClassAShot) AShotArray.get(as); ashot.render(); b++; if(b == 5){ AShotArray.add(new ClassAShot(AlienArray.get(as).AlienPosX+13,AlienArray.get(as).AlienPosX)); b = 0; as = 0;}} } 
submitted by /u/Jordyluke
[link] [comments]

Trying to export application, application works in play mode in the app, but not when I export it

the 3 classes are bullet enemies and sprite. I have a feeling it is to do with the main file, but i'm unsure what. https://gyazo.com/559d687a54f01fd92592e8643f1afa2e https://gyazo.com/cd086bbe25c155b9db12487b34616dc3 https://gyazo.com/b3135ea8e98245179846fd9e27053f99 https://gyazo.com/9a527bf5daa6a171b1cb318f17b1772e

edit: The error itself is that the screen is just grey when I try to open it.

submitted by /u/SeanMartin96
[link] [comments]