You are better off setting up a regular Java project and including Processing's JAR as a library from your project. Here's instructions for doing it in Eclipse.
What a cute bear!
In general when you want to rotate something you have to translate into the center of whatever you want to rotate around and then call rotate with some changing parameter based on time, like frameCount*.1 and draw your thing after that.
Keep in mind that translate changes the meaning of all coordinates after it, so after translate(width/2, height/2) calling ellipse(0,0,20,30) will actually draw the ellipse in the center of your canvas rather than the corner.
I made you a simple robot face to illustrate the general idea:
void setup() { size(400, 400); }
void draw() { float t = frameCount*.05; background(200); rectMode(CENTER); rect(width/2, height/2, 300, 300); //robot head as background
pushMatrix(); //save original matrix translate(width/3, height/3); //move matrix to center of left eye rotate(t); //rotate based on time rect(0, 0, 20, 20); //draw rectangle centered at 0,0 popMatrix(); //load original matrix
pushMatrix(); //do the same thing for the other eye translate(width-width/3, height/3); rotate(-t); //rotate backwards rect(0, 0, 20, 20); popMatrix();
rect(width/2, height-height/4, 200, 20); }
basically yes! look at classes — you could make a new Wall
class (containing whatever variables a wall needs: x position, y position, width height, colour etc.), and a function that draws the wall.
then make as many Wall
objects as you want!
Processing code can't run on a gpu. A gpu runs things called shaders, which are programmed in it's own programming language. You'll need to learn something completely new to work with them.
It's a ternary operator. It essentially acts as a shortcut for writing an if else statement. You can read more about it here
strokeWeight(special ? random(0.75, 3) : 0.75);
is equivalent to
if(special){ strokeWeight(random(0.75,3)); } else { strokeWeight(0.75); }
I made this quicky. I'm currently sick and it was painful... On my webpage : https://bleuje.github.io/p5js-myprojects/dark-side-moon/index.html On codepen : https://codepen.io/Bleuj/pen/ozZpwp
edit : little update
Unlike Processing.js it is officially approved and supported by the Processing Foundation. And as always, Dan Shiffman has made a great tutorial series.
Java applets are dead.
Sketch out your idea with pen and paper, then translate it to code.
Seriously, just draw a rectangle that represents the canvas, draw your diagram idea, then pull out labels of the lines/heptagon/etc... that you want to draw/be affected by your input data. Post your diagram here with questions on how to achieve a certain thing you're trying to do. People here are super kind and will give pointers on how to do it, or refer you to something in the reference
A particle system is what you are looking for. Problem is, I have no clue what your expertise in programming is. But particle systems will require at least a basic understanding of object oriented programming (OOP). As soon as you know how to set up a class and create objects from it, you are good to go. Fortunately for you, there's a great resource to learn all that stuff. Enter the zany world of the great Dan Shiffman. He has a ton of fun and informative videos talking about everything you need to know. Here is the first video about particle systems. Look for OOP-related videos in the playlist. Also, Dan has just recently published his second book on coding, and it's free to read online.
For code you need to indent 4 spaces so Reddit will format it correctly. In the future you also might consider something like hastebin or gist to give people syntax highlighting.
You've given a code dump and told us vaguely what you want but it's unclear what kind of response you expect. If you have a specific question I'm sure we could help but if you're asking for someone to walk you through your design conceptually, that could take a lot of time.
There's a line strokeCap function in processing, first of all. Start there, so you don't have those rounded-looking lines.
Other than that, it looks fine to me. If it does the job you want it to do, good job!
I would like to point out that there is also a settings() method which runs just before the setup() method. It lets you do some nice stuff like setuping the window's dimensions using calculations!
int w = 200; int h = 200; int x = 0;
void settings() { size(w, h); }
void setup() { background(0); noStroke(); fill(102); }
void draw() { rect(x, 10, 1, 180); x = x + 2; }
Really underappreciated!
Sorry but I'm not analyzing code formatted like this. Please, use a code block next time. I'll give you general pointers just in case it'll help:
​
class Delay { int limit;
Delay (int l) { limit = millis() + l; }
boolean expired () {
if (millis() > limit) { return true; }
return false; } }
I can answer questions about these concepts if needed. Have fun!
It’s still down. I really wish they hadn’t abandoned the downloadable p5.js editor. p5.js works suitably with the Atom editor, but I recommend also downloading Firefox Developer edition to use in conjunction with the Atom editor so you can view your sketches.
https://atom.io https://www.mozilla.org/en-US/firefox/developer/
Variables go without quotation marks when used inside text(), while anything else needs to be quoted.
Following your example:
text("score : score2", 0, 0);
will display score : score2 at 0,0. However,
text(score + ":" + score2, 0,0);
will display 3:7 at 0,0 instead.
Here's the reference if you want to check it out.
Couldn't you put the code inside the keyPressed function outside the draw loop?
e.g.
draw(){ Code }
keyPressed(){ if key is s Your code }
What you want is an object that keeps track of its own X and Y coordinates. This can be something as simple as a PVector object or a custom class of object that holds its own coordinates and other information.
Well, you'll need video as input. The entire idea behind slit scanning is that you're delaying portions of the frame over time, and thus you need video input. You can't slit scan an image.
The basic formula would be:
Read a frame of video, draw it to the screen. Read a second frame, and draw it- but clip off the top row of pixels, draw it on top of the last frame. Repeat until you hit the bottom of the render area.
To handle the cropping, you'd use get. To get the video, you'd need to use some of these objects.
Finally, to save an image- like say, when you hit the bottom- you use the saveFrame
method. When in the process you call that is up to you- it could be in response to a key press.
There's a great Skilshare introductory course on developing with this, along with a few tips on colour selection techniques/composition etc., taught by Joshua Davis, who iirc is one of the initial developers of hype:
Theoretically, once the code starts running, the difference in speed between C++ and Java should not be that big, with the exception of trigonometric functions, which for cross-platform compatibility reasons, are really slow in Java. However, code that draws to the screen, is normally faster in C++ since there is less overhead (wrappers, native bindings, etc). What kind of computations are you doing? Maybe I can help a bit to speed them up.
If you want to try C++, you should also look at openFrameworks. From what I understand, it uses a subset of C++ more familiar to people who come from java/processing. Cinder is awesome, but uses a lot of modern C++ formalisms which can be a little intimidating to a C++ beginner.
Have you seen gradients using beginShape and endShape? You can set color on a per vertex basis and the shape interpolates the color between the vertices for you. Blew my mind when I was told about it.
​
void setup() { size(800, 800, P2D); }
void draw(){
beginShape();
fill(255);
vertex(0, 0);
vertex(width, 0);
fill(0);
vertex(width, height);
vertex(0, height);
endShape(CLOSE);
}
​
Edit: This also works for the various shape types described in the beginShape reference page. Also there's a more involved way to achieve cool effects including gradients, you could be using shaders to texture your shapes. It's actually what happens behind the scenes for the above example anyway, you'd just be doing it manually with a lot more control.
I'd probably look at how to connect a serial connection from processing to your arduino over serial connections.
https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing/all
Then, as a separate prototype, create a processing to excel solution.
https://processing.org/reference/saveTable_.html
Then build a new solution based off of the two existing prototypes.
PImage.get
is an accessor method. Its purpose is to retrieve sections of the image as an array, which you can then do other things with.
.copy
is multipurpose. If you call it with no parameters, it allows you to simply duplicate the entire image. With lots of different parameters, it allows you to copy a part of an image onto another part of the same image.
get
lets you check what's in the image. copy
allows you to copy/paste all over the image.
If I'm understanding you correctly, the solution would be to reimplement your ball code as a Java class and create new balls as instances of that class. This way you can just call your class constructor function [say, new BouncingBall()] in mousePressed() to spawn new balls at runtime instead of hardcoding each one in, which will probably spare you a lot of memory/performance/development headaches.
Here's a good primer on using objects and classes in Processing that shows how you can translate your current program design into an object-oriented one: https://processing.org/tutorials/objects/ -- /u/GoSubRoutine's tutorial links also break this down in a really good way for beginners.
Best of luck!
Ask and ye shall receive:
https://processing.org/reference/pixels.html
my humble example: https://gist.github.com/KrabCode/292d1b51db7d6b15fb509648e8448ade
allow me to direct your attention to these methods:
modifyPixels() which prepares the stage with calls to loadPixels() and updatePixels as per the reference page
shiftL() which uses swapPixels() which uses getPixel() and setPixel()
The easiest way would be to use the split() function. Split() takes a string and returns an array of strings split up by user a character or string as a delimiter. In your case it would be very simple.
String text = "Your text goes here."; String words[] = split(text, " ");
This will however keep punctuation attached to any words. It may beyond your skill right now, but these sorts of problems are very easily solved by what is called a regular expression, or regex. As always, Shiffman has a pretty good video and guide on them. Essentially regex's are like using "find" in Word but on steroids.
Edit: just realised this is only half the answer.
To select a random word from our new words array we can simply do:
String word = words[int(random(words.length))];
This might be a bit complicated looking at first but all we're doing is randomly generating a number between 0 and the size of the words[] array. Random generates a float number so we need to cast it as an integer by wrapping random inside of int(). The. We can display that word on the screen:
text(word, x, y);
Where x and y are the coordinates of where you want to display. There are some ways to adjust textSize() as well as loading a textFont() but for now this is enough.
Hi, this is my try, https://rawgit.com/Bleuje/p5js-myprojects/master/generated-joydivision-cover/index.html
edit : codepen version : https://codepen.io/Bleuj/pen/JRWkjg I fixed some things on codepen and I don't really know why the other version seem to work now :)
I recorded a video of my screen while coding, I may upload that later especially if anyone is really interested.
I didn't mean it works. I'm just not getting an error message. That's actually a problem. But referring to what u/davebees and u/AGardenerCoding said, it doesn't seem to be a bug, PGraphics objects just need to be made one at a time.
Also, using createGraphics() in draw-loop is quite wasteful as you need to make them only once. It'd be better to create them in setup() as in this example.
I suppose that your problem is how to move several different shapes as one? This createShape() reference page should be helpful when creating a shape from multiple parts to work as one.
I don't know the Chladni equations but it definitely sounds possible. Break the problem down into its individual steps, adding as many as needed. Might be something like:
I also don't know anything about working with audio. But I do know there's an audio library for Processing.
Well the PGraphics itself inherits from PImage and can be drawn as an image onto another canvas. If you want the pixels themselves you'd want to use myNewImage.loadPixels()
and then access its pixels
array.
Try recreating each individual element as separate class -> https://processing.org/reference/class.html
​
A starfield
The noise
The rings
​
Combine everything and add the pixellook.
What you're going to want to look into is the PVector class. Instead of having an array crammed with all the X coordinates, and an array crammed with all the Y coordinates, each ball can be represented by a PVector, which combines the X/Y coordinates into a single object and provides a lot of helper functions for handling the vector arithmetic.
So, how do you aim by moving the mouse? By using a PVector
operation to figure out the vector which connects the mouse pointer with the white ball. How do you draw a line? By drawing a line that follows the PVector which connects the mouse with the white ball. How do you handle things bouncing? By rotating the PVector which describes the velocity of the ball.
Also, instead of having an array of PVector
s representing the balls, I'll suggest instead having a Ball
class, which has a PVector position
, a PVector velocity
, and a color c
property. Try and start with just one ball instance, that is your white ball, and work on playing with PVectors to see how you can interact with its position and velocity.
We don't even know what your problem is, how can we help you achieve your goal? 2D morphing can be done like this: https://processing.org/examples/morph.html
3D will be very similar, just with another dimension.
In your code you are looking at the keyPressed event in one if statement and then again seperately in other. Since the key has been pressed, both of these events become true and both sets of code are executed.
The reference documentation has an example that uses keyCode so that you can do different things depending on the actual key pressed, see here: https://processing.org/reference/keyCode.html
The first thing to realize about Processing is that it is thinly veiled Java. Similar to the main()
function in a C program, Java programs have a main()
method.
Processing has its own compiler that picks up your setup()
function and runs it once upfront. Presumably the main()
method generated by the compiler is responsible for calling your setup()
function.
Then the draw()
function will be called at the frequency of your frame rate. Again it's the compiler that is responsible for picking up this function and generating a Java program that behaves in this way.
With this in mind you could lean into Java OOP concepts and write classes to better organize your code.
Another direction is to import libraries that extend Processing's functionality and blow the minds of your peers
Are you doing a double for loop to access each pixel? That's one way to quickly slow your sketch down. I used to do that for some of my sketches and I would get 0.1-1FPS depending on renderer and canvas size. For example, using a double for loop for each pixel on a 600x600 canvas is 360,000 iterations. The computer uses the CPU for this.
An alternative to this is to use shaders. I use Shadertoy to write them, it uses OpenGL ES. You basically write a sketch that will be applied to every pixel, then it gets compiled into code your GPU can use. Since your GPU does every pixel calculation in parallel, rather than serial like a CPU, it becomes that much faster. It is a bit of a learning curve to start coding in Shadertoy but it is worth it.
A less useful way to speed up your sketch is to iterate through the pixel array. This lets you change the double for loop to a single one. It speeds things up a small bit, but not nearly as much as the shader would. You can also change you renderer from the default to FX2D using size(600, 600, FX2D); . This will take longer to putthe first image on the canvas, but it will have a much higher framerate than the default renderer.
key
as a variable can only have one value so it can't be both w and d (it will be the most recently pressed one). You can create a boolean per key (wPressed, dPressed, etc) and flip those or you can make make a StringList and track pressed keys in it.
I found a way without using constrain and I'm not sure why you'd feel constrain would help you here, there's no such thing as constraining your distance to something, because while you can measure distance you can't directly set it as a variable.
Algorithm that works for me:
For every particle find its distance to my target circle center. If this distance is bigger than the radius of the target circle then I need to adjust its position to the point on the circle that is closest to it. I do that by finding the angle between the center of the circle and the particle using the atan2 function. Now that I know the angle and radius so I can convert from polar coordinates to cartesian coordinates like this:
float angle = atan2(pos.y-center.y, pos.x-center.x); pos.x = center.x+r*cos(angle); pos.y = center.y+r*sin(angle);
To hide the circles just comment the lines where you say ellipse(...
Exporting to SVG is possible with this library
If you want variable thickness you can declare a variable called thickness somewhere on the same level as your canvas variable, say strokeWeight(thickness)
instead of strokeWeight(1)
and then if you change the value of thickness inside draw you will also change the weight of your lines dynamically
Hey, thank you!
I have used Github Pages to host this code. It's super easy to setup static pages on it. You can even attach a custom URL to these pages. Upload it to your repo to host your .exe file (if you want to keep it as downloadable v/s browser based). GitHub even lets you do this with templates and frameworks (jekyll is awesome!).
Documentation: https://pages.github.com/
Are you sure you want to do this in Processing? While possible it’s a lot of work. Don’t know what’s the thing you are trying to build but HTML/CSS/JS would make this a lot easier. Ans if you need Processing in there, you can always use P5.js.
give one of the official guides a try. personally I hate video guides, they are hard to read the code, you can't copy/paste, and rewinding to go over something again is a pain.
this one should get you close to what you need to know https://processing.org/tutorials/interactivity/, but you might need to back up and do a few previous ones from https://processing.org/tutorials/
You might need to look at loadTable https://processing.org/reference/loadTable_.html
Create a class with 2 variable : name and count. An arrayList of that class.
Look at all the rows.
If the row n is a restaurant that do not have an instance of the class create it and start the count at 1.
If not, find this restaurant in the arrayList and add 1 to its count.
Make two separate PGraphics objects, draw the rainbow layer to one, then draw your black shape on the other, then in the main loop you can draw them both to the screen. Here is the reference for PGraphics: https://processing.org/reference/PGraphics.html
What it is essentially is an offscreen rendering context, when you call any commands in processing they are implicitly drawn to a Pgraphics object, now you are just making extra ones, so consider it like drawing your layers onto two separate screens then combining them into one image at the end. The nice part of this approach is that if you can make your desired effect for either of the parts in isolation then it is no extra work to combine them.
Watch all of Daniel Shiffman's videos to understand the basics. Also look at Processing's reference. They have a page on switch.
You might want to look into recursion! I haven't done enough with it to really explain it in-depth, but it can easily repeat shapes. Daniel Shiffman has a great YouTube tutorial on it.
"The screen only updates when the end of draw() is reached, so delay()cannot be used to slow down drawing. For instance, you cannot usedelay() to control the timing of an animation." - https://processing.org/reference/delay_.html.
You want to draw only one ellipse from the 'ripple' each time the draw function executes. You could use a variable that holds the ripple diameter and increase it each time the draw function is called. Then draw only one ellipse with that diameter. This is a simple method, and requires that you store the mousex and mousey in variables (if you continue to call them during each draw call its possible that they would have changed).
Is this for homework? You definitely could use a class to hold the required information.
It has nothing to do with the data.
You're just telling the program to print the text 60 times every second.
fullScreen() for Processing 3 has the capability of selecting the display. So you can do fullScreen(P2D, 2) to run the window in fullscreen on display number 2.
You can also use the command line parameter --display=n to choose the display.
I might be sidestepping your question a little, but when working with and managing objets, you might get better results using an ArrayList. Unlike an Array, the ArrayList doesn't need to be initialised with a fixed length and it's far simpler to add and remove objects from it.
There's another way to deal with the ship moving without using translate. You would instead draw the rocketship once to a PGraphics "canvas"
PGraphics theShip; theShip= createGraphics(w, h); theShip.beginDraw(); // here you would put everything from drawRocket() but prefixed with your variable name (in this case theShip) theShip.endDraw();
Then in your draw() function you would draw using something like:
image(theShip, xCoord, yCoord);
Finally you could deal with collision detection without adding in the translation amount because you're not actually translating. You're drawing the pixels in the PGraphics at whatever your x, y coordinates are. Side note: this also saves a little bit of cpu because you're not recalculating all those beziers every tick.
I would get a processing sketch running and use a keyboard to do the image swapping first, then bring in the arduino. This way you're introducing one element at a time and it will be easier to troubleshoot. Use the Processing website to learn how to put an image on the screen and do the swap, then come back to us with specific questions if you can't get it working.
https://processing.org/reference/image_.html
Easiest way is communicate from Processing to arduino is to load standard Firmata onto the arduino (Firamta is under examples in the arduino IDE). Then you also need the "arduino(firmata)" library for processing.
With that in place communication is simple.
http://playground.arduino.cc/interfacing/processing
The processing website already has some great examples on it, so let me redirect you to those pages.
You can copy and paste the code into processing and then mess around to figure out what stuff does. It's pretty easy to pick up. Good luck!
I made this, inspired by your post : https://bleuje.github.io/p5js-myprojects/edge-force. Codepen version : https://codepen.io/Bleuj/pen/ALaYJg
Basically I estimate how close the object is to the edges with : 1 - min(min(width-x,x),min(height-y,y))/max(width,height);
Then we can put it to a power to have it close to zero almost everywhere in the canvas but not close to the edges, and I use that to weight the force. It keeps well things in the window if wait long enough, and the effect of the force can be invisible in most parts of the window.
If you want to have the objects just touching the edges it's going to be really complicated I think.
I hope I could help, don't hesitate to ask for explainations about what I did if that's what you wanted.
If you want to try it this is the link
https://play.google.com/store/apps/details?id=processing.test.sketch_20191026d
it's not great obviously, I made it in my free time, but if you try it and you tell me what you think it would be really appreciated!
Yes, I like Processing a lot more than working with Unity because I'm not some kind of drag & drop mouth breather and having everything in code actually helps me understand things better.
There are some limitations to the distance you can render in 3D, but maybe you could get around that just by making stuff smaller. I also find camera work a bit math heavy, but there's PeasyCam for java and EasyCam for p5 which lets you not worry about most of it.
And you can easily port your java game to android with Processing! I made this simple game for example with a few hundred lines.
Cool duck!
Hello everybody! I'm a student and I participated in this year's edition of Google Summer of Code with The Processing Foundation.
This is the product of my work: a VR application that lets you travel through a procedural landscape generated according to music. It can use any music, just play the track with any app on your phone, and the app will automatically take it as an input. Other features I'm happy about are two types of generative cacti and the day/night cycle.
Here you can find the link of all the source code and more info on Github: Repository on Github
And there it is on the Play Store: Play Store link
Hopefully it can be useful to somebody else as a reference for making more VR apps, generative terrains / plants, or some music analysis! Feel free to write to me if you have any questions (:
not sure what you mean - repl.it and the p5js editor let you run your code repeatedly. They *also* let you share it if you like. I use them all the time when I'm tinkering. It beats trying to set up local development.
Sure, I'll share the process and the code once I get back to that computer:
Basically: Asendorf pixel sorting applied to each frame of a .gif automatically... available here from this guy: http://prostheticknowledge.tumblr.com/post/34182510825/animated-pixel-sort-kim-asendorfs-open-source
And I came up with an algorithm that calculates within the draw()-replacing for() loop using whiteValue (or any value really if you use a case like I did but it was whiteValue in this gif). From memory...
out of the loop:
float nudge =1;
float value = whiteValue/[total#ofFrames] ;
in the loop:
whitevalue = whiteValue + value*nudge;
so white value keeps climbing or shrinking depending on whether nudge is negative or not, and how far that nudge float goes from 1 determines the speed of decay: that nudge allowed me to time the gif decay with the people getting shot. Neat, right? I'll try to remember to upload the script somewhere tomorrow.
Here's the .pde
Do you have a sketch where you can read an MP3 file yet?
This link is to the Processing Sound library: https://processing.org/reference/libraries/sound/index.html
Check the documentation there to see if you can figure out what pieces you need to get a sound file loaded. Then see if you can use any of the analysis methods to change the stroke based on their output.
In the beginning there's a global array with static size and method reproduce()
replaces all its members starting from index 0 every time any of its members reach 500 energy. Since the array is static there's no room to add two new objects for every reproducing object anyway unless you also remove two. All new objects end up in 3*3 grid because they actually seem to be created based on a location of a single object, the first one to reach 500 energy.
You can maybe either try ArrayList instead of static list, or have prey
class have two instances of itself as offspring which reproduce()
method populates instead of original list, but in either case you would run out of memory very soon unless you make a rule to limit the size of the population.
I would like to also mention another way that's perhaps even easier and more often applicable ( although it can be used with combined shapes just as well ) and that's transformations. With translate, scale and different rotations it's possible to move your creature anywhere on the screen even without touching the original coordinates, or rotate it around any axis or scale it smaller or larger.
Study the PShape tutorial:
https://processing.org/tutorials/pshape
You can create PShapes for each of the thing's neck, body, and head, then use a PShape group to combine them into a single shape 'myGroupShape', which can then be drawn simply by using the method
shape( myGroupShape );
Use PGraphics. You can build your character, step by step, as one object, and then move the whole object, redrawing it as you go.
I used this to make custom sprites in my own game.
Create ten different hair styles, ten different eye styles, ten different noses, ten different mouths, etc.
Assign the hair to the ones place, eyes to the tens place, nose to the hundreds place, mouth to the thousands place, etc.
Pick a random number.
Swap in the correct hair depending what's in the ones place, choose the nose for the tens place, etc. etc.
You've already got 10,000 combinations just for hair, eyes, nose and mouth.
If you want to save them all to a folder, you just use a for loop instead of picking a random number.
To save an image to a file, processing has a simple Save function that saves whatever is on screen to a file. You'll have to build the filename dynamically in the for-loop.
Sadly not. The'reference docs say 'It is not possible to use the transparency alpha parameter with background colors on the main drawing surface.'
If you try it, you'll find it doesn't work; many a time I've been caught out by that and fruitlessly wondered why my sketch wasn't doing what I wanted…
It add a square cap of equal width and half the height of the line thickness at the ends of a line. Basically extends the line, a tiny bit, while keeping it square. ROUND adds a rounded cap, and SQUARE removes fhe cap all together.
Ah so if I understand correctly you want to keep iterating over the array on a mouseClick? If so and assuming i
is used to access the array you could simply reset it either within the if condition;
if (i >= bubbles.length) { i = 0; }
or alternatively use the modulo operator;
i = i % bubbles.length
P3D is a render mode that allow to represent stuff in 3D ! I use to always make sketches in 2D, so i studied P3D last night and here is the results x)
More details here !
You may want to look into the dist() function. It is usually the easiest way; it will do Pythagoras for you, returning the distance between two points. You can compare that to the size of the circle.
Sure. Just a matter of figuring out which variables you want to dump and in what order, saving them to a text file, and then being able to read a text file back in and parse the values back to the right variables.
The Input: Files and Output: Files sections of the reference should be able to get you started.
One technique is to do some work upfront, store that information in an array, and then read from the array for each frame instead of doing calculations b/t frames. This works well for animation based on an input.
In advanced computer graphics you can divide the task of drawing a frame into subtasks and draw them in parallel with a multi-core processor. This is called parallelism, but Processing doesn't give you this level of control.
A related but different idea is concurrency. This is when more than one task is being handled by a single processor core. The processor will jump from task to task which might give the illusion of parallelism, but in reality the processor is only working on one task at a time.
So... in your draw
function you have 100 lines of code that always draw. When that something == false, there is a small window of time when your processor is doing nothing but waiting to draw the next frame. Great! But when that something == true, the processor can't execute all the code b/f the next frame should get drawn and the frame rate drops. Bad!
When that something == true, you could instead begin a background thread
that will be executed independently of the animation loop. When it's time to draw the next frame, the processor will jump out of the background thread, draw as it should, and then go back to completing the task in the background thread. Once the background "task is finished, set a variable that indicates the task is complete, and check that from inside your draw() method." https://processing.org/reference/thread_.html
This is how you'd do it in the Java flavor of Processing. You might have to dig to find the Python equivalent. Hopefully that orients you with the idea of concurrency :)
You need to check the mouseX and mouseY position on the mousePressed() event, and then check if it's within the x, y, width, and height of the picture. If so, then call the function in question.
if(mouseX >= pic.x && mouseX < (pic.x + pic.width) && mouseY >= pic.y && mouseY < (pic.y + pic.height)) { doSomething(); }
Whenever you hit a side you could save the millisecond using millis() and then inside the draw function compare the current millis with the saved value plus some duration.
There's a guide on how to use processing in eclipse: https://processing.org/tutorials/eclipse/
I tried to make a reusable project template but I think there's something wrong which prevents using it out of the box. Anyway, if someone is interested, here it is: https://github.com/ledeniz/processing-sketch-template
The very first thing is: USE PVECTORS. This is the most important skill for a Processing newbie to pick up. PVectors allow you to represent positions and velocities and calculate angles and everything.
With that in mind, I'd do something roughly like this:
PVector target; PVector location; PVector velocity;
void setup() { size(640, 480, P3D); location = new PVector(0, 0); frameRate(60); }
void draw() { clear(); advance(); rect(location.x, location.y, 10, 10); }
void advance() { if (velocity == null) return; //if velocity is nul, that means we're not moving location.add(velocity); //if we are moving, add the velocity to our current location if (location.dist(target) < velocity.mag()) { //if we're less than one frame away from our destination velocity = null; //stop moving location = target; //skip to the destination } }
void mouseClicked() { target = new PVector(mouseX, mouseY); //go where they clicked velocity = PVector.sub(target, location); //figure out the relationship between were we ARE and where we're GOING velocity.setMag(velocity.mag() / frameRate); //scale our velocity so that it takes about 1 second to cover the distance }
By adding, subtracting, and scaling vectors, we can build a really flexible system for doing this.
Are you using textFont() to set the desired font?
​
It needs to go:
​
PFont font;
​
font = loadFont("Nunito-Black.ttf");
​
textFont(font);
​
text("Example",0,40);
​
While this example will display a nice grid the problem is that only thing it "remembers" from frame to frame is the position of the one selected cell - the "selected" variable. You'd instead like to have a grid of cells that can each be in one of n distinct states. You can do this with 2D arrays: https://processing.org/tutorials/2darray/
The tutorial shows how to fill each cell with a grayscale color but you could just as easily draw an image there.
point() in processing is very slow. Mainly because it's doing extra calculations (for example you could draw 3d point(x,y,z), stuff like this).
The fastest solution is with pixels[]
See the reference for usage.
d
is an array, and the size of that array is equal to numE
- when the array was created. Just changing numE
later doesn't do anything to the array- the array still only holds the same number of elements it held originally.
Arrays have a static size.
You want to use an ArrayList instead.
As you might know, dictionaries are protected by copyright.
https://www.gutenberg.org/files/29765/
I would suggest the one from the Gutenberg project because you are free to use it. You should probably write a script in Python for example that is able to scrape the textfile and set it up in XML. You could then reference that XML file in Processing. Referencing to a 27.5mb text file is not something I would advice.
I would also recommend the introduction to generative art with Joshua Davis. He has a great attitude and his way of explaining things is really clear. It's on skillshare if you have access to that. And he was selling it on gumroad for $5 https://gumroad.com/joshuadavis (scroll down and find the "Programming Graphics I, Introduction to generative art").
What I really liked about it is that he introduces a library called Hype that makes some operations that I found frustrating in Processing quite easy, or at least easy to understand for me. Good Luck!
More examples of this style here: https://creativemarket.com/Colorpong/2343015-Neurones/screenshots/#screenshot4 On Instagram, the artist stated that this was created with Processing and Illustrator.
Can anyone point me to a suitable tutorial? I would love to be able to generate some random organic lines like this (and possibly animate).
as the author of said gif, let me say: well done and very cool! (and frankly more interesting & harder than my gif!)
You might have fun doing this in three.js as well. There are a lot of shiny web toys out there that are three.js + dat.gui.js. Plus webgl is increasingly on mobile now!
And don't forget you can approximate ortho() by using a small FOV and moving the camera back (or you can just set the camera matrices if you have access to those)
I used mplayer to play videos; I couldn't get the processing one to work very well (low FPS).
I used a shell with the following:
mplayer blah.mov -vo corevideo:device_id=1 -fs -ontop -framedrop -idle -slave -input file=/tmp/mplayerthing
to play it on the external monitor under OS X. I couldn't find a way of making the movie stop on a black screen, so I just had the external desktop with a black background and a menu bar.
I don't know what platform you are on, but on OS X I ended up using QLab. The free version can support one external screen and trigger videos on MIDI messages. Your Processing app could listen to the Arduino's input and send MIDI messages along an IAC bus to QLab to trigger the videos.
Imho Processings forte lies in 2D. And while there certainly have been impressive 3D programs made with it, I feel setting up a full VR environment would just be pushing it too much. Though I'd like to be proven wrong.
You might yield better results looking in to openFrameworks or cinder. (Though even there I don't know if these environments are ideal for VR).
> If there's something I was missing...
Java Mode sketch needs to conform to Pjs' API: http://ProcessingJS.org/reference/
That API more or less matches Processing's Java Mode 1.5.1. O_o
Processing.JS (Pjs)'s API is pretty much stuck to when Processing was at version 1.5.1:
http://ProcessingJS.org/reference/
And only very recently PDE's become compatible w/ enum
.
I suggest you to replace all of your enum
structures w/ interface
instead.
Only thing I can think of trying to change is using the PVectors.
Making a bunch of temporary Objects has slowed things down for me in the past.
As for js, there's a bunch of stuff that could be unsupported.
Interesting sketch.
Nah. .pde is just the extension that the original Processing uses for source code files.
http://processingjs.org/articles/jsQuickStart.html many ways to skin this cat but this should get yous started
>As of Processing 3.0, to use variables as the parameters to size() function, place the size() function within the settings() function (instead of setup()). There is more information about this on the settings() reference page.
>
>
>
>https://processing.org/reference/size_.html
​
drawing lines by rotating...
I have done the drawing lines!! found great youtube tut...
but I AWAYS got stuck upon rotating these...
any pointers toward "Rotation" `?
then the shifting HUE ... I think this can be done with Random colors, right?
z Position ... I havent touched that. can you recommend a tut?
doing this at the moment https://processing.org/examples/mandelbrot.html
I'm not going to write your code for you but I'll give you a hint. The function "image(fragment,0,0);" is where the code displays the image to the screen. In this case it is displaying it at the coordinates (0,0). You can find more info here: https://processing.org/reference/image_.html.
Look for simple example programs that demonstrate code for the individual steps you need, and put it all together in a way that makes it do what you want.
Starting out you should look through this page hundreds of times while writing programs and figuring out examples.
https://processing.org/reference/
There's a large library of example programs in the processing coding environment's help section to look through as well.
There's the vertex-based gradients mentioned by another poster, the other thing I'd consider is that the example you posted may be using gradients as textures on 3D objects. In that case, you'd make gradient images beforehand, and then use texture() to apply them: https://processing.org/reference/texture_.html