Created
March 13, 2024 00:12
-
-
Save valxyz/c33941fb5e7ff06e3a7c619e709f7e35 to your computer and use it in GitHub Desktop.
processing draw grid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float time = 0.0; | |
int dpi = 1; | |
float scalex = 50.0; | |
float scaley = 50.0; | |
color colorbackground = #0E1012; | |
color colorhud = #E5DCDC; | |
void setup() { | |
size(900,505,P2D); | |
pixelDensity(dpi); | |
frameRate(60); | |
smooth(4); | |
textSize(64.0); | |
textAlign(LEFT); | |
prefconfig(); | |
initconfig(); | |
return; | |
} | |
void draw() { | |
push(); | |
background(colorbackground); | |
updateconfig(); | |
float t = time; | |
rotate(t*0.25); | |
scale(1.0+0.25*sin(t)); | |
dgrid(0,0, 500,500, 100,100, #222223, 0.02); | |
dgrid(0,0, 100,100, 100,100, #3F4042, 0.02); | |
daxis(0,0, 10,10, 0.035, 0.1, #FFFFFF ); | |
fill(255); | |
dtext("A", 2.5, 2.5, 1.0); | |
dtext("B", -2.5, 2.5, 1.0); | |
dtext("C", -2.5, -2.5, 1.0); | |
dtext("D", 2.5, -2.5, 1.0); | |
pop(); | |
hud(); | |
return; | |
} | |
//config functions | |
void initconfig(){ | |
return; | |
} | |
void prefconfig(){ | |
translate (width/2.0, height/2.0); | |
scale(scalex,-scaley); | |
return; | |
} | |
void updateconfig(){ | |
prefconfig(); | |
time = millis()/1000.0; | |
return; | |
} | |
void hud(){ | |
textSize(14.0); | |
fill (colorhud); | |
noStroke(); | |
text(nfc(frameRate,2)+" fps", 5,16); | |
text(nfc(millis()/1000.0,2)+" s", 5,32); | |
return; | |
} | |
//draw functions | |
void daxis(float x, float y, float lx, float ly, float thicknessline, float thicknesspoint, color colaxis){ | |
color colxpositive = #FF4747; | |
color colypositive = #7BFF47; //#4782FF; | |
color colxaxis = colaxis; | |
color colyaxis = colaxis; | |
//x | |
stroke(colxaxis); | |
strokeWeight (thicknessline); | |
line(x-lx/2.0,y, x+lx/2.0,y); | |
strokeWeight (thicknesspoint); | |
point(x-lx/2.0,0.0); | |
stroke(colxpositive); | |
strokeWeight (thicknesspoint); | |
point(x+lx/2.0,0.0); | |
//y | |
stroke(colyaxis); | |
strokeWeight (thicknessline); | |
line(x,y-ly/2.0, x,y+ly/2.0); | |
strokeWeight (thicknesspoint); | |
point(0.0,y-ly/2.0); | |
stroke(colypositive); | |
strokeWeight (thicknesspoint); | |
point(0.0,y+ly/2.0); | |
return; | |
} | |
void dgrid(float x, float y, float col, float row, float w, float h, color linecolor, float linethickness){ | |
stroke(linecolor); | |
strokeWeight(linethickness); | |
//vertical lines | |
for (float ic = -w/2.0 ; ic <= w/2.0 ; ic += w/col ){ | |
line (x+ic,y+-h/2.0, x+ic , y+h/2.0); | |
} | |
//horizontal lines | |
for (float ir = -h/2.0 ; ir <= h/2.0 ; ir += h/row ){ | |
line (-w/2.0 + x , ir + y , w/2.0 + x , ir + y); | |
} | |
return; | |
} | |
void dtext(String str, float x, float y, float size){ | |
push(); | |
scale(1.0,-1.0); | |
textSize(size); | |
text(str,x,-y); | |
pop(); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment