processing

Not drawing at desired position in “Processing”

此生再无相见时 提交于 2019-12-11 06:07:53
问题 I am trying to draw at one place by dragging a mouse (for example, a circle in left upper quadrant) and have the figure appear at 4 places around center of canvas (including one right under the mouse cursor). I have tried following code: int x=0; int y=0; void setup(){ size(400, 400); background(255); translate(width/2, height/2); } void draw() { } void mouseDragged(){ translate(width/2, height/2); for(int i=0; i<4; i++){ rotate(PI/2); x= mouseX ; y=mouseY; line(x, y, mouseX, mouseY); } }

How to “pause” during merge sort to visualize JS p5js

南笙酒味 提交于 2019-12-11 06:02:05
问题 Im working on a sorting visualizer using p5.js, and I need to know if its possible to slow down merge sort so it can be drawn slower. Im currently trying to use the sleep function below to slow down they merge function, but I get Uncaught TypeError: a.slice is not a function. Am I just making a silly mistake, or am I approaching the problem incorrectly? let rectWidth; let depth = 0; function setup() { let numOfRects = document.getElementById('numOfRects').value; let width = document

Not drawing under the mouse in “Processing”

我们两清 提交于 2019-12-11 05:46:14
问题 I want to draw at one place by dragging the mouse and have the line drawn at 3 places around the center of canvas, including one under the cursor itself. I am using following code which does draw 3 lines but none of them is under the mouse cursor: void setup(){ size(300, 300); } void draw() { translate(width/2, height/2); if(mousePressed) for(int i=0; i<3; i++){ line(width/2 -mouseX, height/2 -mouseY, width/2 -pmouseX, height/2 -pmouseY); rotate(2*PI/3); }} How can I correct this code so that

Performance of GLSL geometry shaders unexpectedly slow

假装没事ソ 提交于 2019-12-11 05:38:39
问题 I'm trying to learn how to program GLSL Geometry shaders. My test project works like this: I have N VBO's which are modeling "blades of grass". Without the shader, each blade of grass is just basically a line strip with 20 segments. I was able to get this animating more or less smoothly with almost N=10k blades so that's 200,000 lines. The shader takes each line segment and blows it out to a cylinder of the same length centered on that line segment, so the blades of grass are now tubes with

Drawing to p5.Image instead of to canvas

我是研究僧i 提交于 2019-12-11 05:19:54
问题 Given a loaded png image as a template, I want to enable a user to trace elements of the image. In p5, this is easy: setup() { // Load image var img = loadImage('...'); image(img, 0, 0); } draw() { ellipse(mouseX, mouseY, 2, 2); } However, I want to then be able to save only the ellipses (without the underlying image). Is there a way to write to an Image instead of directly down to the canvas, so that I can lift the pixels of the trace without taking the original image with it? My current

How to generate android code from a processing project

左心房为你撑大大i 提交于 2019-12-11 05:14:40
问题 Am trying get the complete code for android form this project (http://www.gwoptics.org/processing/mobile/BouncingBall/) And i get 2 errors when i try to compile it on processing. Here is the output i get: -set-mode-check: -set-debug-files: -check-env: Android SDK Tools Revision 22.3.0 Installed at C:\Users\antonis\adt-bundle-windows-x86_64-20130917\sdk -setup: [echo] Project Name: BouncingBall Project Type: Application -set-debug-mode: -debug-obfuscation-check: -pre-build: -build-setup: Using

Processing Drawing Problems

不羁岁月 提交于 2019-12-11 05:08:45
问题 I'm kind of new to processing so bear with me. I'm creating a basic drawing program where you click on a colored box to get that color and then you can draw and stuff. Well I already created a red box color and an eraser so I decided to create a blue box but when I click it, it doesn't change the color to blue. I have tried troubleshooting this with no luck. Here's the code (note this works best with Eclipse and importing the processing core https://processing.org/tutorials/eclipse/): // note

How can I achieve noSmooth() with the P3D renderer?

梦想的初衷 提交于 2019-12-11 04:28:58
问题 I'd like to render basic 3D shapes without any aliasing/smoothing with a PGraphics instance using the P3D renderer, but noSmooth() doesn't seem to work. In OF I remember calling setTextureMinMagFilter(GL_NEAREST,GL_NEAREST); on a texture. What would be the equivalent in Processing ? I tried to use PGL: PGL.TEXTURE_MIN_FILTER = PGL.NEAREST; PGL.TEXTURE_MAG_FILTER = PGL.NEAREST; but I get a black image as the result. If I comment PGL.TEXTURE_MIN_FILTER = PGL.NEAREST; I can see the render, but

How to form String Using pixel Array and read all characters value of array

谁说胖子不能爱 提交于 2019-12-11 04:18:12
问题 I am Creating a binary image from processing ide. i want to use pixel array as a string . when i convert this pixel array to string i can't read String characters. every time i get an error. array index of bound. please help to out of this problem for(int y = 0; y < img.height; y++) { for(int x=0; x < img.width; x++) { int i = x+y*img.width; String s = str(i); int c = s.charAt(1); print(c); } } when i run this code in processing software i get an error in console that String Index out of

how to make my player move in diagonal lines and horizontal lines

时光怂恿深爱的人放手 提交于 2019-12-11 04:17:36
问题 i have the following code to make an ellipse move to the left right top and bottom. but now the player can only move in one direction at the time. so if the player moves to the left he cant move to the to the top or bottom. how do i make my code so the player can move both left and right and to the top and the bottom at the same time? any suggestions are appreciated. :) see the code that i have so far: void userInput() { if (keyPressed && (key == 's')) { speedY = 1; println("yes"); } if